@@ -186,6 +186,18 @@ inline void Http2Settings::RefreshDefaults(Environment* env) {
186186 (1 << IDX_SETTINGS_MAX_HEADER_LIST_SIZE);
187187}
188188
189+ Http2Priority::Http2Priority (Environment* env,
190+ Local<Value> parent,
191+ Local<Value> weight,
192+ Local<Value> exclusive) {
193+ Local<Context> context = env->context ();
194+ int32_t parent_ = parent->Int32Value (context).ToChecked ();
195+ int32_t weight_ = weight->Int32Value (context).ToChecked ();
196+ bool exclusive_ = exclusive->BooleanValue (context).ToChecked ();
197+ DEBUG_HTTP2 (" Http2Priority: parent: %d, weight: %d, exclusive: %d\n " ,
198+ parent_, weight_, exclusive_);
199+ nghttp2_priority_spec_init (&spec, parent_, weight_, exclusive_ ? 1 : 0 );
200+ }
189201
190202Http2Session::Http2Session (Environment* env,
191203 Local<Object> wrap,
@@ -267,12 +279,8 @@ ssize_t Http2Session::OnCallbackPadding(size_t frameLen,
267279 buffer[PADDING_BUF_RETURN_VALUE] = frameLen;
268280 MakeCallback (env ()->ongetpadding_string (), 0 , nullptr );
269281 uint32_t retval = buffer[PADDING_BUF_RETURN_VALUE];
270- retval = retval <= maxPayloadLen ? retval : maxPayloadLen;
271- retval = retval >= frameLen ? retval : frameLen;
272- #if defined(DEBUG) && DEBUG
273- CHECK_GE (retval, frameLen);
274- CHECK_LE (retval, maxPayloadLen);
275- #endif
282+ retval = std::min (retval, static_cast <uint32_t >(maxPayloadLen));
283+ retval = std::max (retval, static_cast <uint32_t >(frameLen));
276284 return retval;
277285}
278286
@@ -454,30 +462,18 @@ void Http2Session::SubmitPriority(const FunctionCallbackInfo<Value>& args) {
454462 ASSIGN_OR_RETURN_UNWRAP (&session, args.Holder ());
455463 Local<Context> context = env->context ();
456464
457- nghttp2_priority_spec spec;
458465 int32_t id = args[0 ]->Int32Value (context).ToChecked ();
459- int32_t parent = args[1 ]->Int32Value (context).ToChecked ();
460- int32_t weight = args[2 ]->Int32Value (context).ToChecked ();
461- bool exclusive = args[3 ]->BooleanValue (context).ToChecked ();
466+ Http2Priority priority (env, args[1 ], args[2 ], args[3 ]);
462467 bool silent = args[4 ]->BooleanValue (context).ToChecked ();
463- DEBUG_HTTP2 (" Http2Session: submitting priority for stream %d: "
464- " parent: %d, weight: %d, exclusive: %d, silent: %d\n " ,
465- id, parent, weight, exclusive, silent);
466-
467- #if defined(DEBUG) && DEBUG
468- CHECK_GT (id, 0 );
469- CHECK_GE (parent, 0 );
470- CHECK_GE (weight, 0 );
471- #endif
468+ DEBUG_HTTP2 (" Http2Session: submitting priority for stream %d" , id);
472469
473470 Nghttp2Stream* stream;
474471 if (!(stream = session->FindStream (id))) {
475472 // invalid stream
476473 return args.GetReturnValue ().Set (NGHTTP2_ERR_INVALID_STREAM_ID);
477474 }
478- nghttp2_priority_spec_init (&spec, parent, weight, exclusive ? 1 : 0 );
479475
480- args.GetReturnValue ().Set (stream->SubmitPriority (&spec , silent));
476+ args.GetReturnValue ().Set (stream->SubmitPriority (*priority , silent));
481477}
482478
483479void Http2Session::SubmitSettings (const FunctionCallbackInfo<Value>& args) {
@@ -533,20 +529,14 @@ void Http2Session::SubmitRequest(const FunctionCallbackInfo<Value>& args) {
533529
534530 Local<Array> headers = args[0 ].As <Array>();
535531 int options = args[1 ]->IntegerValue (context).ToChecked ();
536- int32_t parent = args[2 ]->Int32Value (context).ToChecked ();
537- int32_t weight = args[3 ]->Int32Value (context).ToChecked ();
538- bool exclusive = args[4 ]->BooleanValue (context).ToChecked ();
539-
540- DEBUG_HTTP2 (" Http2Session: submitting request: headers: %d, options: %d, "
541- " parent: %d, weight: %d, exclusive: %d\n " , headers->Length (),
542- options, parent, weight, exclusive);
532+ Http2Priority priority (env, args[2 ], args[3 ], args[4 ]);
543533
544- nghttp2_priority_spec prispec;
545- nghttp2_priority_spec_init (&prispec, parent, weight, exclusive ? 1 : 0 );
534+ DEBUG_HTTP2 ( " Http2Session: submitting request: headers: %d, options: %d \n " ,
535+ headers-> Length (), options );
546536
547537 Headers list (isolate, context, headers);
548538
549- int32_t ret = session->Nghttp2Session ::SubmitRequest (&prispec ,
539+ int32_t ret = session->Nghttp2Session ::SubmitRequest (*priority ,
550540 *list, list.length (),
551541 nullptr , options);
552542 DEBUG_HTTP2 (" Http2Session: request submitted, response: %d\n " , ret);
0 commit comments