How can I send 10x responses using Express API?

Viewed 1034

I'm in the process of implementing the send of early informational responses. This is a feature I'm trying with to optimize h2o's push response feature described here (Ctrl+F for Server Push) .

I was looking for a sane Express API to allow to flush an early 100 response like this:

HTTP/1.1 100 Continue
Link: </assets/layout.css>; rel=preload; as=style
...

HTTP/1.1 200 OK
....

but was sadly unable to find it. I've also looked for the proper Node Response API, but the only thing I could find was copy-paste node's internal solution for writeContinue, which looks like this:

const common = require('_http_common')
const { CRLF } = common
let links = []

// fill up links

const earlyResponse = 'HTTP/1.1 100 Continue' + CRLF + links.map(link => `Link: ${link}`).join(CRLF) + CRLF + CRLF

res._writeRaw(earlyResponse, 'ascii', () => {
  res.status(200)send("blabla")
})

this kind of feels dirty, as _writeRaw appears to be private API, so I'd like to know what's the cleanest way to inject early responses there.

This is in the process of being standardized under the 103 code, so it's important to know how to accomplish this.

1 Answers
Related