-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
http2: refactor Http2Stream and inbound headers #16676
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8082939
http2: eliminate pooling of Nghttp2Stream instances
jasnell 54ce323
http2: refactor inbound headers
jasnell 2f78a9f
[Squash] fix
jasnell 957eff9
[Squash] Set header pairs limit to 128
jasnell 59614d7
[Squash] Updates
jasnell c69e7b2
doc: update docs with changes
jasnell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
#include "node_http2_state.h" | ||
|
||
#include <queue> | ||
#include <algorithm> | ||
|
||
namespace node { | ||
|
||
|
@@ -20,8 +21,6 @@ using v8::Undefined; | |
|
||
namespace http2 { | ||
|
||
Freelist<Nghttp2Stream, FREELIST_MAX> stream_free_list; | ||
|
||
Nghttp2Session::Callbacks Nghttp2Session::callback_struct_saved[2] = { | ||
Callbacks(false), | ||
Callbacks(true)}; | ||
|
@@ -67,6 +66,10 @@ Http2Options::Http2Options(Environment* env) { | |
buffer.GetValue(IDX_OPTIONS_PADDING_STRATEGY)); | ||
SetPaddingStrategy(strategy); | ||
} | ||
|
||
if (flags & (1 << IDX_OPTIONS_MAX_HEADER_LIST_PAIRS)) { | ||
SetMaxHeaderPairs(buffer[IDX_OPTIONS_MAX_HEADER_LIST_PAIRS]); | ||
} | ||
} | ||
|
||
Http2Settings::Http2Settings(Environment* env) : env_(env) { | ||
|
@@ -173,11 +176,14 @@ inline void Http2Settings::RefreshDefaults(Environment* env) { | |
DEFAULT_SETTINGS_INITIAL_WINDOW_SIZE; | ||
buffer[IDX_SETTINGS_MAX_FRAME_SIZE] = | ||
DEFAULT_SETTINGS_MAX_FRAME_SIZE; | ||
buffer[IDX_SETTINGS_MAX_HEADER_LIST_SIZE] = | ||
DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE; | ||
buffer[IDX_SETTINGS_COUNT] = | ||
(1 << IDX_SETTINGS_HEADER_TABLE_SIZE) | | ||
(1 << IDX_SETTINGS_ENABLE_PUSH) | | ||
(1 << IDX_SETTINGS_INITIAL_WINDOW_SIZE) | | ||
(1 << IDX_SETTINGS_MAX_FRAME_SIZE); | ||
(1 << IDX_SETTINGS_MAX_FRAME_SIZE) | | ||
(1 << IDX_SETTINGS_MAX_HEADER_LIST_SIZE); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. btw, this is … clever 😄 |
||
} | ||
|
||
|
||
|
@@ -192,7 +198,10 @@ Http2Session::Http2Session(Environment* env, | |
|
||
padding_strategy_ = opts.GetPaddingStrategy(); | ||
|
||
Init(type, *opts); | ||
int32_t maxHeaderPairs = opts.GetMaxHeaderPairs(); | ||
maxHeaderPairs = type == NGHTTP2_SESSION_SERVER ? | ||
std::max(maxHeaderPairs, 4) : std::max(maxHeaderPairs, 1); | ||
Init(type, *opts, nullptr, maxHeaderPairs); | ||
|
||
// For every node::Http2Session instance, there is a uv_prepare_t handle | ||
// whose callback is triggered on every tick of the event loop. When | ||
|
@@ -911,7 +920,8 @@ void Http2Session::OnTrailers(Nghttp2Stream* stream, | |
|
||
void Http2Session::OnHeaders( | ||
Nghttp2Stream* stream, | ||
std::queue<nghttp2_header>* headers, | ||
nghttp2_header* headers, | ||
size_t count, | ||
nghttp2_headers_category cat, | ||
uint8_t flags) { | ||
Local<Context> context = env()->context(); | ||
|
@@ -936,18 +946,19 @@ void Http2Session::OnHeaders( | |
// like {name1: value1, name2: value2, name3: [value3, value4]}. We do it | ||
// this way for performance reasons (it's faster to generate and pass an | ||
// array than it is to generate and pass the object). | ||
do { | ||
size_t n = 0; | ||
while (count > 0) { | ||
size_t j = 0; | ||
while (!headers->empty() && j < arraysize(argv) / 2) { | ||
nghttp2_header item = headers->front(); | ||
while (count > 0 && j < arraysize(argv) / 2) { | ||
nghttp2_header item = headers[n++]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can’t this just be |
||
// The header name and value are passed as external one-byte strings | ||
name_str = | ||
ExternalHeader::New<true>(env(), item.name).ToLocalChecked(); | ||
value_str = | ||
ExternalHeader::New<false>(env(), item.value).ToLocalChecked(); | ||
argv[j * 2] = name_str; | ||
argv[j * 2 + 1] = value_str; | ||
headers->pop(); | ||
count--; | ||
j++; | ||
} | ||
// For performance, we pass name and value pairs to array.protototype.push | ||
|
@@ -956,7 +967,7 @@ void Http2Session::OnHeaders( | |
if (j > 0) { | ||
fn->Call(env()->context(), holder, j * 2, argv).ToLocalChecked(); | ||
} | ||
} while (!headers->empty()); | ||
} | ||
|
||
Local<Value> args[4] = { | ||
Integer::New(isolate, stream->id()), | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
we should probably update the changelog in the docs somehow for this.
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.
Good point