@@ -186,6 +186,18 @@ inline void Http2Settings::RefreshDefaults(Environment* env) {
186
186
(1 << IDX_SETTINGS_MAX_HEADER_LIST_SIZE);
187
187
}
188
188
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
+ }
189
201
190
202
Http2Session::Http2Session (Environment* env,
191
203
Local<Object> wrap,
@@ -267,12 +279,8 @@ ssize_t Http2Session::OnCallbackPadding(size_t frameLen,
267
279
buffer[PADDING_BUF_RETURN_VALUE] = frameLen;
268
280
MakeCallback (env ()->ongetpadding_string (), 0 , nullptr );
269
281
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));
276
284
return retval;
277
285
}
278
286
@@ -454,30 +462,18 @@ void Http2Session::SubmitPriority(const FunctionCallbackInfo<Value>& args) {
454
462
ASSIGN_OR_RETURN_UNWRAP (&session, args.Holder ());
455
463
Local<Context> context = env->context ();
456
464
457
- nghttp2_priority_spec spec;
458
465
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 ]);
462
467
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);
472
469
473
470
Nghttp2Stream* stream;
474
471
if (!(stream = session->FindStream (id))) {
475
472
// invalid stream
476
473
return args.GetReturnValue ().Set (NGHTTP2_ERR_INVALID_STREAM_ID);
477
474
}
478
- nghttp2_priority_spec_init (&spec, parent, weight, exclusive ? 1 : 0 );
479
475
480
- args.GetReturnValue ().Set (stream->SubmitPriority (&spec , silent));
476
+ args.GetReturnValue ().Set (stream->SubmitPriority (*priority , silent));
481
477
}
482
478
483
479
void Http2Session::SubmitSettings (const FunctionCallbackInfo<Value>& args) {
@@ -533,20 +529,14 @@ void Http2Session::SubmitRequest(const FunctionCallbackInfo<Value>& args) {
533
529
534
530
Local<Array> headers = args[0 ].As <Array>();
535
531
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 ]);
543
533
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 );
546
536
547
537
Headers list (isolate, context, headers);
548
538
549
- int32_t ret = session->Nghttp2Session ::SubmitRequest (&prispec ,
539
+ int32_t ret = session->Nghttp2Session ::SubmitRequest (*priority ,
550
540
*list, list.length (),
551
541
nullptr , options);
552
542
DEBUG_HTTP2 (" Http2Session: request submitted, response: %d\n " , ret);
0 commit comments