-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add typescript and http/2 and server push support #1
Conversation
This is awesome! It's also quite a big change though. I'm probably not going to merge this directly in its full form, but I would like to merge some parts from it into the current project structure. I have a couple of questions though:
Either way, thanks for sending this my way, looks really interesting, nice work! |
I have changed the license to MIT. |
About allowHalfOpenTLS, |
With spdy module you can create HTTP2 / SPDY servers in node.js with natural http module interface and fallback to regular https (for browsers that don't support neither HTTP2, nor SPDY yet). The spdy module can implement all functions of the http 2 protocol and provide APIs similar to the HTTPS module. |
Is there a reproducible code base for __httpPeekedData? I used nodejs v13 and did not encounter this problem |
What is the reason behind this problem? |
If there is a problem with |
Thanks!
Yes, but I'm not actually sure if that will cause you problems, but it will cause slightly different behaviour. That's why the original httpolyglot set it to true (which also isn't correct - it should actually be true for HTTP, false for HTTPS: mscdex/httpolyglot#11). No idea how HTTP/2 handles that!
Here's a quick demo: const httpolyglot = require('httpolyglot');
const fs = require('fs');
const server = httpolyglot.createServer({
key: fs.readFileSync('./ca.key'),
cert: fs.readFileSync('./ca.pem')
}, function(req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end((req.socket.encrypted ? 'HTTPS' : 'HTTP') + ' Connection!');
}).listen(9000, 'localhost', function() {
console.log('httpolyglot server listening on port 9000');
});
server.on('clientError', (e) => {
console.log('Error', e.code, e.rawPacket.toString());
}); Now connect to the server and issue an invalid HTTP request, e.g.:
The server will print:
The raw packet here shows only HTTPS requests to httpolyglot correctly print I haven't tested that many node versions, but this happens reliably in both Node 10.15.3 & Node 14.0.0. I think it's caused because the socket & HTTP parsers are doing various things with native buffers, and pretending that they're just normal JS streams. For my case (an HTTP debugging tool, where I report these client errors to the end users), I really need this data to be correct. Even for everybody else, having correct data here is nice for logging (and there might be other cases that use this same raw packet data, I don't know).
It might be fixable by wrapping the incoming socket with a separate stream - I haven't tested that, but similar discussions elsewhere suggested that there's a performance penalty to that option. For now, the |
well done |
If you want to upgrade "https" server to "http / 2" server, just replace "require ('https')" with "require ('spdy')". |
https://github.com/masx200/http-https-spdy-http2-polyglot/blob/master/lib/index.js
https://github.com/masx200/http-https-spdy-http2-polyglot/blob/master/lib/declaration.ts
https://github.com/masx200/http-https-spdy-http2-polyglot
Abandon the support for the old version of nodejs, and simplify the code implementation, remove the hack code.
add typescript and http/2 and server push support