koajs / discussions

KoaJS Discussions
2 stars 2 forks source link

koajs/conditional-get: uws.http failure #44

Open pkoretic opened 7 years ago

pkoretic commented 7 years ago

this is not really issue of this module but for completeness

const http = require('uws').http
const Koa = require('koa')
const conditional = require('koa-conditional-get')

const app = new Koa()

app.use(conditional())

app.use(ctx => {
    ctx.body = 'Hello World!'
})

http.createServer(app.callback()).listen(8000)

using this module with uws http server results in: Warning: req.headers usage past request handler is not supported!

this is because this.get (or this.headers in fresh module) being called in upstream triggers it

one would have to "solve" this like

const fresh = ctx.fresh
return next().then(() => {
          if (fresh) {
        ctx.status = 304;
        ctx.body = null;
     }
    });

which I don't think is really a solution since one has to allocate memory before it is sure it will get used I suspect there is bunch of other libraries that will have the same "issue"

reported that over to uws https://github.com/uWebSockets/uWebSockets/issues/590