JAVA中间件(middleware)模式

  • ()

  • filter,pipeline(forEach)

  • java()

http, IP   cookie   (session) gzip(compress) 

aspnetcorehttp JAVA中间件(middleware)模式

https://docs.microsoft.com/en-us/aspnet/core/fundamentals/middleware/?view=aspnetcore-5.0

nodejshttpnodejs express koa 

koa middlewareuse  responseheader'X-Response-Time'()

const Koa = require('koa');
const app = new Koa();

// logger

app.use(async (ctx, next) => {
  await next();//进入下一个中间件
  const rt = ctx.response.get('X-Response-Time');
  //记录日志
  console.log(`${ctx.method} ${ctx.url} - ${rt}`);
});

// x-response-time

app.use(async (ctx, next) => {
  const start = Date.now();
  await next();//进入下一个中间件
  const ms = Date.now() - start;
  //记录请求时长
  ctx.set('X-Response-Time', `${ms}ms`);
});

// response

app.use(async ctx => {
  ctx.body = 'Hello World';
});
app.listen(3000);

 

  

相关文章: