@@ -180,6 +180,18 @@ inline void Http2Settings::RefreshDefaults(Environment* env) {
180
180
(1 << IDX_SETTINGS_MAX_FRAME_SIZE);
181
181
}
182
182
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
+ }
183
195
184
196
Http2Session::Http2Session (Environment* env,
185
197
Local<Object> wrap,
@@ -258,12 +270,8 @@ ssize_t Http2Session::OnCallbackPadding(size_t frameLen,
258
270
buffer[PADDING_BUF_RETURN_VALUE] = frameLen;
259
271
MakeCallback (env ()->ongetpadding_string (), 0 , nullptr );
260
272
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));
267
275
return retval;
268
276
}
269
277
@@ -445,30 +453,18 @@ void Http2Session::SubmitPriority(const FunctionCallbackInfo<Value>& args) {
445
453
ASSIGN_OR_RETURN_UNWRAP (&session, args.Holder ());
446
454
Local<Context> context = env->context ();
447
455
448
- nghttp2_priority_spec spec;
449
456
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 ]);
453
458
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);
463
460
464
461
Nghttp2Stream* stream;
465
462
if (!(stream = session->FindStream (id))) {
466
463
// invalid stream
467
464
return args.GetReturnValue ().Set (NGHTTP2_ERR_INVALID_STREAM_ID);
468
465
}
469
- nghttp2_priority_spec_init (&spec, parent, weight, exclusive ? 1 : 0 );
470
466
471
- args.GetReturnValue ().Set (stream->SubmitPriority (&spec , silent));
467
+ args.GetReturnValue ().Set (stream->SubmitPriority (*priority , silent));
472
468
}
473
469
474
470
void Http2Session::SubmitSettings (const FunctionCallbackInfo<Value>& args) {
@@ -524,20 +520,14 @@ void Http2Session::SubmitRequest(const FunctionCallbackInfo<Value>& args) {
524
520
525
521
Local<Array> headers = args[0 ].As <Array>();
526
522
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 ]);
534
524
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 );
537
527
538
528
Headers list (isolate, context, headers);
539
529
540
- int32_t ret = session->Nghttp2Session ::SubmitRequest (&prispec ,
530
+ int32_t ret = session->Nghttp2Session ::SubmitRequest (*priority ,
541
531
*list, list.length (),
542
532
nullptr , options);
543
533
DEBUG_HTTP2 (" Http2Session: request submitted, response: %d\n " , ret);
0 commit comments