7 examples of 'express set header' in JavaScript

Every line of 'express set header' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
5async use(context: any, next: (err?: any) => any): Promise<any> {
6 context.set('Access-Control-Allow-Methods', 'GET,HEAD,PUT,POST,DELETE,PATCH')
7 context.set('Access-Control-Allow-Origin', context.request.header.origin || context.request.origin)
8 context.set('Access-Control-Allow-Headers', ['content-type'])
9 context.set('Access-Control-Allow-Credentials', 'true')
10 context.set('Content-Type', 'application/json; charset=utf-8')
11 return next()
12}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

38public getHeader(field: string): string | undefined {
39 return this.req.header(field);
40}
68header(header) {
69 if (!arguments.length) return this._header;
70 this._header = header;
71 return this;
72}
443function setHeader(res, field, value) {
444 if (!res.getHeader(field))
445 res.setHeader(field, value)
446}
147function setHeader(res: express.Response, key: string, value: string) {
148 try {
149 let existingHeaders = res.getHeaders();
150 let existingValue = existingHeaders[key.toLowerCase()];
151 if (existingValue === undefined) {
152 res.header(key, value);
153 } else {
154 res.header(key, existingValue + ", " + value);
155 }
156 } catch (err) {
157 throw generateError(AuthError.GENERAL_ERROR, err);
158 }
159}
133setHeader(name, val) {
134 this._handle._headers.set(name, val);
135}
85function setHeader(req, res, next) {
86 res.writeHead(200, {'age': '42'});
87 return next();
88}

Related snippets