koa-auto-transfer-header
v1.3.1
Published
auto transfer header in each http-request when server receive a request
Downloads
14
Readme
koa-auto-transfer-header
In a Koa server, when a client request is received and an external HTTP request is initiated in the request, the request header initiated by the client is automatically forwarded.
Also used in a server started from any Web Framework.
Support all http-client
libs based on http
module.
Installation
npm install koa-auto-transfer-header [--save]
or
yarn add koa-auto-transfer-header
Usage
import in portal file
import 'koa-auto-transfer-header';
Config
interface IConfig {
enable: boolean; // is enable tranfer, default: true
transferHeaders: string[], // transfer header keys, default: ['request-id', 'trace-id']
}
disable transfer
import { disableTransferHeaders } from 'koa-auto-transfer-header';
disableTransferHeaders();
add transfer header
import { addTransferHeader } from 'koa-auto-transfer-header';
addTransferHeader('my-header');
reset transfer headers
import { setTransferHeaders } from 'koa-auto-transfer-header';
setTransferHeaders(['my-header1', 'my-header2']);
add request headers hook
import { RequestHeadersHook } from 'koa-auto-transfer-header';
const foo = () => {
return { 'x-headers-foo': '123' }
}
const bar = () => {
return { 'x-headers-bar': '123' }
}
RequestHeadersHook.register(foo)
RequestHeadersHook.register(bar)
// cancel the register
RequestHeadersHook.unregister(foo)