-
Notifications
You must be signed in to change notification settings - Fork 38
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
Added support for HTTP/2 #93
base: master
Are you sure you want to change the base?
Conversation
.github/workflows/ci.yml
Outdated
run: npm install --legacy-peer-deps | ||
|
||
- name: Compile TS | ||
run: tsc lib/**/*.ts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this library published? We'll just want to make sure we don't accidentally not perform the compilation step. I think there's a prepare or prepublish script we can invoke in package.json to minimize errors.
@@ -14,7 +14,7 @@ | |||
}, | |||
"license": "Apache-2.0", | |||
"engines": { | |||
"node": ">= 6" | |||
"node": ">= 16" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How and where is this library consumed and used? Does bumping this up so heavily cause any issues?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would, but http2 support was only introduced in node 15, and node 16 is the lowest LTS version that supports http2 hence decided/forced to make this change
request.js
Outdated
@@ -3,6 +3,8 @@ | |||
var tls = require('tls') | |||
var http = require('http') | |||
var https = require('https') | |||
var http2 = require('./lib/http2').default; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit maybe, but I think there's a way to publish TypeScript modules still as commonjs. I think it's export =
last I checked.
Mostly just the default export is kinda wack in a project which is mostly CommonJS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah we still need to look into the pipeline of it all, mainly focus on feature completeness and readiness.
Will fix this up before making the PR ready for review
tests/server.js
Outdated
@@ -1,142 +1,196 @@ | |||
'use strict' | |||
"use strict"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another nit that I know will be resolved, but make sure any stylistic preferences are fixed in future commits so that the history stays mostly clean and just what was changed.
index.js
Outdated
@@ -34,6 +35,22 @@ function initParams (uri, options, callback) { | |||
} | |||
|
|||
params.callback = callback || params.callback | |||
|
|||
// Disable http/2 when using custom agents that don't handle different versions separately | |||
if (params.agents && !(params.agents.http1 || params.agents.auto || params.agents.h2)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How agents
option looks like now?
// therefore we split on the index of the first ':' | ||
var splitIndex = arr[i].indexOf(':') | ||
// HTTP/2 specific headers beging with :, so we find the index of the first colon skipping the first character | ||
var splitIndex = arr[i].indexOf(':', 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
foo=bar:baz
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
![image](https://private-user-images.githubusercontent.com/75295512/342494874-09f6b206-a3e2-41a4-988b-2ad7912c0a77.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk2NDczMTYsIm5iZiI6MTcxOTY0NzAxNiwicGF0aCI6Ii83NTI5NTUxMi8zNDI0OTQ4NzQtMDlmNmIyMDYtYTNlMi00MWE0LTk4OGItMmFkNzkxMmMwYTc3LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MjklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjI5VDA3NDMzNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTIzMzI2MzE2Nzk1YzRmNWNjYmQ3ZmE3OTY2MGMzZDVlZGE2MzMwYjE0MDU5YTZkZmFiODAwOTg0ZGEzMWYxMzUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.-jMCP6_Z9WyRR8CpHoJoJ5unym-qbf1ZQUpeAfVxYx0)
The header section of the HTTP message splits the key and value on :
, thus in order to safeguard against HTTP/2 headers that start with :
, the above indexof
will skip the first character to find the index.
Example
For the header foo: bar:baz
, the index of will find the index as 3 and the above code will contniue working as expected
// Reference to request, so if _reqResInfo is updated (in case of redirects), we still can update the headers | ||
const request = self._reqResInfo.request | ||
Promise.resolve(self.req._header).then(function (header) { | ||
request.headers = parseRequestHeaders(header) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.req._header = header
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed, since once the _header
value is resolved, it means that we have access to the final request object that was sent, thus subsequent gets for _header
will return the value instead of the promise. Additionally, since _header
is implemented as a getter, it cannot be reassigned
PR Checklist:
npm test
locally and all tests are passing.PR Description
Introduces support for HTTP/2 by disguising HTTP/2 as HTTP/1 requests and writing appropriate translation/proxy layers.
HTTP/2 is disabled automatically when
Also adds changes to the redirection logic, where the redirection plugin will now wait for the redirected request to finish before making the next request