@@ -148,14 +148,16 @@ static int check_ext_type_set(const uint8_t *ext_types, uint8_t type) {
148
148
}
149
149
150
150
static int session_call_error_callback (nghttp2_session * session ,
151
- const char * fmt , ...) {
151
+ int lib_error_code , const char * fmt ,
152
+ ...) {
152
153
size_t bufsize ;
153
154
va_list ap ;
154
155
char * buf ;
155
156
int rv ;
156
157
nghttp2_mem * mem ;
157
158
158
- if (!session -> callbacks .error_callback ) {
159
+ if (!session -> callbacks .error_callback &&
160
+ !session -> callbacks .error_callback2 ) {
159
161
return 0 ;
160
162
}
161
163
@@ -189,8 +191,13 @@ static int session_call_error_callback(nghttp2_session *session,
189
191
return 0 ;
190
192
}
191
193
192
- rv = session -> callbacks .error_callback (session , buf , (size_t )rv ,
193
- session -> user_data );
194
+ if (session -> callbacks .error_callback2 ) {
195
+ rv = session -> callbacks .error_callback2 (session , lib_error_code , buf ,
196
+ (size_t )rv , session -> user_data );
197
+ } else {
198
+ rv = session -> callbacks .error_callback (session , buf , (size_t )rv ,
199
+ session -> user_data );
200
+ }
194
201
195
202
nghttp2_mem_free (mem , buf );
196
203
@@ -541,9 +548,8 @@ static int session_new(nghttp2_session **session_ptr,
541
548
if (nghttp2_enable_strict_preface ) {
542
549
nghttp2_inbound_frame * iframe = & (* session_ptr )-> iframe ;
543
550
544
- if (server &&
545
- ((* session_ptr )-> opt_flags & NGHTTP2_OPTMASK_NO_RECV_CLIENT_MAGIC ) ==
546
- 0 ) {
551
+ if (server && ((* session_ptr )-> opt_flags &
552
+ NGHTTP2_OPTMASK_NO_RECV_CLIENT_MAGIC ) == 0 ) {
547
553
iframe -> state = NGHTTP2_IB_READ_CLIENT_MAGIC ;
548
554
iframe -> payloadleft = NGHTTP2_CLIENT_MAGIC_LEN ;
549
555
} else {
@@ -2183,7 +2189,7 @@ static int session_prep_frame(nghttp2_session *session,
2183
2189
closed. */
2184
2190
stream = nghttp2_session_get_stream (session , frame -> hd .stream_id );
2185
2191
2186
- /* predicte should fail if stream is NULL. */
2192
+ /* predicate should fail if stream is NULL. */
2187
2193
rv = session_predicate_push_promise_send (session , stream );
2188
2194
if (rv != 0 ) {
2189
2195
return rv ;
@@ -2411,19 +2417,16 @@ static int session_close_stream_on_goaway(nghttp2_session *session,
2411
2417
nghttp2_stream * stream , * next_stream ;
2412
2418
nghttp2_close_stream_on_goaway_arg arg = {session , NULL , last_stream_id ,
2413
2419
incoming };
2414
- uint32_t error_code ;
2415
2420
2416
2421
rv = nghttp2_map_each (& session -> streams , find_stream_on_goaway_func , & arg );
2417
2422
assert (rv == 0 );
2418
2423
2419
- error_code =
2420
- session -> server && incoming ? NGHTTP2_REFUSED_STREAM : NGHTTP2_CANCEL ;
2421
-
2422
2424
stream = arg .head ;
2423
2425
while (stream ) {
2424
2426
next_stream = stream -> closed_next ;
2425
2427
stream -> closed_next = NULL ;
2426
- rv = nghttp2_session_close_stream (session , stream -> stream_id , error_code );
2428
+ rv = nghttp2_session_close_stream (session , stream -> stream_id ,
2429
+ NGHTTP2_REFUSED_STREAM );
2427
2430
2428
2431
/* stream may be deleted here */
2429
2432
@@ -3608,7 +3611,7 @@ static int inflate_header_block(nghttp2_session *session, nghttp2_frame *frame,
3608
3611
nv .name -> base , (int )nv .value -> len , nv .value -> base );
3609
3612
3610
3613
rv2 = session_call_error_callback (
3611
- session ,
3614
+ session , NGHTTP2_ERR_HTTP_HEADER ,
3612
3615
"Ignoring received invalid HTTP header field: frame type: "
3613
3616
"%u, stream: %d, name: [%.*s], value: [%.*s]" ,
3614
3617
frame -> hd .type , frame -> hd .stream_id , (int )nv .name -> len ,
@@ -3626,8 +3629,9 @@ static int inflate_header_block(nghttp2_session *session, nghttp2_frame *frame,
3626
3629
nv .name -> base , (int )nv .value -> len , nv .value -> base );
3627
3630
3628
3631
rv = session_call_error_callback (
3629
- session , "Invalid HTTP header field was received: frame type: "
3630
- "%u, stream: %d, name: [%.*s], value: [%.*s]" ,
3632
+ session , NGHTTP2_ERR_HTTP_HEADER ,
3633
+ "Invalid HTTP header field was received: frame type: "
3634
+ "%u, stream: %d, name: [%.*s], value: [%.*s]" ,
3631
3635
frame -> hd .type , frame -> hd .stream_id , (int )nv .name -> len ,
3632
3636
nv .name -> base , (int )nv .value -> len , nv .value -> base );
3633
3637
@@ -3781,7 +3785,7 @@ int nghttp2_session_on_request_headers_received(nghttp2_session *session,
3781
3785
session , frame , NGHTTP2_ERR_PROTO , "request HEADERS: stream_id == 0" );
3782
3786
}
3783
3787
3784
- /* If client recieves idle stream from server, it is invalid
3788
+ /* If client receives idle stream from server, it is invalid
3785
3789
regardless stream ID is even or odd. This is because client is
3786
3790
not expected to receive request from server. */
3787
3791
if (!session -> server ) {
@@ -5345,9 +5349,10 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in,
5345
5349
iframe -> state = NGHTTP2_IB_IGN_ALL ;
5346
5350
5347
5351
rv = session_call_error_callback (
5348
- session , "Remote peer returned unexpected data while we expected "
5349
- "SETTINGS frame. Perhaps, peer does not support HTTP/2 "
5350
- "properly." );
5352
+ session , NGHTTP2_ERR_SETTINGS_EXPECTED ,
5353
+ "Remote peer returned unexpected data while we expected "
5354
+ "SETTINGS frame. Perhaps, peer does not support HTTP/2 "
5355
+ "properly." );
5351
5356
5352
5357
if (nghttp2_is_fatal (rv )) {
5353
5358
return rv ;
@@ -5588,13 +5593,13 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in,
5588
5593
if (iframe -> payloadleft ) {
5589
5594
nghttp2_settings_entry * min_header_table_size_entry ;
5590
5595
5591
- /* We allocate iv with addtional one entry, to store the
5596
+ /* We allocate iv with additional one entry, to store the
5592
5597
minimum header table size. */
5593
5598
iframe -> max_niv =
5594
5599
iframe -> frame .hd .length / NGHTTP2_FRAME_SETTINGS_ENTRY_LENGTH + 1 ;
5595
5600
5596
- iframe -> iv = nghttp2_mem_malloc (
5597
- mem , sizeof ( nghttp2_settings_entry ) * iframe -> max_niv );
5601
+ iframe -> iv = nghttp2_mem_malloc (mem , sizeof ( nghttp2_settings_entry ) *
5602
+ iframe -> max_niv );
5598
5603
5599
5604
if (!iframe -> iv ) {
5600
5605
return NGHTTP2_ERR_NOMEM ;
0 commit comments