Browse Source

http2: refactor method arguments to avoid bools

PR-URL: https://github.com/nodejs/node/pull/15693
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
v9.x-staging
James M Snell 8 years ago
parent
commit
8f4db313f0
  1. 67
      lib/internal/http2/core.js
  2. 32
      src/node_http2.cc
  3. 34
      src/node_http2_core-inl.h
  4. 18
      src/node_http2_core.h

67
lib/internal/http2/core.js

@ -127,7 +127,10 @@ const {
HTTP_STATUS_OK, HTTP_STATUS_OK,
HTTP_STATUS_NO_CONTENT, HTTP_STATUS_NO_CONTENT,
HTTP_STATUS_NOT_MODIFIED, HTTP_STATUS_NOT_MODIFIED,
HTTP_STATUS_SWITCHING_PROTOCOLS HTTP_STATUS_SWITCHING_PROTOCOLS,
STREAM_OPTION_EMPTY_PAYLOAD,
STREAM_OPTION_GET_TRAILERS
} = constants; } = constants;
// Top level to avoid creating a closure // Top level to avoid creating a closure
@ -412,20 +415,22 @@ function requestOnConnect(headers, options) {
return; return;
} }
let getTrailers = false; let streamOptions = 0;
if (options.endStream)
streamOptions |= STREAM_OPTION_EMPTY_PAYLOAD;
if (typeof options.getTrailers === 'function') { if (typeof options.getTrailers === 'function') {
getTrailers = true; streamOptions |= STREAM_OPTION_GET_TRAILERS;
this[kState].getTrailers = options.getTrailers; this[kState].getTrailers = options.getTrailers;
} }
// ret will be either the reserved stream ID (if positive) // ret will be either the reserved stream ID (if positive)
// or an error code (if negative) // or an error code (if negative)
const ret = handle.submitRequest(headersList, const ret = handle.submitRequest(headersList,
!!options.endStream, streamOptions,
options.parent | 0, options.parent | 0,
options.weight | 0, options.weight | 0,
!!options.exclusive, !!options.exclusive);
getTrailers);
// In an error condition, one of three possible response codes will be // In an error condition, one of three possible response codes will be
// possible: // possible:
@ -1568,7 +1573,7 @@ function processHeaders(headers) {
} }
function processRespondWithFD(fd, headers, offset = 0, length = -1, function processRespondWithFD(fd, headers, offset = 0, length = -1,
getTrailers = false) { streamOptions = 0) {
const session = this[kSession]; const session = this[kSession];
const state = this[kState]; const state = this[kState];
state.headersSent = true; state.headersSent = true;
@ -1578,7 +1583,7 @@ function processRespondWithFD(fd, headers, offset = 0, length = -1,
const handle = session[kHandle]; const handle = session[kHandle];
const ret = const ret =
handle.submitFile(this[kID], fd, headers, offset, length, getTrailers); handle.submitFile(this[kID], fd, headers, offset, length, streamOptions);
let err; let err;
switch (ret) { switch (ret) {
case NGHTTP2_ERR_NOMEM: case NGHTTP2_ERR_NOMEM:
@ -1593,7 +1598,7 @@ function processRespondWithFD(fd, headers, offset = 0, length = -1,
} }
} }
function doSendFD(session, options, fd, headers, getTrailers, err, stat) { function doSendFD(session, options, fd, headers, streamOptions, err, stat) {
if (this.destroyed || session.destroyed) { if (this.destroyed || session.destroyed) {
abort(this); abort(this);
return; return;
@ -1623,10 +1628,10 @@ function doSendFD(session, options, fd, headers, getTrailers, err, stat) {
processRespondWithFD.call(this, fd, headersList, processRespondWithFD.call(this, fd, headersList,
statOptions.offset, statOptions.offset,
statOptions.length, statOptions.length,
getTrailers); streamOptions);
} }
function doSendFileFD(session, options, fd, headers, getTrailers, err, stat) { function doSendFileFD(session, options, fd, headers, streamOptions, err, stat) {
if (this.destroyed || session.destroyed) { if (this.destroyed || session.destroyed) {
abort(this); abort(this);
return; return;
@ -1681,10 +1686,10 @@ function doSendFileFD(session, options, fd, headers, getTrailers, err, stat) {
processRespondWithFD.call(this, fd, headersList, processRespondWithFD.call(this, fd, headersList,
options.offset, options.offset,
options.length, options.length,
getTrailers); streamOptions);
} }
function afterOpen(session, options, headers, getTrailers, err, fd) { function afterOpen(session, options, headers, streamOptions, err, fd) {
const state = this[kState]; const state = this[kState];
const onError = options.onError; const onError = options.onError;
if (this.destroyed || session.destroyed) { if (this.destroyed || session.destroyed) {
@ -1702,7 +1707,8 @@ function afterOpen(session, options, headers, getTrailers, err, fd) {
state.fd = fd; state.fd = fd;
fs.fstat(fd, fs.fstat(fd,
doSendFileFD.bind(this, session, options, fd, headers, getTrailers)); doSendFileFD.bind(this, session, options, fd,
headers, streamOptions));
} }
function streamOnError(err) { function streamOnError(err) {
@ -1786,9 +1792,9 @@ class ServerHttp2Stream extends Http2Stream {
throw headersList; throw headersList;
} }
const ret = handle.submitPushPromise(this[kID], const streamOptions = options.endStream ? STREAM_OPTION_EMPTY_PAYLOAD : 0;
headersList,
options.endStream); const ret = handle.submitPushPromise(this[kID], headersList, streamOptions);
let err; let err;
switch (ret) { switch (ret) {
case NGHTTP2_ERR_NOMEM: case NGHTTP2_ERR_NOMEM:
@ -1844,14 +1850,17 @@ class ServerHttp2Stream extends Http2Stream {
options = Object.assign(Object.create(null), options); options = Object.assign(Object.create(null), options);
options.endStream = !!options.endStream; options.endStream = !!options.endStream;
let getTrailers = false; let streamOptions = 0;
if (options.endStream)
streamOptions |= STREAM_OPTION_EMPTY_PAYLOAD;
if (options.getTrailers !== undefined) { if (options.getTrailers !== undefined) {
if (typeof options.getTrailers !== 'function') { if (typeof options.getTrailers !== 'function') {
throw new errors.TypeError('ERR_INVALID_OPT_VALUE', throw new errors.TypeError('ERR_INVALID_OPT_VALUE',
'getTrailers', 'getTrailers',
options.getTrailers); options.getTrailers);
} }
getTrailers = true; streamOptions |= STREAM_OPTION_GET_TRAILERS;
state.getTrailers = options.getTrailers; state.getTrailers = options.getTrailers;
} }
@ -1881,10 +1890,7 @@ class ServerHttp2Stream extends Http2Stream {
const handle = session[kHandle]; const handle = session[kHandle];
const ret = const ret =
handle.submitResponse(this[kID], handle.submitResponse(this[kID], headersList, streamOptions);
headersList,
options.endStream,
getTrailers);
let err; let err;
switch (ret) { switch (ret) {
case NGHTTP2_ERR_NOMEM: case NGHTTP2_ERR_NOMEM:
@ -1937,14 +1943,14 @@ class ServerHttp2Stream extends Http2Stream {
options.statCheck); options.statCheck);
} }
let getTrailers = false; let streamOptions = 0;
if (options.getTrailers !== undefined) { if (options.getTrailers !== undefined) {
if (typeof options.getTrailers !== 'function') { if (typeof options.getTrailers !== 'function') {
throw new errors.TypeError('ERR_INVALID_OPT_VALUE', throw new errors.TypeError('ERR_INVALID_OPT_VALUE',
'getTrailers', 'getTrailers',
options.getTrailers); options.getTrailers);
} }
getTrailers = true; streamOptions |= STREAM_OPTION_GET_TRAILERS;
state.getTrailers = options.getTrailers; state.getTrailers = options.getTrailers;
} }
@ -1963,7 +1969,8 @@ class ServerHttp2Stream extends Http2Stream {
if (options.statCheck !== undefined) { if (options.statCheck !== undefined) {
fs.fstat(fd, fs.fstat(fd,
doSendFD.bind(this, session, options, fd, headers, getTrailers)); doSendFD.bind(this, session, options, fd,
headers, streamOptions));
return; return;
} }
@ -1977,7 +1984,7 @@ class ServerHttp2Stream extends Http2Stream {
processRespondWithFD.call(this, fd, headersList, processRespondWithFD.call(this, fd, headersList,
options.offset, options.offset,
options.length, options.length,
getTrailers); streamOptions);
} }
// Initiate a file response on this Http2Stream. The path is passed to // Initiate a file response on this Http2Stream. The path is passed to
@ -2019,14 +2026,14 @@ class ServerHttp2Stream extends Http2Stream {
options.statCheck); options.statCheck);
} }
let getTrailers = false; let streamOptions = 0;
if (options.getTrailers !== undefined) { if (options.getTrailers !== undefined) {
if (typeof options.getTrailers !== 'function') { if (typeof options.getTrailers !== 'function') {
throw new errors.TypeError('ERR_INVALID_OPT_VALUE', throw new errors.TypeError('ERR_INVALID_OPT_VALUE',
'getTrailers', 'getTrailers',
options.getTrailers); options.getTrailers);
} }
getTrailers = true; streamOptions |= STREAM_OPTION_GET_TRAILERS;
state.getTrailers = options.getTrailers; state.getTrailers = options.getTrailers;
} }
@ -2040,7 +2047,7 @@ class ServerHttp2Stream extends Http2Stream {
} }
fs.open(path, 'r', fs.open(path, 'r',
afterOpen.bind(this, session, options, headers, getTrailers)); afterOpen.bind(this, session, options, headers, streamOptions));
} }
// Sends a block of informational headers. In theory, the HTTP/2 spec // Sends a block of informational headers. In theory, the HTTP/2 spec

32
src/node_http2.cc

@ -479,7 +479,7 @@ void Http2Session::SubmitRstStream(const FunctionCallbackInfo<Value>& args) {
void Http2Session::SubmitRequest(const FunctionCallbackInfo<Value>& args) { void Http2Session::SubmitRequest(const FunctionCallbackInfo<Value>& args) {
// args[0] Array of headers // args[0] Array of headers
// args[1] endStream boolean // args[1] options int
// args[2] parentStream ID (for priority spec) // args[2] parentStream ID (for priority spec)
// args[3] weight (for priority spec) // args[3] weight (for priority spec)
// args[4] exclusive boolean (for priority spec) // args[4] exclusive boolean (for priority spec)
@ -492,15 +492,14 @@ void Http2Session::SubmitRequest(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = env->isolate(); Isolate* isolate = env->isolate();
Local<Array> headers = args[0].As<Array>(); Local<Array> headers = args[0].As<Array>();
bool endStream = args[1]->BooleanValue(context).ToChecked(); int options = args[1]->IntegerValue(context).ToChecked();
int32_t parent = args[2]->Int32Value(context).ToChecked(); int32_t parent = args[2]->Int32Value(context).ToChecked();
int32_t weight = args[3]->Int32Value(context).ToChecked(); int32_t weight = args[3]->Int32Value(context).ToChecked();
bool exclusive = args[4]->BooleanValue(context).ToChecked(); bool exclusive = args[4]->BooleanValue(context).ToChecked();
bool getTrailers = args[5]->BooleanValue(context).ToChecked();
DEBUG_HTTP2("Http2Session: submitting request: headers: %d, end-stream: %d, " DEBUG_HTTP2("Http2Session: submitting request: headers: %d, options: %d, "
"parent: %d, weight: %d, exclusive: %d\n", headers->Length(), "parent: %d, weight: %d, exclusive: %d\n", headers->Length(),
endStream, parent, weight, exclusive); options, parent, weight, exclusive);
nghttp2_priority_spec prispec; nghttp2_priority_spec prispec;
nghttp2_priority_spec_init(&prispec, parent, weight, exclusive ? 1 : 0); nghttp2_priority_spec_init(&prispec, parent, weight, exclusive ? 1 : 0);
@ -509,8 +508,7 @@ void Http2Session::SubmitRequest(const FunctionCallbackInfo<Value>& args) {
int32_t ret = session->Nghttp2Session::SubmitRequest(&prispec, int32_t ret = session->Nghttp2Session::SubmitRequest(&prispec,
*list, list.length(), *list, list.length(),
nullptr, endStream, nullptr, options);
getTrailers);
DEBUG_HTTP2("Http2Session: request submitted, response: %d\n", ret); DEBUG_HTTP2("Http2Session: request submitted, response: %d\n", ret);
args.GetReturnValue().Set(ret); args.GetReturnValue().Set(ret);
} }
@ -529,11 +527,10 @@ void Http2Session::SubmitResponse(const FunctionCallbackInfo<Value>& args) {
int32_t id = args[0]->Int32Value(context).ToChecked(); int32_t id = args[0]->Int32Value(context).ToChecked();
Local<Array> headers = args[1].As<Array>(); Local<Array> headers = args[1].As<Array>();
bool endStream = args[2]->BooleanValue(context).ToChecked(); int options = args[2]->IntegerValue(context).ToChecked();
bool getTrailers = args[3]->BooleanValue(context).ToChecked();
DEBUG_HTTP2("Http2Session: submitting response for stream %d: headers: %d, " DEBUG_HTTP2("Http2Session: submitting response for stream %d: headers: %d, "
"end-stream: %d\n", id, headers->Length(), endStream); "options: %d\n", id, headers->Length(), options);
if (!(stream = session->FindStream(id))) { if (!(stream = session->FindStream(id))) {
return args.GetReturnValue().Set(NGHTTP2_ERR_INVALID_STREAM_ID); return args.GetReturnValue().Set(NGHTTP2_ERR_INVALID_STREAM_ID);
@ -542,7 +539,7 @@ void Http2Session::SubmitResponse(const FunctionCallbackInfo<Value>& args) {
Headers list(isolate, context, headers); Headers list(isolate, context, headers);
args.GetReturnValue().Set( args.GetReturnValue().Set(
stream->SubmitResponse(*list, list.length(), endStream, getTrailers)); stream->SubmitResponse(*list, list.length(), options));
} }
void Http2Session::SubmitFile(const FunctionCallbackInfo<Value>& args) { void Http2Session::SubmitFile(const FunctionCallbackInfo<Value>& args) {
@ -566,7 +563,7 @@ void Http2Session::SubmitFile(const FunctionCallbackInfo<Value>& args) {
int64_t offset = args[3]->IntegerValue(context).ToChecked(); int64_t offset = args[3]->IntegerValue(context).ToChecked();
int64_t length = args[4]->IntegerValue(context).ToChecked(); int64_t length = args[4]->IntegerValue(context).ToChecked();
bool getTrailers = args[5]->BooleanValue(context).ToChecked(); int options = args[5]->IntegerValue(context).ToChecked();
CHECK_GE(offset, 0); CHECK_GE(offset, 0);
@ -580,7 +577,7 @@ void Http2Session::SubmitFile(const FunctionCallbackInfo<Value>& args) {
Headers list(isolate, context, headers); Headers list(isolate, context, headers);
args.GetReturnValue().Set(stream->SubmitFile(fd, *list, list.length(), args.GetReturnValue().Set(stream->SubmitFile(fd, *list, list.length(),
offset, length, getTrailers)); offset, length, options));
} }
void Http2Session::SendHeaders(const FunctionCallbackInfo<Value>& args) { void Http2Session::SendHeaders(const FunctionCallbackInfo<Value>& args) {
@ -719,10 +716,10 @@ void Http2Session::SubmitPushPromise(const FunctionCallbackInfo<Value>& args) {
Nghttp2Stream* parent; Nghttp2Stream* parent;
int32_t id = args[0]->Int32Value(context).ToChecked(); int32_t id = args[0]->Int32Value(context).ToChecked();
Local<Array> headers = args[1].As<Array>(); Local<Array> headers = args[1].As<Array>();
bool endStream = args[2]->BooleanValue(context).ToChecked(); int options = args[2]->IntegerValue(context).ToChecked();
DEBUG_HTTP2("Http2Session: submitting push promise for stream %d: " DEBUG_HTTP2("Http2Session: submitting push promise for stream %d: "
"end-stream: %d, headers: %d\n", id, endStream, "options: %d, headers: %d\n", id, options,
headers->Length()); headers->Length());
if (!(parent = session->FindStream(id))) { if (!(parent = session->FindStream(id))) {
@ -732,7 +729,7 @@ void Http2Session::SubmitPushPromise(const FunctionCallbackInfo<Value>& args) {
Headers list(isolate, context, headers); Headers list(isolate, context, headers);
int32_t ret = parent->SubmitPushPromise(*list, list.length(), int32_t ret = parent->SubmitPushPromise(*list, list.length(),
nullptr, endStream); nullptr, options);
DEBUG_HTTP2("Http2Session: push promise submitted, ret: %d\n", ret); DEBUG_HTTP2("Http2Session: push promise submitted, ret: %d\n", ret);
args.GetReturnValue().Set(ret); args.GetReturnValue().Set(ret);
} }
@ -1250,6 +1247,9 @@ void Initialize(Local<Object> target,
NODE_DEFINE_HIDDEN_CONSTANT(constants, NGHTTP2_ERR_STREAM_CLOSED); NODE_DEFINE_HIDDEN_CONSTANT(constants, NGHTTP2_ERR_STREAM_CLOSED);
NODE_DEFINE_CONSTANT(constants, NGHTTP2_ERR_FRAME_SIZE_ERROR); NODE_DEFINE_CONSTANT(constants, NGHTTP2_ERR_FRAME_SIZE_ERROR);
NODE_DEFINE_HIDDEN_CONSTANT(constants, STREAM_OPTION_EMPTY_PAYLOAD);
NODE_DEFINE_HIDDEN_CONSTANT(constants, STREAM_OPTION_GET_TRAILERS);
NODE_DEFINE_CONSTANT(constants, NGHTTP2_FLAG_NONE); NODE_DEFINE_CONSTANT(constants, NGHTTP2_FLAG_NONE);
NODE_DEFINE_CONSTANT(constants, NGHTTP2_FLAG_END_STREAM); NODE_DEFINE_CONSTANT(constants, NGHTTP2_FLAG_END_STREAM);
NODE_DEFINE_CONSTANT(constants, NGHTTP2_FLAG_END_HEADERS); NODE_DEFINE_CONSTANT(constants, NGHTTP2_FLAG_END_HEADERS);

34
src/node_http2_core-inl.h

@ -614,10 +614,10 @@ inline Nghttp2Stream* Nghttp2Stream::Init(
int32_t id, int32_t id,
Nghttp2Session* session, Nghttp2Session* session,
nghttp2_headers_category category, nghttp2_headers_category category,
bool getTrailers) { int options) {
DEBUG_HTTP2("Nghttp2Stream %d: initializing stream\n", id); DEBUG_HTTP2("Nghttp2Stream %d: initializing stream\n", id);
Nghttp2Stream* stream = stream_free_list.pop(); Nghttp2Stream* stream = stream_free_list.pop();
stream->ResetState(id, session, category, getTrailers); stream->ResetState(id, session, category, options);
session->AddStream(stream); session->AddStream(stream);
return stream; return stream;
} }
@ -628,7 +628,7 @@ inline void Nghttp2Stream::ResetState(
int32_t id, int32_t id,
Nghttp2Session* session, Nghttp2Session* session,
nghttp2_headers_category category, nghttp2_headers_category category,
bool getTrailers) { int options) {
DEBUG_HTTP2("Nghttp2Stream %d: resetting stream state\n", id); DEBUG_HTTP2("Nghttp2Stream %d: resetting stream state\n", id);
session_ = session; session_ = session;
queue_head_ = nullptr; queue_head_ = nullptr;
@ -644,7 +644,7 @@ inline void Nghttp2Stream::ResetState(
prev_local_window_size_ = 65535; prev_local_window_size_ = 65535;
queue_head_index_ = 0; queue_head_index_ = 0;
queue_head_offset_ = 0; queue_head_offset_ = 0;
getTrailers_ = getTrailers; getTrailers_ = options & STREAM_OPTION_GET_TRAILERS;
} }
@ -735,7 +735,7 @@ inline int32_t Nghttp2Stream::SubmitPushPromise(
nghttp2_nv* nva, nghttp2_nv* nva,
size_t len, size_t len,
Nghttp2Stream** assigned, Nghttp2Stream** assigned,
bool emptyPayload) { int options) {
CHECK_GT(len, 0); CHECK_GT(len, 0);
DEBUG_HTTP2("Nghttp2Stream %d: sending push promise\n", id_); DEBUG_HTTP2("Nghttp2Stream %d: sending push promise\n", id_);
int32_t ret = nghttp2_submit_push_promise(session_->session(), int32_t ret = nghttp2_submit_push_promise(session_->session(),
@ -744,7 +744,8 @@ inline int32_t Nghttp2Stream::SubmitPushPromise(
nullptr); nullptr);
if (ret > 0) { if (ret > 0) {
auto stream = Nghttp2Stream::Init(ret, session_); auto stream = Nghttp2Stream::Init(ret, session_);
if (emptyPayload) stream->Shutdown(); if (options & STREAM_OPTION_EMPTY_PAYLOAD)
stream->Shutdown();
if (assigned != nullptr) *assigned = stream; if (assigned != nullptr) *assigned = stream;
} }
return ret; return ret;
@ -756,16 +757,15 @@ inline int32_t Nghttp2Stream::SubmitPushPromise(
// be sent. // be sent.
inline int Nghttp2Stream::SubmitResponse(nghttp2_nv* nva, inline int Nghttp2Stream::SubmitResponse(nghttp2_nv* nva,
size_t len, size_t len,
bool emptyPayload, int options) {
bool getTrailers) {
CHECK_GT(len, 0); CHECK_GT(len, 0);
DEBUG_HTTP2("Nghttp2Stream %d: submitting response\n", id_); DEBUG_HTTP2("Nghttp2Stream %d: submitting response\n", id_);
getTrailers_ = getTrailers; getTrailers_ = options & STREAM_OPTION_GET_TRAILERS;
nghttp2_data_provider* provider = nullptr; nghttp2_data_provider* provider = nullptr;
nghttp2_data_provider prov; nghttp2_data_provider prov;
prov.source.ptr = this; prov.source.ptr = this;
prov.read_callback = Nghttp2Session::OnStreamRead; prov.read_callback = Nghttp2Session::OnStreamRead;
if (!emptyPayload && IsWritable()) if (IsWritable() && !(options & STREAM_OPTION_EMPTY_PAYLOAD))
provider = &prov; provider = &prov;
return nghttp2_submit_response(session_->session(), id_, return nghttp2_submit_response(session_->session(), id_,
@ -777,11 +777,11 @@ inline int Nghttp2Stream::SubmitFile(int fd,
nghttp2_nv* nva, size_t len, nghttp2_nv* nva, size_t len,
int64_t offset, int64_t offset,
int64_t length, int64_t length,
bool getTrailers) { int options) {
CHECK_GT(len, 0); CHECK_GT(len, 0);
CHECK_GT(fd, 0); CHECK_GT(fd, 0);
DEBUG_HTTP2("Nghttp2Stream %d: submitting file\n", id_); DEBUG_HTTP2("Nghttp2Stream %d: submitting file\n", id_);
getTrailers_ = getTrailers; getTrailers_ = options & STREAM_OPTION_GET_TRAILERS;
nghttp2_data_provider prov; nghttp2_data_provider prov;
prov.source.ptr = this; prov.source.ptr = this;
prov.source.fd = fd; prov.source.fd = fd;
@ -802,15 +802,14 @@ inline int32_t Nghttp2Session::SubmitRequest(
nghttp2_nv* nva, nghttp2_nv* nva,
size_t len, size_t len,
Nghttp2Stream** assigned, Nghttp2Stream** assigned,
bool emptyPayload, int options) {
bool getTrailers) {
CHECK_GT(len, 0); CHECK_GT(len, 0);
DEBUG_HTTP2("Nghttp2Session: submitting request\n"); DEBUG_HTTP2("Nghttp2Session: submitting request\n");
nghttp2_data_provider* provider = nullptr; nghttp2_data_provider* provider = nullptr;
nghttp2_data_provider prov; nghttp2_data_provider prov;
prov.source.ptr = this; prov.source.ptr = this;
prov.read_callback = OnStreamRead; prov.read_callback = OnStreamRead;
if (!emptyPayload) if (!(options & STREAM_OPTION_EMPTY_PAYLOAD))
provider = &prov; provider = &prov;
int32_t ret = nghttp2_submit_request(session_, int32_t ret = nghttp2_submit_request(session_,
prispec, nva, len, prispec, nva, len,
@ -819,8 +818,9 @@ inline int32_t Nghttp2Session::SubmitRequest(
if (ret > 0) { if (ret > 0) {
Nghttp2Stream* stream = Nghttp2Stream::Init(ret, this, Nghttp2Stream* stream = Nghttp2Stream::Init(ret, this,
NGHTTP2_HCAT_HEADERS, NGHTTP2_HCAT_HEADERS,
getTrailers); options);
if (emptyPayload) stream->Shutdown(); if (options & STREAM_OPTION_EMPTY_PAYLOAD)
stream->Shutdown();
if (assigned != nullptr) *assigned = stream; if (assigned != nullptr) *assigned = stream;
} }
return ret; return ret;

18
src/node_http2_core.h

@ -68,6 +68,10 @@ enum nghttp2_stream_flags {
NGHTTP2_STREAM_FLAG_DESTROYED = 0x10 NGHTTP2_STREAM_FLAG_DESTROYED = 0x10
}; };
enum nghttp2_stream_options {
STREAM_OPTION_EMPTY_PAYLOAD = 0x1,
STREAM_OPTION_GET_TRAILERS = 0x2,
};
// Callbacks // Callbacks
typedef void (*nghttp2_stream_write_cb)( typedef void (*nghttp2_stream_write_cb)(
@ -127,8 +131,7 @@ class Nghttp2Session {
nghttp2_nv* nva, nghttp2_nv* nva,
size_t len, size_t len,
Nghttp2Stream** assigned = nullptr, Nghttp2Stream** assigned = nullptr,
bool emptyPayload = true, int options = 0);
bool getTrailers = false);
// Submits a notice to the connected peer that the session is in the // Submits a notice to the connected peer that the session is in the
// process of shutting down. // process of shutting down.
@ -299,7 +302,7 @@ class Nghttp2Stream {
int32_t id, int32_t id,
Nghttp2Session* session, Nghttp2Session* session,
nghttp2_headers_category category = NGHTTP2_HCAT_HEADERS, nghttp2_headers_category category = NGHTTP2_HCAT_HEADERS,
bool getTrailers = false); int options = 0);
inline ~Nghttp2Stream() { inline ~Nghttp2Stream() {
CHECK_EQ(session_, nullptr); CHECK_EQ(session_, nullptr);
@ -319,7 +322,7 @@ class Nghttp2Stream {
int32_t id, int32_t id,
Nghttp2Session* session, Nghttp2Session* session,
nghttp2_headers_category category = NGHTTP2_HCAT_HEADERS, nghttp2_headers_category category = NGHTTP2_HCAT_HEADERS,
bool getTrailers = false); int options = 0);
// Destroy this stream instance and free all held memory. // Destroy this stream instance and free all held memory.
// Note that this will free queued outbound and inbound // Note that this will free queued outbound and inbound
@ -347,15 +350,14 @@ class Nghttp2Stream {
// Initiate a response on this stream. // Initiate a response on this stream.
inline int SubmitResponse(nghttp2_nv* nva, inline int SubmitResponse(nghttp2_nv* nva,
size_t len, size_t len,
bool emptyPayload = false, int options);
bool getTrailers = false);
// Send data read from a file descriptor as the response on this stream. // Send data read from a file descriptor as the response on this stream.
inline int SubmitFile(int fd, inline int SubmitFile(int fd,
nghttp2_nv* nva, size_t len, nghttp2_nv* nva, size_t len,
int64_t offset, int64_t offset,
int64_t length, int64_t length,
bool getTrailers = false); int options);
// Submit informational headers for this stream // Submit informational headers for this stream
inline int SubmitInfo(nghttp2_nv* nva, size_t len); inline int SubmitInfo(nghttp2_nv* nva, size_t len);
@ -372,7 +374,7 @@ class Nghttp2Stream {
nghttp2_nv* nva, nghttp2_nv* nva,
size_t len, size_t len,
Nghttp2Stream** assigned = nullptr, Nghttp2Stream** assigned = nullptr,
bool writable = true); int options = 0);
// Marks the Writable side of the stream as being shutdown // Marks the Writable side of the stream as being shutdown
inline void Shutdown() { inline void Shutdown() {

Loading…
Cancel
Save