本文整理匯總了TypeScript中express.Response.setHeader方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Response.setHeader方法的具體用法?TypeScript Response.setHeader怎麽用?TypeScript Response.setHeader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類express.Response
的用法示例。
在下文中一共展示了Response.setHeader方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1:
const setHeaders = (res: Response): void => {
res.setHeader('X-Content-Type-Options', 'nosniff');
res.setHeader('X-Frame-Options', 'DENY');
res.setHeader('X-XSS-Protection', '1; mode=block');
res.setHeader('Strict-Transport-Security', 'max-age=10886400; includeSubDomains; preload');
res.setHeader('Content-Type', 'text/html');
res.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
res.setHeader('Pragma', 'no-cache');
res.setHeader('Expires', '0');
res.setHeader('max-age', '0');
};
示例2: addCharSet
compress.gzip(Buffer.from(geoText), (err: Error, buffer: Buffer) => {
if (is.value(err)) {
view.internalError(res, err);
} else {
res.setHeader(Header.Content.Encoding, Encoding.GZip);
res.setHeader(Header.CacheControl, 'max-age=86400, public'); // seconds
res.setHeader(Header.Content.Type, addCharSet(MimeType.JSON));
res.setHeader(
Header.Content.Disposition,
`attachment; filename=${key}`
);
res.write(buffer);
res.end();
}
});
示例3: data
export function data(_req: Request, res: Response) {
const minify = config.isProduction && !config.testing;
// vary caching depending on the accepted encoding
res.setHeader(Header.Vary, Header.Accept.Encoding);
view.send(
res,
Page.PostMenuData,
{ blog, layout: Layout.None },
MimeType.JSONP,
minify
);
}
示例4: return
return (req: Request, res: Response, next: NextFunction) => {
var origin = req.headers.origin || req.headers.host;
if (origin) {
res.setHeader('Access-Control-Allow-Origin', origin);
}
Object.keys(configs).forEach((cell: string) => {
res.setHeader(cell, configs[cell]);
});
next();
}
示例5: gpx
/**
* Initiate GPX download for a post.
*/
function gpx(req: Request, res: Response) {
const post = config.providers.map.allowDownload
? blog.postWithKey(req.params[RouteParam.PostKey])
: null;
if (is.value(post)) {
const fileName = post.title + '.gpx';
res.setHeader(
Header.Content.Disposition,
`attachment; filename=${fileName}`
);
res.setHeader(Header.Content.Type, inferMimeType(fileName));
post.gpx(res).catch(err => {
log.error(err);
res.removeHeader(Header.Content.Type);
res.removeHeader(Header.Content.Disposition);
view.notFound(req, res);
});
} else {
view.notFound(req, res);
}
}
示例6: next
app.use((req: Request, res: Response, next: NextFunction) => {
if (config.app.forceHttps === 'enabled') {
if (!req.secure) {
return res.redirect('https://' + req.hostname + ':' + config.app.httpsPort + req.originalUrl);
}
res.setHeader('Strict-Transport-Security', 'max-age=31536000');
}
if (req.method !== 'OPTIONS' && req.header('Accept') !== 'application/json' && req.header('Content-Type') === 'application/json') {
return res.status(406).json({
error: 'Unsupported "Accept" header'
});
}
res.setHeader('X-Content-Type-Options', 'nosniff');
res.setHeader('X-Frame-Options', 'deny');
res.setHeader('Content-Security-Policy', 'default-src \'none\'');
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Authorization, Origin, X-Requested-With, Content-Type, Accept');
return next();
});
示例7: next
router.use((req: Request, res: Response, next: any)=> {
util.log(util.format("Request to: %s:%s -- Params:%s",
req.url, req.method, JSON.stringify(req.body)));
res.setHeader('Access-Control-Allow-Credentials', "true");
res.header("Access-Control-Allow-Origin", req.header("Origin"));
res.header("Access-Control-Allow-Methods", "GET,POST,PUT,HEAD,DELETE,OPTIONS");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
if ('OPTIONS' == req.method) {
res.sendStatus(200);
}
else {
next();
}
});
示例8: writeItemToResponse
export function writeItemToResponse(
res: Response,
item: ViewItem,
cache = true
) {
res.setHeader(Header.Content.Encoding, Encoding.GZip);
if (cache) {
res.setHeader(Header.CacheControl, 'max-age=86400, public'); // seconds
} else {
// force no caching
res.setHeader(Header.CacheControl, 'no-cache');
res.setHeader(Header.Expires, 'Tue, 01 Jan 1980 1:00:00 GMT');
res.setHeader(Header.PRAGMA, 'no-cache');
}
res.setHeader(Header.eTag, item.eTag);
res.setHeader(Header.Content.Type, addCharSet(item.type));
res.write(item.buffer);
res.end();
}
示例9: next
app.use((req: PivotRequest, res: Response, next: Function) => {
res.setHeader("X-Frame-Options", "DENY");
res.setHeader("Content-Security-Policy", "frame-ancestors 'none'");
next();
});
示例10: function
var handleMove = function (req:Request, res:Response, next) {
var move = service.getNextMove(req.body);
res.setHeader('ala', 'ma kota2');
res.json(move);
res.end();
};