@@ -111,11 +111,13 @@ void Http2Session::OnFreeSession() {
111
111
112
112
ssize_t Http2Session::OnMaxFrameSizePadding (size_t frameLen,
113
113
size_t maxPayloadLen) {
114
+ DEBUG_HTTP2 (" Http2Session: using max frame size padding\n " );
114
115
return maxPayloadLen;
115
116
}
116
117
117
118
ssize_t Http2Session::OnCallbackPadding (size_t frameLen,
118
119
size_t maxPayloadLen) {
120
+ DEBUG_HTTP2 (" Http2Session: using callback padding\n " );
119
121
Isolate* isolate = env ()->isolate ();
120
122
Local<Context> context = env ()->context ();
121
123
@@ -146,7 +148,9 @@ void Http2Session::SetNextStreamID(const FunctionCallbackInfo<Value>& args) {
146
148
Http2Session* session;
147
149
ASSIGN_OR_RETURN_UNWRAP (&session, args.Holder ());
148
150
nghttp2_session* s = session->session ();
149
- nghttp2_session_set_next_stream_id (s, args[0 ]->Int32Value ());
151
+ int32_t id = args[0 ]->Int32Value ();
152
+ DEBUG_HTTP2 (" Http2Session: setting next stream id to %d\n " , id);
153
+ nghttp2_session_set_next_stream_id (s, id);
150
154
}
151
155
152
156
void HttpErrorString (const FunctionCallbackInfo<Value>& args) {
@@ -193,6 +197,7 @@ void PackSettings(const FunctionCallbackInfo<Value>& args) {
193
197
194
198
// Used to fill in the spec defined initial values for each setting.
195
199
void RefreshDefaultSettings (const FunctionCallbackInfo<Value>& args) {
200
+ DEBUG_HTTP2 (" Http2Session: refreshing default settings\n " );
196
201
Environment* env = Environment::GetCurrent (args);
197
202
int32_t * const buffer = env->http2_default_settings_buffer ();
198
203
buffer[IDX_SETTINGS_HEADER_TABLE_SIZE] =
@@ -207,6 +212,7 @@ void RefreshDefaultSettings(const FunctionCallbackInfo<Value>& args) {
207
212
208
213
template <get_setting fn>
209
214
void RefreshSettings (const FunctionCallbackInfo<Value>& args) {
215
+ DEBUG_HTTP2 (" Http2Session: refreshing settings for session\n " );
210
216
CHECK_EQ (args.Length (), 1 );
211
217
CHECK (args[0 ]->IsObject ());
212
218
Http2Session* session;
@@ -231,6 +237,7 @@ void RefreshSettings(const FunctionCallbackInfo<Value>& args) {
231
237
232
238
// Used to fill in the spec defined initial values for each setting.
233
239
void RefreshSessionState (const FunctionCallbackInfo<Value>& args) {
240
+ DEBUG_HTTP2 (" Http2Session: refreshing session state\n " );
234
241
CHECK_EQ (args.Length (), 1 );
235
242
CHECK (args[0 ]->IsObject ());
236
243
Environment* env = Environment::GetCurrent (args);
@@ -263,9 +270,10 @@ void RefreshStreamState(const FunctionCallbackInfo<Value>& args) {
263
270
CHECK_EQ (args.Length (), 2 );
264
271
CHECK (args[0 ]->IsObject ());
265
272
CHECK (args[1 ]->IsNumber ());
273
+ int32_t id = args[1 ]->Int32Value ();
274
+ DEBUG_HTTP2 (" Http2Session: refreshing stream %d state\n " , id);
266
275
Http2Session* session;
267
276
ASSIGN_OR_RETURN_UNWRAP (&session, args[0 ].As <Object>());
268
- int32_t id = args[1 ]->Int32Value ();
269
277
nghttp2_session* s = session->session ();
270
278
Nghttp2Stream* stream;
271
279
@@ -313,7 +321,7 @@ void Http2Session::New(const FunctionCallbackInfo<Value>& args) {
313
321
314
322
nghttp2_session_type type =
315
323
static_cast <nghttp2_session_type>(args[0 ]->IntegerValue ());
316
-
324
+ DEBUG_HTTP2 ( " Http2Session: creating a session of type: %d \n " , type);
317
325
new Http2Session (env, args.This (), type, args[1 ]);
318
326
}
319
327
@@ -327,6 +335,7 @@ void Http2Session::Consume(const FunctionCallbackInfo<Value>& args) {
327
335
}
328
336
329
337
void Http2Session::Destroy (const FunctionCallbackInfo<Value>& args) {
338
+ DEBUG_HTTP2 (" Http2Session: destroying session\n " );
330
339
Http2Session* session;
331
340
ASSIGN_OR_RETURN_UNWRAP (&session, args.Holder ());
332
341
session->Unconsume ();
@@ -343,6 +352,9 @@ void Http2Session::SubmitPriority(const FunctionCallbackInfo<Value>& args) {
343
352
int32_t weight = args[2 ]->Int32Value ();
344
353
bool exclusive = args[3 ]->BooleanValue ();
345
354
bool silent = args[4 ]->BooleanValue ();
355
+ DEBUG_HTTP2 (" Http2Session: submitting priority for stream %d: "
356
+ " parent: %d, weight: %d, exclusive: %d, silent: %d\n " ,
357
+ id, parent, weight, exclusive, silent);
346
358
CHECK_GT (id, 0 );
347
359
CHECK_GE (parent, 0 );
348
360
CHECK_GE (weight, 0 );
@@ -394,13 +406,17 @@ void Http2Session::SubmitRstStream(const FunctionCallbackInfo<Value>& args) {
394
406
Http2Session* session;
395
407
ASSIGN_OR_RETURN_UNWRAP (&session, args.Holder ());
396
408
409
+ int32_t id = args[0 ]->Int32Value ();
410
+ uint32_t code = args[1 ]->Uint32Value ();
411
+
397
412
Nghttp2Stream* stream;
398
- if (!(stream = session->FindStream (args[ 0 ]-> Int32Value () ))) {
413
+ if (!(stream = session->FindStream (id ))) {
399
414
// invalid stream
400
415
return args.GetReturnValue ().Set (NGHTTP2_ERR_INVALID_STREAM_ID);
401
416
}
402
- args.GetReturnValue ().Set (
403
- stream->SubmitRstStream (args[1 ]->Uint32Value ()));
417
+ DEBUG_HTTP2 (" Http2Session: sending rst_stream for stream %d, code: %d\n " ,
418
+ id, code);
419
+ args.GetReturnValue ().Set (stream->SubmitRstStream (code));
404
420
}
405
421
406
422
void Http2Session::SubmitRequest (const FunctionCallbackInfo<Value>& args) {
@@ -418,19 +434,24 @@ void Http2Session::SubmitRequest(const FunctionCallbackInfo<Value>& args) {
418
434
419
435
Local<Array> headers = args[0 ].As <Array>();
420
436
bool endStream = args[1 ]->BooleanValue ();
421
- int32_t parent_id = args[2 ]->Int32Value ();
437
+ int32_t parent = args[2 ]->Int32Value ();
422
438
int32_t weight = args[3 ]->Int32Value ();
423
439
bool exclusive = args[4 ]->BooleanValue ();
424
440
441
+ DEBUG_HTTP2 (" Http2Session: submitting request: headers: %d, end-stream: %d, "
442
+ " parent: %d, weight: %d, exclusive: %d" , headers->Length (),
443
+ endStream, parent, weight, exclusive);
444
+
425
445
nghttp2_priority_spec prispec;
426
- nghttp2_priority_spec_init (&prispec, parent_id , weight, exclusive ? 1 : 0 );
446
+ nghttp2_priority_spec_init (&prispec, parent , weight, exclusive ? 1 : 0 );
427
447
428
448
Headers list (isolate, headers);
429
449
430
- args.GetReturnValue ().Set (
431
- session->Nghttp2Session ::SubmitRequest (&prispec,
432
- *list, list.length (),
433
- nullptr , endStream));
450
+ int32_t ret = session->Nghttp2Session ::SubmitRequest (&prispec,
451
+ *list, list.length (),
452
+ nullptr , endStream);
453
+ DEBUG_HTTP2 (" Http2Session: request submitted, response: %d\n " , ret);
454
+ args.GetReturnValue ().Set (ret);
434
455
}
435
456
436
457
void Http2Session::SubmitResponse (const FunctionCallbackInfo<Value>& args) {
@@ -444,10 +465,14 @@ void Http2Session::SubmitResponse(const FunctionCallbackInfo<Value>& args) {
444
465
Environment* env = session->env ();
445
466
Isolate* isolate = env->isolate ();
446
467
468
+ int32_t id = args[0 ]->Int32Value ();
447
469
Local<Array> headers = args[1 ].As <Array>();
448
470
bool endStream = args[2 ]->BooleanValue ();
449
471
450
- if (!(stream = session->FindStream (args[0 ]->Int32Value ()))) {
472
+ DEBUG_HTTP2 (" Http2Session: submitting response for stream %d: headers: %d, "
473
+ " end-stream: %d\n " , id, headers->Length (), endStream);
474
+
475
+ if (!(stream = session->FindStream (id))) {
451
476
return args.GetReturnValue ().Set (NGHTTP2_ERR_INVALID_STREAM_ID);
452
477
}
453
478
@@ -468,11 +493,16 @@ void Http2Session::SendHeaders(const FunctionCallbackInfo<Value>& args) {
468
493
Environment* env = session->env ();
469
494
Isolate* isolate = env->isolate ();
470
495
471
- if (!(stream = session->FindStream (args[0 ]->Int32Value ()))) {
496
+ int32_t id = args[0 ]->Int32Value ();
497
+ Local<Array> headers = args[1 ].As <Array>();
498
+
499
+ DEBUG_HTTP2 (" Http2Session: sending informational headers for stream %d, "
500
+ " count: %d\n " , id, headers->Length ());
501
+
502
+ if (!(stream = session->FindStream (id))) {
472
503
return args.GetReturnValue ().Set (NGHTTP2_ERR_INVALID_STREAM_ID);
473
504
}
474
505
475
- Local<Array> headers = args[1 ].As <Array>();
476
506
Headers list (isolate, headers);
477
507
478
508
args.GetReturnValue ().Set (stream->SubmitInfo (*list, list.length ()));
@@ -483,7 +513,9 @@ void Http2Session::ShutdownStream(const FunctionCallbackInfo<Value>& args) {
483
513
Http2Session* session;
484
514
ASSIGN_OR_RETURN_UNWRAP (&session, args.Holder ());
485
515
Nghttp2Stream* stream;
486
- if (!(stream = session->FindStream (args[0 ]->Int32Value ()))) {
516
+ int32_t id = args[0 ]->Int32Value ();
517
+ DEBUG_HTTP2 (" Http2Session: shutting down stream %d\n " , id);
518
+ if (!(stream = session->FindStream (id))) {
487
519
return args.GetReturnValue ().Set (NGHTTP2_ERR_INVALID_STREAM_ID);
488
520
}
489
521
stream->Shutdown ();
@@ -517,10 +549,16 @@ void Http2Session::StreamReadStop(const FunctionCallbackInfo<Value>& args) {
517
549
static void DoSessionShutdown (SessionShutdownWrap* req) {
518
550
int status;
519
551
if (req->graceful ()) {
552
+ DEBUG_HTTP2 (" Http2Session: initiating graceful session shutdown. "
553
+ " last-stream-id: %d, code: %d\n " ,
554
+ req->lastStreamID (), req->errorCode ());
520
555
status = nghttp2_session_terminate_session2 (req->handle ()->session (),
521
556
req->lastStreamID (),
522
557
req->errorCode ());
523
558
} else {
559
+ DEBUG_HTTP2 (" Http2Session: initiating immediate shutdown. "
560
+ " last-stream-id: %d, code: %d, opaque-data: %d\n " ,
561
+ req->lastStreamID (), req->errorCode (), req->opaqueDataLength ());
524
562
status = nghttp2_submit_goaway (req->handle ()->session (),
525
563
NGHTTP2_FLAG_NONE,
526
564
req->lastStreamID (),
@@ -593,6 +631,7 @@ void Http2Session::DestroyStream(const FunctionCallbackInfo<Value>& args) {
593
631
CHECK_EQ (args.Length (), 1 );
594
632
CHECK (args[0 ]->IsNumber ());
595
633
int32_t id = args[0 ]->Int32Value ();
634
+ DEBUG_HTTP2 (" Http2Session: destroy stream %d\n " , id);
596
635
Nghttp2Stream* stream;
597
636
if (!(stream = session->FindStream (id))) {
598
637
return args.GetReturnValue ().Set (NGHTTP2_ERR_INVALID_STREAM_ID);
@@ -610,17 +649,23 @@ void Http2Session::SubmitPushPromise(const FunctionCallbackInfo<Value>& args) {
610
649
CHECK (args[1 ]->IsArray ()); // headers array
611
650
612
651
Nghttp2Stream* parent;
652
+ int32_t id = args[0 ]->Int32Value ();
653
+ Local<Array> headers = args[1 ].As <Array>();
654
+ bool endStream = args[2 ]->BooleanValue ();
613
655
614
- if (!(parent = session->FindStream (args[0 ]->Int32Value ()))) {
656
+ DEBUG_HTTP2 (" Http2Session: submitting push promise for stream %d: "
657
+ " end-stream: %d, headers: %d\n " , id, endStream,
658
+ headers->Length ());
659
+
660
+ if (!(parent = session->FindStream (id))) {
615
661
return args.GetReturnValue ().Set (NGHTTP2_ERR_INVALID_STREAM_ID);
616
662
}
617
663
618
- Local<Array> headers = args[1 ].As <Array>();
619
- bool endStream = args[2 ]->BooleanValue ();
620
664
Headers list (isolate, headers);
621
665
622
666
int32_t ret = parent->SubmitPushPromise (*list, list.length (),
623
667
nullptr , endStream);
668
+ DEBUG_HTTP2 (" Http2Session: push promise submitted, ret: %d\n " , ret);
624
669
args.GetReturnValue ().Set (ret);
625
670
}
626
671
@@ -674,7 +719,6 @@ void Http2Session::Send(uv_buf_t* buf, size_t length) {
674
719
if (stream_ == nullptr || !stream_->IsAlive () || stream_->IsClosing ()) {
675
720
return ;
676
721
}
677
-
678
722
HandleScope scope (env ()->isolate ());
679
723
SessionSendBuffer* req = ContainerOf (&SessionSendBuffer::buffer_, buf);
680
724
uv_buf_t actual = uv_buf_init (buf->base , length);
@@ -685,6 +729,8 @@ void Http2Session::Send(uv_buf_t* buf, size_t length) {
685
729
686
730
void Http2Session::OnTrailers (Nghttp2Stream* stream,
687
731
MaybeStackBuffer<nghttp2_nv>* trailers) {
732
+ DEBUG_HTTP2 (" Http2Session: prompting for trailers on stream %d\n " ,
733
+ stream->id ());
688
734
Local<Context> context = env ()->context ();
689
735
Context::Scope context_scope (context);
690
736
Isolate* isolate = env ()->isolate ();
@@ -1020,6 +1066,7 @@ void Http2Session::OnStreamReadImpl(ssize_t nread,
1020
1066
1021
1067
1022
1068
void Http2Session::Consume (Local<External> external) {
1069
+ DEBUG_HTTP2 (" Http2Session: consuming socket\n " );
1023
1070
CHECK (prev_alloc_cb_.is_empty ());
1024
1071
StreamBase* stream = static_cast <StreamBase*>(external->Value ());
1025
1072
CHECK_NE (stream, nullptr );
@@ -1033,6 +1080,7 @@ void Http2Session::Consume(Local<External> external) {
1033
1080
1034
1081
1035
1082
void Http2Session::Unconsume () {
1083
+ DEBUG_HTTP2 (" Http2Session: unconsuming socket\n " );
1036
1084
if (prev_alloc_cb_.is_empty ())
1037
1085
return ;
1038
1086
stream_->set_alloc_cb (prev_alloc_cb_);
0 commit comments