http#IncomingHttpHeaders TypeScript Examples
The following examples show how to use
http#IncomingHttpHeaders.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Token.ts From expresso with MIT License | 6 votes |
/**
*
* @param headers
* @returns
*/
function getToken(headers: IncomingHttpHeaders): string | null | any {
if (headers?.authorization) {
const parted = headers.authorization.split(' ')
// Check Bearer xxx || JWT xxx
if (parted[0] === 'Bearer' || parted[0] === 'JWT') {
if (parted.length === 2) {
return parted[1]
}
}
return null
}
return null
}
Example #2
Source File: Cookie.ts From ZenTS with MIT License | 6 votes |
constructor(headers: IncomingHttpHeaders) {
const cookies = parse(headers.cookie ?? '')
for (const [key, value] of Object.entries(cookies)) {
try {
const cookieValue = JSON.parse(value) as JsonValue
this.data.set(key, {
value: cookieValue,
options: this.getCookieOptions(),
})
} catch (e) {
// silent
}
}
}
Example #3
Source File: __loader__.ts From BotArcAPIs-Memories with MIT License | 5 votes |
handler_request_publicapi =
async (response: ServerResponse, argument: string,
method: string, path: string, header: IncomingHttpHeaders, databody: string | null) => {
let _http_body: string = '';
let _http_status: number = 0;
let _http_content_type: string = '';
let _api_entry: any;
try {
// try to match the route to forward
for (const v in forward_route) {
if (new RegExp(forward_route[v]).test(path)) {
path = path.replace(forward_route[v], '');
_api_entry = await import(`./publicapi/${v}`);
break;
}
}
// require directly if no match
if (!_api_entry)
_api_entry = await import(`./publicapi/${path}.js`);
}
catch (e) {
syslog.w(TAG, `Invalid request path => ${path}`);
return handler_request_notfound(response, 'request path notfound =(:3) z)_');
}
try {
const _api_result: any = {};
// try to invoke method
_api_entry = _api_entry.default;
await _api_entry(argument, method, path, header, databody)
.then((result: any) => {
_api_result.status = 0;
_api_result.content = result;
})
.catch((error: APIError) => {
_api_result.status = error.status;
_api_result.message = error.notify;
});
_http_status = 200;
_http_body = JSON.stringify(_api_result);
_http_content_type = 'application/json; charset=utf-8';
}
catch (e) {
syslog.e(TAG, e.stack);
return handler_request_error(response, 'some error occurred! (>_<)|||');
}
// send result to client
response.statusCode = _http_status;
response.setHeader('Content-Type', _http_content_type);
response.setHeader('Access-Control-Allow-Origin', '*');
response.setHeader('Server', `${BOTARCAPI_VERSTR}`);
response.end(_http_body);
syslog.v(TAG, 'Send response back');
}
Example #4
Source File: validation.d.ts From openapi-cop with MIT License | 5 votes |
validateResponseHeaders(headers: IncomingHttpHeaders, operation: Operation, statusCode: number): ValidationResult;
Example #5
Source File: validation.ts From openapi-cop with MIT License | 5 votes |
validateResponseHeaders(
headers: IncomingHttpHeaders,
operation: Operation,
statusCode: number,
): ValidationResult {
return this.oasValidator.validateResponseHeaders(headers, operation, {
statusCode,
setMatchType: SetMatchType.Superset,
});
}
Example #6
Source File: errors.types.ts From node-twitter-api-v2 with Apache License 2.0 | 5 votes |
headers: IncomingHttpHeaders;
Example #7
Source File: logger.middleware.ts From whispr with MIT License | 5 votes |
export function headersToString(headerMap: IncomingHttpHeaders): string {
const filtred = {
...headerMap,
authorization: headerMap.authorization ? `[HIDDEN size=${headerMap.authorization.length}]` : null,
};
return JSON.stringify(filtred);
}
Example #8
Source File: tracer-provider.ts From nestjs-jaeger-tracing with MIT License | 5 votes |
extractHeaders(headers: IncomingHttpHeaders): SpanContext {
const context = this.tracer.extract(FORMAT_HTTP_HEADERS, headers);
return context || undefined;
}
Example #9
Source File: HTTPResponse.ts From dis.ts with MIT License | 5 votes |
headersIn: IncomingHttpHeaders;
Example #10
Source File: provide-user-agent.ts From universal with MIT License | 5 votes |
export function provideUserAgent(req: {headers: IncomingHttpHeaders}): ValueProvider {
return {
provide: SSR_USER_AGENT,
useValue: req.headers['user-agent'],
};
}
Example #11
Source File: app.imports.ts From api with GNU Affero General Public License v3.0 | 5 votes |
imports = [
ConsoleModule,
HttpModule.register({
timeout: 5000,
maxRedirects: 10,
}),
ServeStaticModule.forRoot({
rootPath: join(__dirname, '..', 'public'),
exclude: ['/graphql'],
}),
ConfigModule.forRoot({
load: [
() => {
return {
LOCALES_PATH: join(process.cwd(), 'locales'),
SECRET_KEY: process.env.SECRET_KEY || crypto.randomBytes(20).toString('hex'),
}
},
],
}),
JwtModule.registerAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (configService: ConfigService): JwtModuleOptions => ({
secret: configService.get<string>('SECRET_KEY'),
signOptions: {
expiresIn: '4h',
},
}),
}),
LoggerModule.forRoot(LoggerConfig),
GraphQLModule.forRoot<ApolloDriverConfig>({
debug: process.env.NODE_ENV !== 'production',
definitions: {
outputAs: 'class',
},
driver: ApolloDriver,
sortSchema: true,
introspection: process.env.NODE_ENV !== 'production',
playground: process.env.NODE_ENV !== 'production',
installSubscriptionHandlers: true,
autoSchemaFile: join(process.cwd(), 'src/schema.gql'),
// to allow guards on resolver props https://github.com/nestjs/graphql/issues/295
fieldResolverEnhancers: [
'guards',
'interceptors',
],
resolverValidationOptions: {
},
context: ({ req, connection }) => {
if (!req && connection) {
const headers: IncomingHttpHeaders = {}
Object.keys(connection.context).forEach(key => {
headers[key.toLowerCase()] = connection.context[key]
})
return {
req: {
headers,
} as Request,
}
}
return { req }
},
}),
TypeOrmModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (configService: ConfigService): TypeOrmModuleOptions => {
const type: any = configService.get<string>('DATABASE_DRIVER', 'sqlite')
let migrationFolder: string
let migrationsTransactionMode: 'each' | 'none' | 'all' = 'each'
switch (type) {
case 'cockroachdb':
case 'postgres':
migrationFolder = 'postgres'
break
case 'mysql':
case 'mariadb':
migrationFolder = 'mariadb'
break
case 'sqlite':
migrationFolder = 'sqlite'
migrationsTransactionMode = 'none'
break
default:
throw new Error('unsupported driver')
}
return ({
name: 'ohmyform',
synchronize: false,
type,
url: configService.get<string>('DATABASE_URL'),
database: type === 'sqlite' ? configService.get<string>('DATABASE_URL', 'data.sqlite').replace('sqlite://', '') : undefined,
ssl: configService.get<string>('DATABASE_SSL', 'false') === 'true' ? { rejectUnauthorized: false } : false,
entityPrefix: configService.get<string>('DATABASE_TABLE_PREFIX', ''),
logging: configService.get<string>('DATABASE_LOGGING', 'false') === 'true',
entities,
migrations: [`${__dirname}/**/migrations/${migrationFolder}/**/*{.ts,.js}`],
migrationsRun: configService.get<boolean>('DATABASE_MIGRATE', true),
migrationsTransactionMode,
})
},
}),
TypeOrmModule.forFeature(entities),
MailerModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (configService: ConfigService) => ({
transport: configService.get<string>('MAILER_URI', 'smtp://localhost:1025'),
defaults: {
from: configService.get<string>('MAILER_FROM', 'OhMyForm <no-reply@localhost>'),
},
}),
}),
]
Example #12
Source File: IncomingMessage.ts From double-agent with MIT License | 5 votes |
readonly headers: IncomingHttpHeaders;