http2: custom promisify for http2.connect · nodejs/node@a6879bf · GitHub
Skip to content

Commit a6879bf

Browse files
committed
http2: custom promisify for http2.connect
... and some other cleanups PR-URL: #15207 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 727d7b5 commit a6879bf

4 files changed

Lines changed: 59 additions & 9 deletions

File tree

lib/internal/http2/core.js

Lines changed: 13 additions & 1 deletion

src/node_http2_core-inl.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,19 @@ inline int Nghttp2Session::OnBeginHeadersCallback(nghttp2_session* session,
5252
const nghttp2_frame* frame,
5353
void* user_data) {
5454
Nghttp2Session* handle = static_cast<Nghttp2Session*>(user_data);
55+
// If this is a push promise frame, we want to grab the handle of
56+
// the promised stream.
5557
int32_t id = (frame->hd.type == NGHTTP2_PUSH_PROMISE) ?
56-
frame->push_promise.promised_stream_id :
57-
frame->hd.stream_id;
58+
frame->push_promise.promised_stream_id :
59+
frame->hd.stream_id;
5860
DEBUG_HTTP2("Nghttp2Session %s: beginning headers for stream %d\n",
5961
handle->TypeName(handle->type()), id);
6062

6163
Nghttp2Stream* stream = handle->FindStream(id);
6264
if (stream == nullptr) {
63-
Nghttp2Stream::Init(id, handle, frame->headers.cat);
65+
Nghttp2Stream::Init(id, handle, frame->headers.cat);
6466
} else {
65-
stream->StartHeaders(frame->headers.cat);
67+
stream->StartHeaders(frame->headers.cat);
6668
}
6769
return 0;
6870
}
@@ -77,9 +79,11 @@ inline int Nghttp2Session::OnHeaderCallback(nghttp2_session* session,
7779
uint8_t flags,
7880
void* user_data) {
7981
Nghttp2Session* handle = static_cast<Nghttp2Session*>(user_data);
82+
// If this is a push promise frame, we want to grab the handle of
83+
// the promised stream.
8084
int32_t id = (frame->hd.type == NGHTTP2_PUSH_PROMISE) ?
81-
frame->push_promise.promised_stream_id :
82-
frame->hd.stream_id;
85+
frame->push_promise.promised_stream_id :
86+
frame->hd.stream_id;
8387
Nghttp2Stream* stream = handle->FindStream(id);
8488
nghttp2_header_list* header = header_free_list.pop();
8589
header->name = name;

src/node_http2_core.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ class Nghttp2Session {
141141
inline ssize_t Write(const uv_buf_t* bufs, unsigned int nbufs);
142142

143143
// Returns the nghttp2 library session
144-
inline nghttp2_session* session() { return session_; }
144+
inline nghttp2_session* session() const { return session_; }
145145

146-
nghttp2_session_type type() {
146+
nghttp2_session_type type() const {
147147
return session_type_;
148148
}
149149

Lines changed: 34 additions & 0 deletions

0 commit comments

Comments
 (0)