fastify.get('/', function (req, reply) { reply.code(200) reply.header('Content-Type', 'text/plain') reply.send('hello world!') })
describe('corsMiddleware', () => { it('should send response directly', async () => { const req = new MockExpressRequest({ method: 'OPTIONS', }); corsMiddleware(req, res, () => { throw new Error('next should not be calld'); }); assert.called(res.header); assert.calledOnce(res.send); }); });
function getHeaderFromToken(token) { const decodedToken = jwt.decode(token, { complete: true }); if (!decodedToken) { throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, `provided token does not decode as JWT`); } return decodedToken.header; }
grp.request.header.map(function (obj) { if(obj.key.toLowerCase()=="content-type" && obj.value.toLowerCase().indexOf("application/json")>-1) { bJSON=true; } util.getPostmanGlobalVar(obj.value,baseUrls); return { name:obj.key, value:obj.value, remark:"" } })
it('should throw TypeError when get encrypt on keys not exists', () => { mm(app, 'keys', null); const ctx = app.mockContext(); ctx.header.cookie = 'foo=bar'; assert.throws(() => { ctx.cookies.get('foo', { encrypt: true, }); }, /\.keys required for encrypt\/sign cookies/); });
function send_string(body, admin_only) { return function(request, reply, next) { if (admin_only) { const user = getUser(request) || {}; if (!user.admin) return next(); } if (request.baseUrl.endsWith('.js')) { reply.header('Content-Type', 'application/javascript'); } reply.send(body); }; }
app.use(async (ctx, next) => { const origin = ctx.header['origin'] if(origin) { ctx.set('Access-Control-Allow-Origin', origin) } const startTime = new Date() await next() const timeDelta = new Date() - startTime console.log(new Date(), ctx.request.url, timeDelta) })
fastify.register(function (instance, options, next) { fastify.addHook('onSend', function (req, reply, payload, next) { reply.header('x-onsend', 'yes') next() }) fastify.get('/redirect-onsend', function (req, reply) { reply.redirect('/') }) next() })
header.forEach(function (obj) { if(obj.name) { info.header[obj.name]=obj.value; } })
const serveFile = async file => { const buffer = await fs.readFile(file) if (process.env.NODE_ENV === 'development') { res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate') res.header('Pragma', 'no-cache') res.header('Expires', '-1') } res.header('Accept-Ranges', 'bytes') res.contentType(ext) res.end(buffer) }
// Basic HTTP response app.get('/', (req, res) => { res.header('Content-type', 'text/html'); return res.end('<h1>DANCING DANCING STARLIGHT</h1>'); });
// Basic HTTP response app.get('/', (req, res) => { res.header('Content-type', 'text/html'); return res.end('<h1>DANCING DANCING STARLIGHT</h1>'); });
// Basic HTTP response app.get('/', (req, res) => { res.header('Content-type', 'text/html'); return res.end('<h1>I said "Oh my!" What a marvelous tune!!!</h1>'); });