StreamSSE on http2

Hi ! It seems that the streamSSE feature is not correctly adapted to work on http2. It adds the following header ‘transfer-encoding’->‘chuncked’, which is not authorised on http2.
var streamSSE = (c, cb, onError) => {
const { readable, writable } = new TransformStream();
const stream = new SSEStreamingApi(writable, readable);
c.header("Transfer-Encoding", "chunked");
c.header("Content-Type", "text/event-stream");
c.header("Cache-Control", "no-cache");
c.header("Connection", "keep-alive");
run(stream, cb, onError);
return c.newResponse(stream.responseReadable);
};
var streamSSE = (c, cb, onError) => {
const { readable, writable } = new TransformStream();
const stream = new SSEStreamingApi(writable, readable);
c.header("Transfer-Encoding", "chunked");
c.header("Content-Type", "text/event-stream");
c.header("Cache-Control", "no-cache");
c.header("Connection", "keep-alive");
run(stream, cb, onError);
return c.newResponse(stream.responseReadable);
};
so it gives me an error :
(node:4570) UnsupportedWarning: The provided connection header is not valid, the value will be dropped from the header and will never be in use.
node:internal/http2/util:531
throw new ERR_HTTP2_INVALID_CONNECTION_HEADERS(key);
^

TypeError [ERR_HTTP2_INVALID_CONNECTION_HEADERS]: HTTP/1 Connection specific headers are forbidden: "transfer-encoding"
at mapToHeaders (node:internal/http2/util:531:13)
at ServerHttp2Stream.respond (node:internal/http2/core:2786:25)
at [begin-send] (node:internal/http2/compat:836:19)
at Http2ServerResponse.writeHead (node:internal/http2/compat:711:21)
at responseViaResponseObject (file:///home/**/node_modules/@hono/node-server/dist/index.mjs:341:14)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 'ERR_HTTP2_INVALID_CONNECTION_HEADERS'
}
(node:4570) UnsupportedWarning: The provided connection header is not valid, the value will be dropped from the header and will never be in use.
node:internal/http2/util:531
throw new ERR_HTTP2_INVALID_CONNECTION_HEADERS(key);
^

TypeError [ERR_HTTP2_INVALID_CONNECTION_HEADERS]: HTTP/1 Connection specific headers are forbidden: "transfer-encoding"
at mapToHeaders (node:internal/http2/util:531:13)
at ServerHttp2Stream.respond (node:internal/http2/core:2786:25)
at [begin-send] (node:internal/http2/compat:836:19)
at Http2ServerResponse.writeHead (node:internal/http2/compat:711:21)
at responseViaResponseObject (file:///home/**/node_modules/@hono/node-server/dist/index.mjs:341:14)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 'ERR_HTTP2_INVALID_CONNECTION_HEADERS'
}
I can't use the SSE and I desperately need it to continue developing my application. It's such a trifle ... I'm an opensource neophyte, should I create an issue on github? And until it's adapted to http2, is there an interesting workaround, without having to go back to h1?
2 Replies
Nico
Nico7mo ago
What runtime are you using? In Bun http2 is not supported yet. I would have to do research to see if that would effect how this works in node as well or another runtime if you are using those
Killian Di Vincenzo
Hi @Nico ! Sorry for responding late. I was using bun before using http2, but now I'm using nodeJS. I found a workaround for a little time by doing :
const streams = await streamSSE(c, ...)
c.res.headers.delete("Transfer-Encoding");
streams.headers.delete("Transfer-Encoding");
return streams
const streams = await streamSSE(c, ...)
c.res.headers.delete("Transfer-Encoding");
streams.headers.delete("Transfer-Encoding");
return streams
And then, the server stop crash and clients managed to connect to the server ; but the stream disconnected immediately with the same error (but no more crash) : UnsupportedWarning: The provided connection header is not valid, the value will be dropped from the header and will never be in use.
Want results from more Discord servers?
Add your server