Skip to content

Commit

Permalink
Find a new solution to avoid losing peeked data
Browse files Browse the repository at this point in the history
  • Loading branch information
pimterry committed Dec 6, 2023
1 parent 38dc555 commit 4239d93
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ A module for serving HTTP, HTTPS and HTTP/2 connections, all over the same port.
Forked from the original [`httpolyglot`](https://github.com/mscdex/httpolyglot) to fix various issues required for [HTTP Toolkit](https://httptoolkit.com), including:

* Support for HTTP/2
* Fixing `tlsClientError`: https://github.com/mscdex/httpolyglot/pull/11.
* Exposing the lost bytes from https://github.com/mscdex/httpolyglot/issues/13 on the socket, as `__httpPeekedData`.
* Dropping support for old versions of Node (and thereby simplifying the code somewhat)
* Fixing `tlsClientError`: https://github.com/mscdex/httpolyglot/pull/11
* Include initially sniffed bytes aren't lost in subsequent `clientError` events (https://github.com/mscdex/httpolyglot/issues/13)
* Dropping support for very old versions of Node (and thereby simplifying the code somewhat)
* Converting to TypeScript
* Event subscription support (subscribe to `server.on(x, ...)` to hear about `x` from _all_ internal servers - HTTP/2, HTTP/1, TLS and net)

Expand Down
7 changes: 1 addition & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class Server extends net.Server {
}

private connectionListener(socket: net.Socket) {
const data = socket.read(1);
const data = socket.read();

if (data === null) {
socket.removeListener('error', onError);
Expand All @@ -137,11 +137,6 @@ export class Server extends net.Server {
// reading until we get the whole stream:
this.http2Listener(socket);
} else {
// The above unshift isn't always sufficient to invisibly replace the
// read data. The rawPacket property on errors in the clientError event
// for plain HTTP servers loses this data - this prop makes it available.
// Bit of a hacky fix, but sufficient to allow for manual workarounds.
socket.__httpPeekedData = data;
this._httpServer.emit('connection', socket);
}
}
Expand Down

0 comments on commit 4239d93

Please sign in to comment.