@@ -180,6 +180,18 @@ inline void Http2Settings::RefreshDefaults(Environment* env) {
180180 (1 << IDX_SETTINGS_MAX_FRAME_SIZE);
181181}
182182
183+ Http2Priority::Http2Priority (Environment* env,
184+ Local<Value> parent,
185+ Local<Value> weight,
186+ Local<Value> exclusive) {
187+ Local<Context> context = env->context ();
188+ int32_t parent_ = parent->Int32Value (context).ToChecked ();
189+ int32_t weight_ = weight->Int32Value (context).ToChecked ();
190+ bool exclusive_ = exclusive->BooleanValue (context).ToChecked ();
191+ DEBUG_HTTP2 (" Http2Priority: parent: %d, weight: %d, exclusive: %d\n " ,
192+ parent_, weight_, exclusive_);
193+ nghttp2_priority_spec_init (&spec, parent_, weight_, exclusive_ ? 1 : 0 );
194+ }
183195
184196Http2Session::Http2Session (Environment* env,
185197 Local<Object> wrap,
@@ -258,12 +270,8 @@ ssize_t Http2Session::OnCallbackPadding(size_t frameLen,
258270 buffer[PADDING_BUF_RETURN_VALUE] = frameLen;
259271 MakeCallback (env ()->ongetpadding_string (), 0 , nullptr );
260272 uint32_t retval = buffer[PADDING_BUF_RETURN_VALUE];
261- retval = retval <= maxPayloadLen ? retval : maxPayloadLen;
262- retval = retval >= frameLen ? retval : frameLen;
263- #if defined(DEBUG) && DEBUG
264- CHECK_GE (retval, frameLen);
265- CHECK_LE (retval, maxPayloadLen);
266- #endif
273+ retval = std::min (retval, static_cast <uint32_t >(maxPayloadLen));
274+ retval = std::max (retval, static_cast <uint32_t >(frameLen));
267275 return retval;
268276}
269277
@@ -445,30 +453,18 @@ void Http2Session::SubmitPriority(const FunctionCallbackInfo<Value>& args) {
445453 ASSIGN_OR_RETURN_UNWRAP (&session, args.Holder ());
446454 Local<Context> context = env->context ();
447455
448- nghttp2_priority_spec spec;
449456 int32_t id = args[0 ]->Int32Value (context).ToChecked ();
450- int32_t parent = args[1 ]->Int32Value (context).ToChecked ();
451- int32_t weight = args[2 ]->Int32Value (context).ToChecked ();
452- bool exclusive = args[3 ]->BooleanValue (context).ToChecked ();
457+ Http2Priority priority (env, args[1 ], args[2 ], args[3 ]);
453458 bool silent = args[4 ]->BooleanValue (context).ToChecked ();
454- DEBUG_HTTP2 (" Http2Session: submitting priority for stream %d: "
455- " parent: %d, weight: %d, exclusive: %d, silent: %d\n " ,
456- id, parent, weight, exclusive, silent);
457-
458- #if defined(DEBUG) && DEBUG
459- CHECK_GT (id, 0 );
460- CHECK_GE (parent, 0 );
461- CHECK_GE (weight, 0 );
462- #endif
459+ DEBUG_HTTP2 (" Http2Session: submitting priority for stream %d" , id);
463460
464461 Nghttp2Stream* stream;
465462 if (!(stream = session->FindStream (id))) {
466463 // invalid stream
467464 return args.GetReturnValue ().Set (NGHTTP2_ERR_INVALID_STREAM_ID);
468465 }
469- nghttp2_priority_spec_init (&spec, parent, weight, exclusive ? 1 : 0 );
470466
471- args.GetReturnValue ().Set (stream->SubmitPriority (&spec , silent));
467+ args.GetReturnValue ().Set (stream->SubmitPriority (*priority , silent));
472468}
473469
474470void Http2Session::SubmitSettings (const FunctionCallbackInfo<Value>& args) {
@@ -524,20 +520,14 @@ void Http2Session::SubmitRequest(const FunctionCallbackInfo<Value>& args) {
524520
525521 Local<Array> headers = args[0 ].As <Array>();
526522 int options = args[1 ]->IntegerValue (context).ToChecked ();
527- int32_t parent = args[2 ]->Int32Value (context).ToChecked ();
528- int32_t weight = args[3 ]->Int32Value (context).ToChecked ();
529- bool exclusive = args[4 ]->BooleanValue (context).ToChecked ();
530-
531- DEBUG_HTTP2 (" Http2Session: submitting request: headers: %d, options: %d, "
532- " parent: %d, weight: %d, exclusive: %d\n " , headers->Length (),
533- options, parent, weight, exclusive);
523+ Http2Priority priority (env, args[2 ], args[3 ], args[4 ]);
534524
535- nghttp2_priority_spec prispec;
536- nghttp2_priority_spec_init (&prispec, parent, weight, exclusive ? 1 : 0 );
525+ DEBUG_HTTP2 ( " Http2Session: submitting request: headers: %d, options: %d \n " ,
526+ headers-> Length (), options );
537527
538528 Headers list (isolate, context, headers);
539529
540- int32_t ret = session->Nghttp2Session ::SubmitRequest (&prispec ,
530+ int32_t ret = session->Nghttp2Session ::SubmitRequest (*priority ,
541531 *list, list.length (),
542532 nullptr , options);
543533 DEBUG_HTTP2 (" Http2Session: request submitted, response: %d\n " , ret);
0 commit comments