Lines Matching refs:h2c

62 static void ngx_http_v2_handle_connection(ngx_http_v2_connection_t *h2c);
66 static u_char *ngx_http_v2_state_proxy_protocol(ngx_http_v2_connection_t *h2c,
68 static u_char *ngx_http_v2_state_preface(ngx_http_v2_connection_t *h2c,
70 static u_char *ngx_http_v2_state_preface_end(ngx_http_v2_connection_t *h2c,
72 static u_char *ngx_http_v2_state_head(ngx_http_v2_connection_t *h2c,
74 static u_char *ngx_http_v2_state_data(ngx_http_v2_connection_t *h2c,
76 static u_char *ngx_http_v2_state_read_data(ngx_http_v2_connection_t *h2c,
78 static u_char *ngx_http_v2_state_headers(ngx_http_v2_connection_t *h2c,
80 static u_char *ngx_http_v2_state_header_block(ngx_http_v2_connection_t *h2c,
82 static u_char *ngx_http_v2_state_field_len(ngx_http_v2_connection_t *h2c,
84 static u_char *ngx_http_v2_state_field_huff(ngx_http_v2_connection_t *h2c,
86 static u_char *ngx_http_v2_state_field_raw(ngx_http_v2_connection_t *h2c,
88 static u_char *ngx_http_v2_state_field_skip(ngx_http_v2_connection_t *h2c,
90 static u_char *ngx_http_v2_state_process_header(ngx_http_v2_connection_t *h2c,
92 static u_char *ngx_http_v2_state_header_complete(ngx_http_v2_connection_t *h2c,
94 static u_char *ngx_http_v2_handle_continuation(ngx_http_v2_connection_t *h2c,
96 static u_char *ngx_http_v2_state_priority(ngx_http_v2_connection_t *h2c,
98 static u_char *ngx_http_v2_state_rst_stream(ngx_http_v2_connection_t *h2c,
100 static u_char *ngx_http_v2_state_settings(ngx_http_v2_connection_t *h2c,
102 static u_char *ngx_http_v2_state_settings_params(ngx_http_v2_connection_t *h2c,
104 static u_char *ngx_http_v2_state_push_promise(ngx_http_v2_connection_t *h2c,
106 static u_char *ngx_http_v2_state_ping(ngx_http_v2_connection_t *h2c,
108 static u_char *ngx_http_v2_state_goaway(ngx_http_v2_connection_t *h2c,
110 static u_char *ngx_http_v2_state_window_update(ngx_http_v2_connection_t *h2c,
112 static u_char *ngx_http_v2_state_continuation(ngx_http_v2_connection_t *h2c,
114 static u_char *ngx_http_v2_state_complete(ngx_http_v2_connection_t *h2c,
116 static u_char *ngx_http_v2_state_skip_padded(ngx_http_v2_connection_t *h2c,
118 static u_char *ngx_http_v2_state_skip(ngx_http_v2_connection_t *h2c,
120 static u_char *ngx_http_v2_state_save(ngx_http_v2_connection_t *h2c,
122 static u_char *ngx_http_v2_state_headers_save(ngx_http_v2_connection_t *h2c,
124 static u_char *ngx_http_v2_connection_error(ngx_http_v2_connection_t *h2c,
127 static ngx_int_t ngx_http_v2_parse_int(ngx_http_v2_connection_t *h2c,
131 ngx_http_v2_connection_t *h2c, ngx_uint_t push);
133 ngx_http_v2_connection_t *h2c, ngx_uint_t sid, ngx_uint_t alloc);
135 ngx_http_v2_connection_t *h2c);
139 static ngx_int_t ngx_http_v2_send_settings(ngx_http_v2_connection_t *h2c);
141 ngx_http_v2_connection_t *h2c, ngx_http_v2_out_frame_t *frame);
142 static ngx_int_t ngx_http_v2_send_window_update(ngx_http_v2_connection_t *h2c,
144 static ngx_int_t ngx_http_v2_send_rst_stream(ngx_http_v2_connection_t *h2c,
146 static ngx_int_t ngx_http_v2_send_goaway(ngx_http_v2_connection_t *h2c,
150 ngx_http_v2_connection_t *h2c, size_t length, ngx_uint_t type,
152 static ngx_int_t ngx_http_v2_frame_handler(ngx_http_v2_connection_t *h2c,
180 static ngx_int_t ngx_http_v2_terminate_stream(ngx_http_v2_connection_t *h2c,
186 static void ngx_http_v2_finalize_connection(ngx_http_v2_connection_t *h2c,
189 static ngx_int_t ngx_http_v2_adjust_windows(ngx_http_v2_connection_t *h2c,
191 static void ngx_http_v2_set_dependency(ngx_http_v2_connection_t *h2c,
240 ngx_http_v2_connection_t *h2c; in ngx_http_v2_init() local
261 h2c = ngx_pcalloc(c->pool, sizeof(ngx_http_v2_connection_t)); in ngx_http_v2_init()
262 if (h2c == NULL) { in ngx_http_v2_init()
267 h2c->connection = c; in ngx_http_v2_init()
268 h2c->http_connection = hc; in ngx_http_v2_init()
270 h2c->send_window = NGX_HTTP_V2_DEFAULT_WINDOW; in ngx_http_v2_init()
271 h2c->recv_window = NGX_HTTP_V2_MAX_WINDOW; in ngx_http_v2_init()
273 h2c->init_window = NGX_HTTP_V2_DEFAULT_WINDOW; in ngx_http_v2_init()
275 h2c->frame_size = NGX_HTTP_V2_DEFAULT_FRAME_SIZE; in ngx_http_v2_init()
279 h2c->concurrent_pushes = h2scf->concurrent_pushes; in ngx_http_v2_init()
280 h2c->priority_limit = ngx_max(h2scf->concurrent_streams, 100); in ngx_http_v2_init()
282 h2c->pool = ngx_create_pool(h2scf->pool_size, h2c->connection->log); in ngx_http_v2_init()
283 if (h2c->pool == NULL) { in ngx_http_v2_init()
295 cln->data = h2c; in ngx_http_v2_init()
297 h2c->streams_index = ngx_pcalloc(c->pool, ngx_http_v2_index_size(h2scf) in ngx_http_v2_init()
299 if (h2c->streams_index == NULL) { in ngx_http_v2_init()
304 if (ngx_http_v2_send_settings(h2c) == NGX_ERROR) { in ngx_http_v2_init()
309 if (ngx_http_v2_send_window_update(h2c, 0, NGX_HTTP_V2_MAX_WINDOW in ngx_http_v2_init()
317 h2c->state.handler = hc->proxy_protocol ? ngx_http_v2_state_proxy_protocol in ngx_http_v2_init()
320 ngx_queue_init(&h2c->waiting); in ngx_http_v2_init()
321 ngx_queue_init(&h2c->dependencies); in ngx_http_v2_init()
322 ngx_queue_init(&h2c->closed); in ngx_http_v2_init()
324 c->data = h2c; in ngx_http_v2_init()
350 ngx_http_v2_connection_t *h2c; in ngx_http_v2_read_handler() local
353 h2c = c->data; in ngx_http_v2_read_handler()
357 ngx_http_v2_finalize_connection(h2c, NGX_HTTP_V2_PROTOCOL_ERROR); in ngx_http_v2_read_handler()
363 h2c->blocked = 1; in ngx_http_v2_read_handler()
369 ngx_http_v2_finalize_connection(h2c, 0); in ngx_http_v2_read_handler()
373 if (!h2c->processing && !h2c->pushing) { in ngx_http_v2_read_handler()
374 ngx_http_v2_finalize_connection(h2c, NGX_HTTP_V2_NO_ERROR); in ngx_http_v2_read_handler()
378 if (!h2c->goaway) { in ngx_http_v2_read_handler()
379 h2c->goaway = 1; in ngx_http_v2_read_handler()
381 if (ngx_http_v2_send_goaway(h2c, NGX_HTTP_V2_NO_ERROR) in ngx_http_v2_read_handler()
384 ngx_http_v2_finalize_connection(h2c, 0); in ngx_http_v2_read_handler()
388 if (ngx_http_v2_send_output_queue(h2c) == NGX_ERROR) { in ngx_http_v2_read_handler()
389 ngx_http_v2_finalize_connection(h2c, 0); in ngx_http_v2_read_handler()
394 h2c->blocked = 0; in ngx_http_v2_read_handler()
399 h2mcf = ngx_http_get_module_main_conf(h2c->http_connection->conf_ctx, in ngx_http_v2_read_handler()
407 ngx_memcpy(p, h2c->state.buffer, NGX_HTTP_V2_STATE_BUFFER_SIZE); in ngx_http_v2_read_handler()
408 end = p + h2c->state.buffer_used; in ngx_http_v2_read_handler()
417 && (h2c->state.incomplete || h2c->processing || h2c->pushing)) in ngx_http_v2_read_handler()
425 ngx_http_v2_finalize_connection(h2c, 0); in ngx_http_v2_read_handler()
431 h2c->state.buffer_used = 0; in ngx_http_v2_read_handler()
432 h2c->state.incomplete = 0; in ngx_http_v2_read_handler()
435 p = h2c->state.handler(h2c, p, end); in ngx_http_v2_read_handler()
443 h2c->total_bytes += n; in ngx_http_v2_read_handler()
445 if (h2c->total_bytes / 8 > h2c->payload_bytes + 1048576) { in ngx_http_v2_read_handler()
447 ngx_http_v2_finalize_connection(h2c, NGX_HTTP_V2_NO_ERROR); in ngx_http_v2_read_handler()
454 ngx_http_v2_finalize_connection(h2c, NGX_HTTP_V2_INTERNAL_ERROR); in ngx_http_v2_read_handler()
458 if (h2c->last_out && ngx_http_v2_send_output_queue(h2c) == NGX_ERROR) { in ngx_http_v2_read_handler()
459 ngx_http_v2_finalize_connection(h2c, 0); in ngx_http_v2_read_handler()
463 h2c->blocked = 0; in ngx_http_v2_read_handler()
465 ngx_http_v2_handle_connection(h2c); in ngx_http_v2_read_handler()
474 ngx_http_v2_connection_t *h2c; in ngx_http_v2_write_handler() local
477 h2c = c->data; in ngx_http_v2_write_handler()
484 ngx_http_v2_finalize_connection(h2c, 0); in ngx_http_v2_write_handler()
490 if (h2c->last_out == NULL && !c->buffered) { in ngx_http_v2_write_handler()
496 ngx_http_v2_handle_connection(h2c); in ngx_http_v2_write_handler()
500 h2c->blocked = 1; in ngx_http_v2_write_handler()
502 rc = ngx_http_v2_send_output_queue(h2c); in ngx_http_v2_write_handler()
505 ngx_http_v2_finalize_connection(h2c, 0); in ngx_http_v2_write_handler()
509 h2c->blocked = 0; in ngx_http_v2_write_handler()
515 ngx_http_v2_handle_connection(h2c); in ngx_http_v2_write_handler()
520 ngx_http_v2_send_output_queue(ngx_http_v2_connection_t *h2c) in ngx_http_v2_send_output_queue() argument
529 c = h2c->connection; in ngx_http_v2_send_output_queue()
543 for (frame = h2c->last_out; frame; frame = fn) { in ngx_http_v2_send_output_queue()
563 clcf = ngx_http_get_module_loc_conf(h2c->http_connection->conf_ctx, in ngx_http_v2_send_output_queue()
590 if (out->handler(h2c, out) != NGX_OK) { in ngx_http_v2_send_output_queue()
609 h2c->last_out = frame; in ngx_http_v2_send_output_queue()
626 if (!h2c->blocked) { in ngx_http_v2_send_output_queue()
635 ngx_http_v2_handle_connection(ngx_http_v2_connection_t *h2c) in ngx_http_v2_handle_connection() argument
641 if (h2c->last_out || h2c->processing || h2c->pushing) { in ngx_http_v2_handle_connection()
645 c = h2c->connection; in ngx_http_v2_handle_connection()
653 h2c->blocked = 1; in ngx_http_v2_handle_connection()
655 rc = ngx_http_v2_send_output_queue(h2c); in ngx_http_v2_handle_connection()
657 h2c->blocked = 0; in ngx_http_v2_handle_connection()
671 if (h2c->goaway) { in ngx_http_v2_handle_connection()
676 clcf = ngx_http_get_module_loc_conf(h2c->http_connection->conf_ctx, in ngx_http_v2_handle_connection()
685 if (h2c->state.incomplete) { in ngx_http_v2_handle_connection()
689 ngx_destroy_pool(h2c->pool); in ngx_http_v2_handle_connection()
691 h2c->pool = NULL; in ngx_http_v2_handle_connection()
692 h2c->free_frames = NULL; in ngx_http_v2_handle_connection()
693 h2c->frames = 0; in ngx_http_v2_handle_connection()
694 h2c->free_fake_connections = NULL; in ngx_http_v2_handle_connection()
717 ngx_http_v2_connection_t *h2c; in ngx_http_v2_lingering_close() local
720 h2c = c->data; in ngx_http_v2_lingering_close()
722 clcf = ngx_http_get_module_loc_conf(h2c->http_connection->conf_ctx, in ngx_http_v2_lingering_close()
730 if (h2c->lingering_time == 0) { in ngx_http_v2_lingering_close()
731 h2c->lingering_time = ngx_time() in ngx_http_v2_lingering_close()
796 ngx_http_v2_connection_t *h2c; in ngx_http_v2_lingering_close_handler() local
800 h2c = c->data; in ngx_http_v2_lingering_close_handler()
810 timer = (ngx_msec_t) h2c->lingering_time - (ngx_msec_t) ngx_time(); in ngx_http_v2_lingering_close_handler()
837 clcf = ngx_http_get_module_loc_conf(h2c->http_connection->conf_ctx, in ngx_http_v2_lingering_close_handler()
850 ngx_http_v2_state_proxy_protocol(ngx_http_v2_connection_t *h2c, u_char *pos, in ngx_http_v2_state_proxy_protocol() argument
855 log = h2c->connection->log; in ngx_http_v2_state_proxy_protocol()
858 pos = ngx_proxy_protocol_read(h2c->connection, pos, end); in ngx_http_v2_state_proxy_protocol()
863 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR); in ngx_http_v2_state_proxy_protocol()
866 return ngx_http_v2_state_preface(h2c, pos, end); in ngx_http_v2_state_proxy_protocol()
871 ngx_http_v2_state_preface(ngx_http_v2_connection_t *h2c, u_char *pos, in ngx_http_v2_state_preface() argument
877 return ngx_http_v2_state_save(h2c, pos, end, ngx_http_v2_state_preface); in ngx_http_v2_state_preface()
881 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_preface()
884 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR); in ngx_http_v2_state_preface()
887 return ngx_http_v2_state_preface_end(h2c, pos + sizeof(preface) - 1, end); in ngx_http_v2_state_preface()
892 ngx_http_v2_state_preface_end(ngx_http_v2_connection_t *h2c, u_char *pos, in ngx_http_v2_state_preface_end() argument
898 return ngx_http_v2_state_save(h2c, pos, end, in ngx_http_v2_state_preface_end()
903 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_preface_end()
906 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR); in ngx_http_v2_state_preface_end()
909 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, in ngx_http_v2_state_preface_end()
912 return ngx_http_v2_state_head(h2c, pos + sizeof(preface) - 1, end); in ngx_http_v2_state_preface_end()
917 ngx_http_v2_state_head(ngx_http_v2_connection_t *h2c, u_char *pos, u_char *end) in ngx_http_v2_state_head() argument
923 return ngx_http_v2_state_save(h2c, pos, end, ngx_http_v2_state_head); in ngx_http_v2_state_head()
928 h2c->state.length = ngx_http_v2_parse_length(head); in ngx_http_v2_state_head()
929 h2c->state.flags = pos[4]; in ngx_http_v2_state_head()
931 h2c->state.sid = ngx_http_v2_parse_sid(&pos[5]); in ngx_http_v2_state_head()
937 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, in ngx_http_v2_state_head()
939 type, h2c->state.flags, h2c->state.length, h2c->state.sid); in ngx_http_v2_state_head()
942 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_head()
944 return ngx_http_v2_state_skip(h2c, pos, end); in ngx_http_v2_state_head()
947 return ngx_http_v2_frame_states[type](h2c, pos, end); in ngx_http_v2_state_head()
952 ngx_http_v2_state_data(ngx_http_v2_connection_t *h2c, u_char *pos, u_char *end) in ngx_http_v2_state_data() argument
958 size = h2c->state.length; in ngx_http_v2_state_data()
960 if (h2c->state.flags & NGX_HTTP_V2_PADDED_FLAG) { in ngx_http_v2_state_data()
962 if (h2c->state.length == 0) { in ngx_http_v2_state_data()
963 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_data()
967 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_SIZE_ERROR); in ngx_http_v2_state_data()
971 return ngx_http_v2_state_save(h2c, pos, end, in ngx_http_v2_state_data()
975 h2c->state.padding = *pos++; in ngx_http_v2_state_data()
977 if (h2c->state.padding >= size) { in ngx_http_v2_state_data()
978 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_data()
981 size, h2c->state.padding); in ngx_http_v2_state_data()
983 return ngx_http_v2_connection_error(h2c, in ngx_http_v2_state_data()
987 h2c->state.length -= 1 + h2c->state.padding; in ngx_http_v2_state_data()
990 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, in ngx_http_v2_state_data()
993 if (h2c->state.sid == 0) { in ngx_http_v2_state_data()
994 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_data()
997 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR); in ngx_http_v2_state_data()
1000 if (size > h2c->recv_window) { in ngx_http_v2_state_data()
1001 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_data()
1004 size, h2c->recv_window); in ngx_http_v2_state_data()
1006 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_FLOW_CTRL_ERROR); in ngx_http_v2_state_data()
1009 h2c->recv_window -= size; in ngx_http_v2_state_data()
1011 if (h2c->recv_window < NGX_HTTP_V2_MAX_WINDOW / 4) { in ngx_http_v2_state_data()
1013 if (ngx_http_v2_send_window_update(h2c, 0, NGX_HTTP_V2_MAX_WINDOW in ngx_http_v2_state_data()
1014 - h2c->recv_window) in ngx_http_v2_state_data()
1017 return ngx_http_v2_connection_error(h2c, in ngx_http_v2_state_data()
1021 h2c->recv_window = NGX_HTTP_V2_MAX_WINDOW; in ngx_http_v2_state_data()
1024 node = ngx_http_v2_get_node_by_id(h2c, h2c->state.sid, 0); in ngx_http_v2_state_data()
1027 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, in ngx_http_v2_state_data()
1030 return ngx_http_v2_state_skip_padded(h2c, pos, end); in ngx_http_v2_state_data()
1036 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_data()
1041 if (ngx_http_v2_terminate_stream(h2c, stream, in ngx_http_v2_state_data()
1045 return ngx_http_v2_connection_error(h2c, in ngx_http_v2_state_data()
1049 return ngx_http_v2_state_skip_padded(h2c, pos, end); in ngx_http_v2_state_data()
1057 if (ngx_http_v2_send_window_update(h2c, node->id, in ngx_http_v2_state_data()
1062 return ngx_http_v2_connection_error(h2c, in ngx_http_v2_state_data()
1070 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_data()
1074 if (ngx_http_v2_terminate_stream(h2c, stream, in ngx_http_v2_state_data()
1078 return ngx_http_v2_connection_error(h2c, in ngx_http_v2_state_data()
1082 return ngx_http_v2_state_skip_padded(h2c, pos, end); in ngx_http_v2_state_data()
1085 h2c->state.stream = stream; in ngx_http_v2_state_data()
1087 return ngx_http_v2_state_read_data(h2c, pos, end); in ngx_http_v2_state_data()
1092 ngx_http_v2_state_read_data(ngx_http_v2_connection_t *h2c, u_char *pos, in ngx_http_v2_state_read_data() argument
1103 stream = h2c->state.stream; in ngx_http_v2_state_read_data()
1106 return ngx_http_v2_state_skip_padded(h2c, pos, end); in ngx_http_v2_state_read_data()
1110 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, in ngx_http_v2_state_read_data()
1113 return ngx_http_v2_state_skip_padded(h2c, pos, end); in ngx_http_v2_state_read_data()
1120 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, in ngx_http_v2_state_read_data()
1123 return ngx_http_v2_state_skip_padded(h2c, pos, end); in ngx_http_v2_state_read_data()
1127 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, in ngx_http_v2_state_read_data()
1130 return ngx_http_v2_state_skip_padded(h2c, pos, end); in ngx_http_v2_state_read_data()
1135 if (size >= h2c->state.length) { in ngx_http_v2_state_read_data()
1136 size = h2c->state.length; in ngx_http_v2_state_read_data()
1137 stream->in_closed = h2c->state.flags & NGX_HTTP_V2_END_STREAM_FLAG; in ngx_http_v2_state_read_data()
1140 h2c->payload_bytes += size; in ngx_http_v2_state_read_data()
1160 return ngx_http_v2_connection_error(h2c, in ngx_http_v2_state_read_data()
1168 ngx_log_error(NGX_LOG_ALERT, h2c->connection->log, 0, in ngx_http_v2_state_read_data()
1170 return ngx_http_v2_connection_error(h2c, in ngx_http_v2_state_read_data()
1178 h2c->state.length -= size; in ngx_http_v2_state_read_data()
1180 if (h2c->state.length) { in ngx_http_v2_state_read_data()
1181 return ngx_http_v2_state_save(h2c, pos, end, in ngx_http_v2_state_read_data()
1185 if (h2c->state.padding) { in ngx_http_v2_state_read_data()
1186 return ngx_http_v2_state_skip_padded(h2c, pos, end); in ngx_http_v2_state_read_data()
1189 return ngx_http_v2_state_complete(h2c, pos, end); in ngx_http_v2_state_read_data()
1194 ngx_http_v2_state_headers(ngx_http_v2_connection_t *h2c, u_char *pos, in ngx_http_v2_state_headers() argument
1207 padded = h2c->state.flags & NGX_HTTP_V2_PADDED_FLAG; in ngx_http_v2_state_headers()
1208 priority = h2c->state.flags & NGX_HTTP_V2_PRIORITY_FLAG; in ngx_http_v2_state_headers()
1220 if (h2c->state.length < size) { in ngx_http_v2_state_headers()
1221 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_headers()
1223 h2c->state.length); in ngx_http_v2_state_headers()
1225 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_SIZE_ERROR); in ngx_http_v2_state_headers()
1228 if (h2c->state.length == size) { in ngx_http_v2_state_headers()
1229 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_headers()
1232 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_SIZE_ERROR); in ngx_http_v2_state_headers()
1235 if (h2c->goaway) { in ngx_http_v2_state_headers()
1236 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, in ngx_http_v2_state_headers()
1238 return ngx_http_v2_state_skip(h2c, pos, end); in ngx_http_v2_state_headers()
1242 return ngx_http_v2_state_save(h2c, pos, end, in ngx_http_v2_state_headers()
1246 h2c->state.length -= size; in ngx_http_v2_state_headers()
1249 h2c->state.padding = *pos++; in ngx_http_v2_state_headers()
1251 if (h2c->state.padding > h2c->state.length) { in ngx_http_v2_state_headers()
1252 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_headers()
1255 h2c->state.length, h2c->state.padding); in ngx_http_v2_state_headers()
1257 return ngx_http_v2_connection_error(h2c, in ngx_http_v2_state_headers()
1261 h2c->state.length -= h2c->state.padding; in ngx_http_v2_state_headers()
1278 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, in ngx_http_v2_state_headers()
1281 h2c->state.sid, depend, excl, weight); in ngx_http_v2_state_headers()
1283 if (h2c->state.sid % 2 == 0 || h2c->state.sid <= h2c->last_sid) { in ngx_http_v2_state_headers()
1284 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_headers()
1286 "%ui, the last was %ui", h2c->state.sid, h2c->last_sid); in ngx_http_v2_state_headers()
1288 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR); in ngx_http_v2_state_headers()
1291 if (depend == h2c->state.sid) { in ngx_http_v2_state_headers()
1292 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_headers()
1294 "with incorrect dependency", h2c->state.sid); in ngx_http_v2_state_headers()
1296 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR); in ngx_http_v2_state_headers()
1299 h2c->last_sid = h2c->state.sid; in ngx_http_v2_state_headers()
1301 h2c->state.pool = ngx_create_pool(1024, h2c->connection->log); in ngx_http_v2_state_headers()
1302 if (h2c->state.pool == NULL) { in ngx_http_v2_state_headers()
1303 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_INTERNAL_ERROR); in ngx_http_v2_state_headers()
1306 cscf = ngx_http_get_module_srv_conf(h2c->http_connection->conf_ctx, in ngx_http_v2_state_headers()
1309 h2c->state.header_limit = cscf->large_client_header_buffers.size in ngx_http_v2_state_headers()
1312 h2scf = ngx_http_get_module_srv_conf(h2c->http_connection->conf_ctx, in ngx_http_v2_state_headers()
1315 if (h2c->processing >= h2scf->concurrent_streams) { in ngx_http_v2_state_headers()
1316 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_headers()
1317 "concurrent streams exceeded %ui", h2c->processing); in ngx_http_v2_state_headers()
1323 if (!h2c->settings_ack in ngx_http_v2_state_headers()
1324 && !(h2c->state.flags & NGX_HTTP_V2_END_STREAM_FLAG) in ngx_http_v2_state_headers()
1327 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_headers()
1335 node = ngx_http_v2_get_node_by_id(h2c, h2c->state.sid, 1); in ngx_http_v2_state_headers()
1338 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_INTERNAL_ERROR); in ngx_http_v2_state_headers()
1343 h2c->closed_nodes--; in ngx_http_v2_state_headers()
1346 stream = ngx_http_v2_create_stream(h2c, 0); in ngx_http_v2_state_headers()
1348 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_INTERNAL_ERROR); in ngx_http_v2_state_headers()
1351 h2c->state.stream = stream; in ngx_http_v2_state_headers()
1353 stream->pool = h2c->state.pool; in ngx_http_v2_state_headers()
1354 h2c->state.keep_pool = 1; in ngx_http_v2_state_headers()
1356 stream->request->request_length = h2c->state.length; in ngx_http_v2_state_headers()
1358 stream->in_closed = h2c->state.flags & NGX_HTTP_V2_END_STREAM_FLAG; in ngx_http_v2_state_headers()
1365 ngx_http_v2_set_dependency(h2c, node, depend, excl); in ngx_http_v2_state_headers()
1368 clcf = ngx_http_get_module_loc_conf(h2c->http_connection->conf_ctx, in ngx_http_v2_state_headers()
1372 || h2c->connection->requests >= clcf->keepalive_requests in ngx_http_v2_state_headers()
1373 || ngx_current_msec - h2c->connection->start_time in ngx_http_v2_state_headers()
1376 h2c->goaway = 1; in ngx_http_v2_state_headers()
1378 if (ngx_http_v2_send_goaway(h2c, NGX_HTTP_V2_NO_ERROR) == NGX_ERROR) { in ngx_http_v2_state_headers()
1379 return ngx_http_v2_connection_error(h2c, in ngx_http_v2_state_headers()
1384 return ngx_http_v2_state_header_block(h2c, pos, end); in ngx_http_v2_state_headers()
1388 if (ngx_http_v2_send_rst_stream(h2c, h2c->state.sid, status) != NGX_OK) { in ngx_http_v2_state_headers()
1389 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_INTERNAL_ERROR); in ngx_http_v2_state_headers()
1392 return ngx_http_v2_state_header_block(h2c, pos, end); in ngx_http_v2_state_headers()
1397 ngx_http_v2_state_header_block(ngx_http_v2_connection_t *h2c, u_char *pos, in ngx_http_v2_state_header_block() argument
1405 return ngx_http_v2_state_headers_save(h2c, pos, end, in ngx_http_v2_state_header_block()
1409 if (!(h2c->state.flags & NGX_HTTP_V2_END_HEADERS_FLAG) in ngx_http_v2_state_header_block()
1410 && h2c->state.length < NGX_HTTP_V2_INT_OCTETS) in ngx_http_v2_state_header_block()
1412 return ngx_http_v2_handle_continuation(h2c, pos, end, in ngx_http_v2_state_header_block()
1428 h2c->state.index = 1; in ngx_http_v2_state_header_block()
1445 value = ngx_http_v2_parse_int(h2c, &pos, end, prefix); in ngx_http_v2_state_header_block()
1449 return ngx_http_v2_state_headers_save(h2c, pos, end, in ngx_http_v2_state_header_block()
1454 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_header_block()
1458 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_COMP_ERROR); in ngx_http_v2_state_header_block()
1461 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_header_block()
1464 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_SIZE_ERROR); in ngx_http_v2_state_header_block()
1468 if (ngx_http_v2_get_indexed_header(h2c, value, 0) != NGX_OK) { in ngx_http_v2_state_header_block()
1469 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_COMP_ERROR); in ngx_http_v2_state_header_block()
1472 return ngx_http_v2_state_process_header(h2c, pos, end); in ngx_http_v2_state_header_block()
1476 if (ngx_http_v2_table_size(h2c, value) != NGX_OK) { in ngx_http_v2_state_header_block()
1477 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_COMP_ERROR); in ngx_http_v2_state_header_block()
1480 return ngx_http_v2_state_header_complete(h2c, pos, end); in ngx_http_v2_state_header_block()
1484 h2c->state.parse_name = 1; in ngx_http_v2_state_header_block()
1486 } else if (ngx_http_v2_get_indexed_header(h2c, value, 1) != NGX_OK) { in ngx_http_v2_state_header_block()
1487 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_COMP_ERROR); in ngx_http_v2_state_header_block()
1490 h2c->state.parse_value = 1; in ngx_http_v2_state_header_block()
1492 return ngx_http_v2_state_field_len(h2c, pos, end); in ngx_http_v2_state_header_block()
1497 ngx_http_v2_state_field_len(ngx_http_v2_connection_t *h2c, u_char *pos, in ngx_http_v2_state_field_len() argument
1505 if (!(h2c->state.flags & NGX_HTTP_V2_END_HEADERS_FLAG) in ngx_http_v2_state_field_len()
1506 && h2c->state.length < NGX_HTTP_V2_INT_OCTETS) in ngx_http_v2_state_field_len()
1508 return ngx_http_v2_handle_continuation(h2c, pos, end, in ngx_http_v2_state_field_len()
1512 if (h2c->state.length < 1) { in ngx_http_v2_state_field_len()
1513 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_field_len()
1516 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_SIZE_ERROR); in ngx_http_v2_state_field_len()
1520 return ngx_http_v2_state_headers_save(h2c, pos, end, in ngx_http_v2_state_field_len()
1525 len = ngx_http_v2_parse_int(h2c, &pos, end, ngx_http_v2_prefix(7)); in ngx_http_v2_state_field_len()
1529 return ngx_http_v2_state_headers_save(h2c, pos, end, in ngx_http_v2_state_field_len()
1534 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_field_len()
1537 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_COMP_ERROR); in ngx_http_v2_state_field_len()
1540 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_field_len()
1543 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_SIZE_ERROR); in ngx_http_v2_state_field_len()
1546 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, in ngx_http_v2_state_field_len()
1550 cscf = ngx_http_get_module_srv_conf(h2c->http_connection->conf_ctx, in ngx_http_v2_state_field_len()
1554 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_field_len()
1557 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_ENHANCE_YOUR_CALM); in ngx_http_v2_state_field_len()
1560 h2c->state.field_rest = len; in ngx_http_v2_state_field_len()
1562 if (h2c->state.stream == NULL && !h2c->state.index) { in ngx_http_v2_state_field_len()
1563 return ngx_http_v2_state_field_skip(h2c, pos, end); in ngx_http_v2_state_field_len()
1568 h2c->state.field_start = ngx_pnalloc(h2c->state.pool, alloc); in ngx_http_v2_state_field_len()
1569 if (h2c->state.field_start == NULL) { in ngx_http_v2_state_field_len()
1570 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_INTERNAL_ERROR); in ngx_http_v2_state_field_len()
1573 h2c->state.field_end = h2c->state.field_start; in ngx_http_v2_state_field_len()
1576 return ngx_http_v2_state_field_huff(h2c, pos, end); in ngx_http_v2_state_field_len()
1579 return ngx_http_v2_state_field_raw(h2c, pos, end); in ngx_http_v2_state_field_len()
1584 ngx_http_v2_state_field_huff(ngx_http_v2_connection_t *h2c, u_char *pos, in ngx_http_v2_state_field_huff() argument
1591 if (size > h2c->state.field_rest) { in ngx_http_v2_state_field_huff()
1592 size = h2c->state.field_rest; in ngx_http_v2_state_field_huff()
1595 if (size > h2c->state.length) { in ngx_http_v2_state_field_huff()
1596 size = h2c->state.length; in ngx_http_v2_state_field_huff()
1599 h2c->state.length -= size; in ngx_http_v2_state_field_huff()
1600 h2c->state.field_rest -= size; in ngx_http_v2_state_field_huff()
1602 if (ngx_http_v2_huff_decode(&h2c->state.field_state, pos, size, in ngx_http_v2_state_field_huff()
1603 &h2c->state.field_end, in ngx_http_v2_state_field_huff()
1604 h2c->state.field_rest == 0, in ngx_http_v2_state_field_huff()
1605 h2c->connection->log) in ngx_http_v2_state_field_huff()
1608 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_field_huff()
1611 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_COMP_ERROR); in ngx_http_v2_state_field_huff()
1616 if (h2c->state.field_rest == 0) { in ngx_http_v2_state_field_huff()
1617 *h2c->state.field_end = '\0'; in ngx_http_v2_state_field_huff()
1618 return ngx_http_v2_state_process_header(h2c, pos, end); in ngx_http_v2_state_field_huff()
1621 if (h2c->state.length) { in ngx_http_v2_state_field_huff()
1622 return ngx_http_v2_state_headers_save(h2c, pos, end, in ngx_http_v2_state_field_huff()
1626 if (h2c->state.flags & NGX_HTTP_V2_END_HEADERS_FLAG) { in ngx_http_v2_state_field_huff()
1627 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_field_huff()
1630 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_SIZE_ERROR); in ngx_http_v2_state_field_huff()
1633 return ngx_http_v2_handle_continuation(h2c, pos, end, in ngx_http_v2_state_field_huff()
1639 ngx_http_v2_state_field_raw(ngx_http_v2_connection_t *h2c, u_char *pos, in ngx_http_v2_state_field_raw() argument
1646 if (size > h2c->state.field_rest) { in ngx_http_v2_state_field_raw()
1647 size = h2c->state.field_rest; in ngx_http_v2_state_field_raw()
1650 if (size > h2c->state.length) { in ngx_http_v2_state_field_raw()
1651 size = h2c->state.length; in ngx_http_v2_state_field_raw()
1654 h2c->state.length -= size; in ngx_http_v2_state_field_raw()
1655 h2c->state.field_rest -= size; in ngx_http_v2_state_field_raw()
1657 h2c->state.field_end = ngx_cpymem(h2c->state.field_end, pos, size); in ngx_http_v2_state_field_raw()
1661 if (h2c->state.field_rest == 0) { in ngx_http_v2_state_field_raw()
1662 *h2c->state.field_end = '\0'; in ngx_http_v2_state_field_raw()
1663 return ngx_http_v2_state_process_header(h2c, pos, end); in ngx_http_v2_state_field_raw()
1666 if (h2c->state.length) { in ngx_http_v2_state_field_raw()
1667 return ngx_http_v2_state_headers_save(h2c, pos, end, in ngx_http_v2_state_field_raw()
1671 if (h2c->state.flags & NGX_HTTP_V2_END_HEADERS_FLAG) { in ngx_http_v2_state_field_raw()
1672 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_field_raw()
1675 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_SIZE_ERROR); in ngx_http_v2_state_field_raw()
1678 return ngx_http_v2_handle_continuation(h2c, pos, end, in ngx_http_v2_state_field_raw()
1684 ngx_http_v2_state_field_skip(ngx_http_v2_connection_t *h2c, u_char *pos, in ngx_http_v2_state_field_skip() argument
1691 if (size > h2c->state.field_rest) { in ngx_http_v2_state_field_skip()
1692 size = h2c->state.field_rest; in ngx_http_v2_state_field_skip()
1695 if (size > h2c->state.length) { in ngx_http_v2_state_field_skip()
1696 size = h2c->state.length; in ngx_http_v2_state_field_skip()
1699 h2c->state.length -= size; in ngx_http_v2_state_field_skip()
1700 h2c->state.field_rest -= size; in ngx_http_v2_state_field_skip()
1704 if (h2c->state.field_rest == 0) { in ngx_http_v2_state_field_skip()
1705 return ngx_http_v2_state_process_header(h2c, pos, end); in ngx_http_v2_state_field_skip()
1708 if (h2c->state.length) { in ngx_http_v2_state_field_skip()
1709 return ngx_http_v2_state_save(h2c, pos, end, in ngx_http_v2_state_field_skip()
1713 if (h2c->state.flags & NGX_HTTP_V2_END_HEADERS_FLAG) { in ngx_http_v2_state_field_skip()
1714 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_field_skip()
1717 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_SIZE_ERROR); in ngx_http_v2_state_field_skip()
1720 return ngx_http_v2_handle_continuation(h2c, pos, end, in ngx_http_v2_state_field_skip()
1726 ngx_http_v2_state_process_header(ngx_http_v2_connection_t *h2c, u_char *pos, in ngx_http_v2_state_process_header() argument
1740 header = &h2c->state.header; in ngx_http_v2_state_process_header()
1742 if (h2c->state.parse_name) { in ngx_http_v2_state_process_header()
1743 h2c->state.parse_name = 0; in ngx_http_v2_state_process_header()
1745 header->name.len = h2c->state.field_end - h2c->state.field_start; in ngx_http_v2_state_process_header()
1746 header->name.data = h2c->state.field_start; in ngx_http_v2_state_process_header()
1749 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_process_header()
1752 return ngx_http_v2_connection_error(h2c, in ngx_http_v2_state_process_header()
1756 return ngx_http_v2_state_field_len(h2c, pos, end); in ngx_http_v2_state_process_header()
1759 if (h2c->state.parse_value) { in ngx_http_v2_state_process_header()
1760 h2c->state.parse_value = 0; in ngx_http_v2_state_process_header()
1762 header->value.len = h2c->state.field_end - h2c->state.field_start; in ngx_http_v2_state_process_header()
1763 header->value.data = h2c->state.field_start; in ngx_http_v2_state_process_header()
1768 if (len > h2c->state.header_limit) { in ngx_http_v2_state_process_header()
1769 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_process_header()
1772 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_ENHANCE_YOUR_CALM); in ngx_http_v2_state_process_header()
1775 h2c->state.header_limit -= len; in ngx_http_v2_state_process_header()
1777 if (h2c->state.index) { in ngx_http_v2_state_process_header()
1778 if (ngx_http_v2_add_header(h2c, header) != NGX_OK) { in ngx_http_v2_state_process_header()
1779 return ngx_http_v2_connection_error(h2c, in ngx_http_v2_state_process_header()
1783 h2c->state.index = 0; in ngx_http_v2_state_process_header()
1786 if (h2c->state.stream == NULL) { in ngx_http_v2_state_process_header()
1787 return ngx_http_v2_state_header_complete(h2c, pos, end); in ngx_http_v2_state_process_header()
1790 r = h2c->state.stream->request; in ngx_http_v2_state_process_header()
1794 if (ngx_http_v2_terminate_stream(h2c, h2c->state.stream, in ngx_http_v2_state_process_header()
1798 return ngx_http_v2_connection_error(h2c, in ngx_http_v2_state_process_header()
1813 return ngx_http_v2_state_header_complete(h2c, pos, end); in ngx_http_v2_state_process_header()
1825 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_INTERNAL_ERROR); in ngx_http_v2_state_process_header()
1835 return ngx_http_v2_state_header_complete(h2c, pos, end); in ngx_http_v2_state_process_header()
1843 return ngx_http_v2_connection_error(h2c, in ngx_http_v2_state_process_header()
1850 return ngx_http_v2_connection_error(h2c, in ngx_http_v2_state_process_header()
1882 return ngx_http_v2_state_header_complete(h2c, pos, end); in ngx_http_v2_state_process_header()
1886 h2c->state.stream = NULL; in ngx_http_v2_state_process_header()
1888 return ngx_http_v2_state_header_complete(h2c, pos, end); in ngx_http_v2_state_process_header()
1893 ngx_http_v2_state_header_complete(ngx_http_v2_connection_t *h2c, u_char *pos, in ngx_http_v2_state_header_complete() argument
1898 if (h2c->state.length) { in ngx_http_v2_state_header_complete()
1900 h2c->state.handler = ngx_http_v2_state_header_block; in ngx_http_v2_state_header_complete()
1904 return ngx_http_v2_state_headers_save(h2c, pos, end, in ngx_http_v2_state_header_complete()
1908 if (!(h2c->state.flags & NGX_HTTP_V2_END_HEADERS_FLAG)) { in ngx_http_v2_state_header_complete()
1909 return ngx_http_v2_handle_continuation(h2c, pos, end, in ngx_http_v2_state_header_complete()
1913 stream = h2c->state.stream; in ngx_http_v2_state_header_complete()
1919 if (!h2c->state.keep_pool) { in ngx_http_v2_state_header_complete()
1920 ngx_destroy_pool(h2c->state.pool); in ngx_http_v2_state_header_complete()
1923 h2c->state.pool = NULL; in ngx_http_v2_state_header_complete()
1924 h2c->state.keep_pool = 0; in ngx_http_v2_state_header_complete()
1926 if (h2c->state.padding) { in ngx_http_v2_state_header_complete()
1927 return ngx_http_v2_state_skip_padded(h2c, pos, end); in ngx_http_v2_state_header_complete()
1930 return ngx_http_v2_state_complete(h2c, pos, end); in ngx_http_v2_state_header_complete()
1935 ngx_http_v2_handle_continuation(ngx_http_v2_connection_t *h2c, u_char *pos, in ngx_http_v2_handle_continuation() argument
1942 len = h2c->state.length; in ngx_http_v2_handle_continuation()
1944 if (h2c->state.padding && (size_t) (end - pos) > len) { in ngx_http_v2_handle_continuation()
1945 skip = ngx_min(h2c->state.padding, (end - pos) - len); in ngx_http_v2_handle_continuation()
1947 h2c->state.padding -= skip; in ngx_http_v2_handle_continuation()
1955 return ngx_http_v2_state_headers_save(h2c, pos, end, handler); in ngx_http_v2_handle_continuation()
1963 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_handle_continuation()
1966 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR); in ngx_http_v2_handle_continuation()
1969 h2c->state.flags |= p[4]; in ngx_http_v2_handle_continuation()
1971 if (h2c->state.sid != ngx_http_v2_parse_sid(&p[5])) { in ngx_http_v2_handle_continuation()
1972 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_handle_continuation()
1975 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR); in ngx_http_v2_handle_continuation()
1985 h2c->state.length += len; in ngx_http_v2_handle_continuation()
1987 if (h2c->state.stream) { in ngx_http_v2_handle_continuation()
1988 h2c->state.stream->request->request_length += len; in ngx_http_v2_handle_continuation()
1991 h2c->state.handler = handler; in ngx_http_v2_handle_continuation()
1997 ngx_http_v2_state_priority(ngx_http_v2_connection_t *h2c, u_char *pos, in ngx_http_v2_state_priority() argument
2003 if (h2c->state.length != NGX_HTTP_V2_PRIORITY_SIZE) { in ngx_http_v2_state_priority()
2004 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_priority()
2006 h2c->state.length); in ngx_http_v2_state_priority()
2008 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_SIZE_ERROR); in ngx_http_v2_state_priority()
2011 if (--h2c->priority_limit == 0) { in ngx_http_v2_state_priority()
2012 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_priority()
2015 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_ENHANCE_YOUR_CALM); in ngx_http_v2_state_priority()
2019 return ngx_http_v2_state_save(h2c, pos, end, in ngx_http_v2_state_priority()
2031 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, in ngx_http_v2_state_priority()
2034 h2c->state.sid, depend, excl, weight); in ngx_http_v2_state_priority()
2036 if (h2c->state.sid == 0) { in ngx_http_v2_state_priority()
2037 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_priority()
2040 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR); in ngx_http_v2_state_priority()
2043 if (depend == h2c->state.sid) { in ngx_http_v2_state_priority()
2044 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_priority()
2046 "with incorrect dependency", h2c->state.sid); in ngx_http_v2_state_priority()
2048 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR); in ngx_http_v2_state_priority()
2051 node = ngx_http_v2_get_node_by_id(h2c, h2c->state.sid, 1); in ngx_http_v2_state_priority()
2054 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_INTERNAL_ERROR); in ngx_http_v2_state_priority()
2061 h2c->closed_nodes++; in ngx_http_v2_state_priority()
2067 ngx_queue_insert_tail(&h2c->closed, &node->reuse); in ngx_http_v2_state_priority()
2070 ngx_http_v2_set_dependency(h2c, node, depend, excl); in ngx_http_v2_state_priority()
2072 return ngx_http_v2_state_complete(h2c, pos, end); in ngx_http_v2_state_priority()
2077 ngx_http_v2_state_rst_stream(ngx_http_v2_connection_t *h2c, u_char *pos, in ngx_http_v2_state_rst_stream() argument
2086 if (h2c->state.length != NGX_HTTP_V2_RST_STREAM_SIZE) { in ngx_http_v2_state_rst_stream()
2087 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_rst_stream()
2089 h2c->state.length); in ngx_http_v2_state_rst_stream()
2091 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_SIZE_ERROR); in ngx_http_v2_state_rst_stream()
2095 return ngx_http_v2_state_save(h2c, pos, end, in ngx_http_v2_state_rst_stream()
2103 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, in ngx_http_v2_state_rst_stream()
2105 h2c->state.sid, status); in ngx_http_v2_state_rst_stream()
2107 if (h2c->state.sid == 0) { in ngx_http_v2_state_rst_stream()
2108 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_rst_stream()
2111 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR); in ngx_http_v2_state_rst_stream()
2114 node = ngx_http_v2_get_node_by_id(h2c, h2c->state.sid, 0); in ngx_http_v2_state_rst_stream()
2117 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, in ngx_http_v2_state_rst_stream()
2120 return ngx_http_v2_state_complete(h2c, pos, end); in ngx_http_v2_state_rst_stream()
2135 "client canceled stream %ui", h2c->state.sid); in ngx_http_v2_state_rst_stream()
2140 "client refused stream %ui", h2c->state.sid); in ngx_http_v2_state_rst_stream()
2146 h2c->state.sid); in ngx_http_v2_state_rst_stream()
2152 h2c->state.sid, status); in ngx_http_v2_state_rst_stream()
2159 return ngx_http_v2_state_complete(h2c, pos, end); in ngx_http_v2_state_rst_stream()
2164 ngx_http_v2_state_settings(ngx_http_v2_connection_t *h2c, u_char *pos, in ngx_http_v2_state_settings() argument
2167 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, in ngx_http_v2_state_settings()
2170 if (h2c->state.sid) { in ngx_http_v2_state_settings()
2171 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_settings()
2174 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR); in ngx_http_v2_state_settings()
2177 if (h2c->state.flags == NGX_HTTP_V2_ACK_FLAG) { in ngx_http_v2_state_settings()
2179 if (h2c->state.length != 0) { in ngx_http_v2_state_settings()
2180 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_settings()
2184 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_SIZE_ERROR); in ngx_http_v2_state_settings()
2187 h2c->settings_ack = 1; in ngx_http_v2_state_settings()
2189 return ngx_http_v2_state_complete(h2c, pos, end); in ngx_http_v2_state_settings()
2192 if (h2c->state.length % NGX_HTTP_V2_SETTINGS_PARAM_SIZE) { in ngx_http_v2_state_settings()
2193 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_settings()
2195 h2c->state.length); in ngx_http_v2_state_settings()
2197 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_SIZE_ERROR); in ngx_http_v2_state_settings()
2200 return ngx_http_v2_state_settings_params(h2c, pos, end); in ngx_http_v2_state_settings()
2205 ngx_http_v2_state_settings_params(ngx_http_v2_connection_t *h2c, u_char *pos, in ngx_http_v2_state_settings_params() argument
2215 while (h2c->state.length) { in ngx_http_v2_state_settings_params()
2217 return ngx_http_v2_state_save(h2c, pos, end, in ngx_http_v2_state_settings_params()
2221 h2c->state.length -= NGX_HTTP_V2_SETTINGS_PARAM_SIZE; in ngx_http_v2_state_settings_params()
2226 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, in ngx_http_v2_state_settings_params()
2234 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_settings_params()
2238 return ngx_http_v2_connection_error(h2c, in ngx_http_v2_state_settings_params()
2242 window_delta = value - h2c->init_window; in ngx_http_v2_state_settings_params()
2250 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_settings_params()
2254 return ngx_http_v2_connection_error(h2c, in ngx_http_v2_state_settings_params()
2258 h2c->frame_size = value; in ngx_http_v2_state_settings_params()
2264 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_settings_params()
2268 return ngx_http_v2_connection_error(h2c, in ngx_http_v2_state_settings_params()
2272 h2c->push_disabled = !value; in ngx_http_v2_state_settings_params()
2276 h2scf = ngx_http_get_module_srv_conf(h2c->http_connection->conf_ctx, in ngx_http_v2_state_settings_params()
2279 h2c->concurrent_pushes = ngx_min(value, h2scf->concurrent_pushes); in ngx_http_v2_state_settings_params()
2284 h2c->table_update = 1; in ngx_http_v2_state_settings_params()
2294 frame = ngx_http_v2_get_frame(h2c, NGX_HTTP_V2_SETTINGS_ACK_SIZE, in ngx_http_v2_state_settings_params()
2298 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_INTERNAL_ERROR); in ngx_http_v2_state_settings_params()
2301 ngx_http_v2_queue_ordered_frame(h2c, frame); in ngx_http_v2_state_settings_params()
2304 h2c->init_window += window_delta; in ngx_http_v2_state_settings_params()
2306 if (ngx_http_v2_adjust_windows(h2c, window_delta) != NGX_OK) { in ngx_http_v2_state_settings_params()
2307 return ngx_http_v2_connection_error(h2c, in ngx_http_v2_state_settings_params()
2312 return ngx_http_v2_state_complete(h2c, pos, end); in ngx_http_v2_state_settings_params()
2317 ngx_http_v2_state_push_promise(ngx_http_v2_connection_t *h2c, u_char *pos, in ngx_http_v2_state_push_promise() argument
2320 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_push_promise()
2323 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR); in ngx_http_v2_state_push_promise()
2328 ngx_http_v2_state_ping(ngx_http_v2_connection_t *h2c, u_char *pos, u_char *end) in ngx_http_v2_state_ping() argument
2333 if (h2c->state.length != NGX_HTTP_V2_PING_SIZE) { in ngx_http_v2_state_ping()
2334 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_ping()
2336 h2c->state.length); in ngx_http_v2_state_ping()
2338 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_SIZE_ERROR); in ngx_http_v2_state_ping()
2342 return ngx_http_v2_state_save(h2c, pos, end, ngx_http_v2_state_ping); in ngx_http_v2_state_ping()
2345 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, in ngx_http_v2_state_ping()
2348 if (h2c->state.sid) { in ngx_http_v2_state_ping()
2349 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_ping()
2352 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR); in ngx_http_v2_state_ping()
2355 if (h2c->state.flags & NGX_HTTP_V2_ACK_FLAG) { in ngx_http_v2_state_ping()
2356 return ngx_http_v2_state_skip(h2c, pos, end); in ngx_http_v2_state_ping()
2359 frame = ngx_http_v2_get_frame(h2c, NGX_HTTP_V2_PING_SIZE, in ngx_http_v2_state_ping()
2363 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_INTERNAL_ERROR); in ngx_http_v2_state_ping()
2370 ngx_http_v2_queue_blocked_frame(h2c, frame); in ngx_http_v2_state_ping()
2372 return ngx_http_v2_state_complete(h2c, pos + NGX_HTTP_V2_PING_SIZE, end); in ngx_http_v2_state_ping()
2377 ngx_http_v2_state_goaway(ngx_http_v2_connection_t *h2c, u_char *pos, in ngx_http_v2_state_goaway() argument
2384 if (h2c->state.length < NGX_HTTP_V2_GOAWAY_SIZE) { in ngx_http_v2_state_goaway()
2385 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_goaway()
2387 "with incorrect length %uz", h2c->state.length); in ngx_http_v2_state_goaway()
2389 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_SIZE_ERROR); in ngx_http_v2_state_goaway()
2393 return ngx_http_v2_state_save(h2c, pos, end, ngx_http_v2_state_goaway); in ngx_http_v2_state_goaway()
2396 if (h2c->state.sid) { in ngx_http_v2_state_goaway()
2397 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_goaway()
2400 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR); in ngx_http_v2_state_goaway()
2404 h2c->state.length -= NGX_HTTP_V2_GOAWAY_SIZE; in ngx_http_v2_state_goaway()
2411 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, in ngx_http_v2_state_goaway()
2416 return ngx_http_v2_state_skip(h2c, pos, end); in ngx_http_v2_state_goaway()
2421 ngx_http_v2_state_window_update(ngx_http_v2_connection_t *h2c, u_char *pos, in ngx_http_v2_state_window_update() argument
2430 if (h2c->state.length != NGX_HTTP_V2_WINDOW_UPDATE_SIZE) { in ngx_http_v2_state_window_update()
2431 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_window_update()
2433 "with incorrect length %uz", h2c->state.length); in ngx_http_v2_state_window_update()
2435 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_SIZE_ERROR); in ngx_http_v2_state_window_update()
2439 return ngx_http_v2_state_save(h2c, pos, end, in ngx_http_v2_state_window_update()
2447 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, in ngx_http_v2_state_window_update()
2449 h2c->state.sid, window); in ngx_http_v2_state_window_update()
2452 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_window_update()
2456 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR); in ngx_http_v2_state_window_update()
2459 if (h2c->state.sid) { in ngx_http_v2_state_window_update()
2460 node = ngx_http_v2_get_node_by_id(h2c, h2c->state.sid, 0); in ngx_http_v2_state_window_update()
2463 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, in ngx_http_v2_state_window_update()
2466 return ngx_http_v2_state_complete(h2c, pos, end); in ngx_http_v2_state_window_update()
2473 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_window_update()
2478 h2c->state.sid, window, stream->send_window); in ngx_http_v2_state_window_update()
2480 if (ngx_http_v2_terminate_stream(h2c, stream, in ngx_http_v2_state_window_update()
2484 return ngx_http_v2_connection_error(h2c, in ngx_http_v2_state_window_update()
2488 return ngx_http_v2_state_complete(h2c, pos, end); in ngx_http_v2_state_window_update()
2506 return ngx_http_v2_state_complete(h2c, pos, end); in ngx_http_v2_state_window_update()
2509 if (window > NGX_HTTP_V2_MAX_WINDOW - h2c->send_window) { in ngx_http_v2_state_window_update()
2510 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_window_update()
2515 window, h2c->send_window); in ngx_http_v2_state_window_update()
2517 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_FLOW_CTRL_ERROR); in ngx_http_v2_state_window_update()
2520 h2c->send_window += window; in ngx_http_v2_state_window_update()
2522 while (!ngx_queue_empty(&h2c->waiting)) { in ngx_http_v2_state_window_update()
2523 q = ngx_queue_head(&h2c->waiting); in ngx_http_v2_state_window_update()
2539 if (h2c->send_window == 0) { in ngx_http_v2_state_window_update()
2545 return ngx_http_v2_state_complete(h2c, pos, end); in ngx_http_v2_state_window_update()
2550 ngx_http_v2_state_continuation(ngx_http_v2_connection_t *h2c, u_char *pos, in ngx_http_v2_state_continuation() argument
2553 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_state_continuation()
2556 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR); in ngx_http_v2_state_continuation()
2561 ngx_http_v2_state_complete(ngx_http_v2_connection_t *h2c, u_char *pos, in ngx_http_v2_state_complete() argument
2564 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, in ngx_http_v2_state_complete()
2568 ngx_log_error(NGX_LOG_ALERT, h2c->connection->log, 0, in ngx_http_v2_state_complete()
2571 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_INTERNAL_ERROR); in ngx_http_v2_state_complete()
2574 h2c->state.stream = NULL; in ngx_http_v2_state_complete()
2575 h2c->state.handler = ngx_http_v2_state_head; in ngx_http_v2_state_complete()
2582 ngx_http_v2_state_skip_padded(ngx_http_v2_connection_t *h2c, u_char *pos, in ngx_http_v2_state_skip_padded() argument
2585 h2c->state.length += h2c->state.padding; in ngx_http_v2_state_skip_padded()
2586 h2c->state.padding = 0; in ngx_http_v2_state_skip_padded()
2588 return ngx_http_v2_state_skip(h2c, pos, end); in ngx_http_v2_state_skip_padded()
2593 ngx_http_v2_state_skip(ngx_http_v2_connection_t *h2c, u_char *pos, u_char *end) in ngx_http_v2_state_skip() argument
2599 if (size < h2c->state.length) { in ngx_http_v2_state_skip()
2600 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, in ngx_http_v2_state_skip()
2601 "http2 frame skip %uz of %uz", size, h2c->state.length); in ngx_http_v2_state_skip()
2603 h2c->state.length -= size; in ngx_http_v2_state_skip()
2604 return ngx_http_v2_state_save(h2c, end, end, ngx_http_v2_state_skip); in ngx_http_v2_state_skip()
2607 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, in ngx_http_v2_state_skip()
2608 "http2 frame skip %uz", h2c->state.length); in ngx_http_v2_state_skip()
2610 return ngx_http_v2_state_complete(h2c, pos + h2c->state.length, end); in ngx_http_v2_state_skip()
2615 ngx_http_v2_state_save(ngx_http_v2_connection_t *h2c, u_char *pos, u_char *end, in ngx_http_v2_state_save() argument
2620 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, in ngx_http_v2_state_save()
2627 ngx_log_error(NGX_LOG_ALERT, h2c->connection->log, 0, in ngx_http_v2_state_save()
2630 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_INTERNAL_ERROR); in ngx_http_v2_state_save()
2633 ngx_memcpy(h2c->state.buffer, pos, NGX_HTTP_V2_STATE_BUFFER_SIZE); in ngx_http_v2_state_save()
2635 h2c->state.buffer_used = size; in ngx_http_v2_state_save()
2636 h2c->state.handler = handler; in ngx_http_v2_state_save()
2637 h2c->state.incomplete = 1; in ngx_http_v2_state_save()
2644 ngx_http_v2_state_headers_save(ngx_http_v2_connection_t *h2c, u_char *pos, in ngx_http_v2_state_headers_save() argument
2651 if (h2c->state.stream) { in ngx_http_v2_state_headers_save()
2652 r = h2c->state.stream->request; in ngx_http_v2_state_headers_save()
2661 return ngx_http_v2_state_save(h2c, pos, end, handler); in ngx_http_v2_state_headers_save()
2666 ngx_http_v2_connection_error(ngx_http_v2_connection_t *h2c, in ngx_http_v2_connection_error() argument
2669 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, in ngx_http_v2_connection_error()
2672 ngx_http_v2_finalize_connection(h2c, err); in ngx_http_v2_connection_error()
2679 ngx_http_v2_parse_int(ngx_http_v2_connection_t *h2c, u_char **pos, u_char *end, in ngx_http_v2_parse_int() argument
2691 if (h2c->state.length == 0) { in ngx_http_v2_parse_int()
2695 h2c->state.length--; in ngx_http_v2_parse_int()
2711 if ((size_t) (p - start) > h2c->state.length) { in ngx_http_v2_parse_int()
2715 h2c->state.length -= p - start; in ngx_http_v2_parse_int()
2722 if ((size_t) (end - start) >= h2c->state.length) { in ngx_http_v2_parse_int()
2747 ngx_http_v2_connection_t *h2c; in ngx_http_v2_push_stream() local
2750 h2c = parent->connection; in ngx_http_v2_push_stream()
2752 pool = ngx_create_pool(1024, h2c->connection->log); in ngx_http_v2_push_stream()
2757 node = ngx_http_v2_get_node_by_id(h2c, h2c->last_push, 1); in ngx_http_v2_push_stream()
2764 stream = ngx_http_v2_create_stream(h2c, 1); in ngx_http_v2_push_stream()
2768 h2scf = ngx_http_get_module_srv_conf(h2c->http_connection->conf_ctx, in ngx_http_v2_push_stream()
2771 index = ngx_http_v2_index(h2scf, h2c->last_push); in ngx_http_v2_push_stream()
2772 h2c->streams_index[index] = node->index; in ngx_http_v2_push_stream()
2774 ngx_queue_insert_tail(&h2c->closed, &node->reuse); in ngx_http_v2_push_stream()
2775 h2c->closed_nodes++; in ngx_http_v2_push_stream()
2784 h2c->closed_nodes--; in ngx_http_v2_push_stream()
2797 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, in ngx_http_v2_push_stream()
2800 h2c->last_push, parent->node->id); in ngx_http_v2_push_stream()
2803 ngx_http_v2_set_dependency(h2c, node, parent->node->id, 0); in ngx_http_v2_push_stream()
2880 if (ngx_http_v2_send_rst_stream(h2c, h2c->last_push, in ngx_http_v2_push_stream()
2884 h2c->connection->error = 1; in ngx_http_v2_push_stream()
2892 ngx_http_v2_send_settings(ngx_http_v2_connection_t *h2c) in ngx_http_v2_send_settings() argument
2900 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, in ngx_http_v2_send_settings()
2903 frame = ngx_palloc(h2c->pool, sizeof(ngx_http_v2_out_frame_t)); in ngx_http_v2_send_settings()
2908 cl = ngx_alloc_chain_link(h2c->pool); in ngx_http_v2_send_settings()
2915 buf = ngx_create_temp_buf(h2c->pool, NGX_HTTP_V2_FRAME_HEADER_SIZE + len); in ngx_http_v2_send_settings()
2941 h2scf = ngx_http_get_module_srv_conf(h2c->http_connection->conf_ctx, in ngx_http_v2_send_settings()
2958 ngx_http_v2_queue_blocked_frame(h2c, frame); in ngx_http_v2_send_settings()
2965 ngx_http_v2_settings_frame_handler(ngx_http_v2_connection_t *h2c, in ngx_http_v2_settings_frame_handler() argument
2976 ngx_free_chain(h2c->pool, frame->first); in ngx_http_v2_settings_frame_handler()
2983 ngx_http_v2_send_window_update(ngx_http_v2_connection_t *h2c, ngx_uint_t sid, in ngx_http_v2_send_window_update() argument
2989 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, in ngx_http_v2_send_window_update()
2993 frame = ngx_http_v2_get_frame(h2c, NGX_HTTP_V2_WINDOW_UPDATE_SIZE, in ngx_http_v2_send_window_update()
3004 ngx_http_v2_queue_blocked_frame(h2c, frame); in ngx_http_v2_send_window_update()
3011 ngx_http_v2_send_rst_stream(ngx_http_v2_connection_t *h2c, ngx_uint_t sid, in ngx_http_v2_send_rst_stream() argument
3017 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, in ngx_http_v2_send_rst_stream()
3021 frame = ngx_http_v2_get_frame(h2c, NGX_HTTP_V2_RST_STREAM_SIZE, in ngx_http_v2_send_rst_stream()
3032 ngx_http_v2_queue_blocked_frame(h2c, frame); in ngx_http_v2_send_rst_stream()
3039 ngx_http_v2_send_goaway(ngx_http_v2_connection_t *h2c, ngx_uint_t status) in ngx_http_v2_send_goaway() argument
3044 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, in ngx_http_v2_send_goaway()
3046 h2c->last_sid, status); in ngx_http_v2_send_goaway()
3048 frame = ngx_http_v2_get_frame(h2c, NGX_HTTP_V2_GOAWAY_SIZE, in ngx_http_v2_send_goaway()
3057 buf->last = ngx_http_v2_write_sid(buf->last, h2c->last_sid); in ngx_http_v2_send_goaway()
3060 ngx_http_v2_queue_blocked_frame(h2c, frame); in ngx_http_v2_send_goaway()
3067 ngx_http_v2_get_frame(ngx_http_v2_connection_t *h2c, size_t length, in ngx_http_v2_get_frame() argument
3074 frame = h2c->free_frames; in ngx_http_v2_get_frame()
3077 h2c->free_frames = frame->next; in ngx_http_v2_get_frame()
3084 } else if (h2c->frames < 10000) { in ngx_http_v2_get_frame()
3085 pool = h2c->pool ? h2c->pool : h2c->connection->pool; in ngx_http_v2_get_frame()
3109 h2c->frames++; in ngx_http_v2_get_frame()
3112 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_get_frame()
3115 h2c->connection->error = 1; in ngx_http_v2_get_frame()
3122 ngx_log_error(NGX_LOG_ALERT, h2c->connection->log, 0, in ngx_http_v2_get_frame()
3141 ngx_http_v2_frame_handler(ngx_http_v2_connection_t *h2c, in ngx_http_v2_frame_handler() argument
3152 frame->next = h2c->free_frames; in ngx_http_v2_frame_handler()
3153 h2c->free_frames = frame; in ngx_http_v2_frame_handler()
3155 h2c->total_bytes += NGX_HTTP_V2_FRAME_HEADER_SIZE + frame->length; in ngx_http_v2_frame_handler()
3162 ngx_http_v2_create_stream(ngx_http_v2_connection_t *h2c, ngx_uint_t push) in ngx_http_v2_create_stream() argument
3173 fc = h2c->free_fake_connections; in ngx_http_v2_create_stream()
3176 h2c->free_fake_connections = fc->data; in ngx_http_v2_create_stream()
3184 fc = ngx_palloc(h2c->pool, sizeof(ngx_connection_t)); in ngx_http_v2_create_stream()
3189 rev = ngx_palloc(h2c->pool, sizeof(ngx_event_t)); in ngx_http_v2_create_stream()
3194 wev = ngx_palloc(h2c->pool, sizeof(ngx_event_t)); in ngx_http_v2_create_stream()
3199 log = ngx_palloc(h2c->pool, sizeof(ngx_log_t)); in ngx_http_v2_create_stream()
3204 ctx = ngx_palloc(h2c->pool, sizeof(ngx_http_log_ctx_t)); in ngx_http_v2_create_stream()
3214 ngx_memcpy(log, h2c->connection->log, sizeof(ngx_log_t)); in ngx_http_v2_create_stream()
3236 ngx_memcpy(fc, h2c->connection, sizeof(ngx_connection_t)); in ngx_http_v2_create_stream()
3238 fc->data = h2c->http_connection; in ngx_http_v2_create_stream()
3258 h2c->connection->requests++; in ngx_http_v2_create_stream()
3288 stream->connection = h2c; in ngx_http_v2_create_stream()
3292 stream->send_window = h2c->init_window; in ngx_http_v2_create_stream()
3296 h2c->pushing++; in ngx_http_v2_create_stream()
3299 h2c->processing++; in ngx_http_v2_create_stream()
3302 h2c->priority_limit += h2scf->concurrent_streams; in ngx_http_v2_create_stream()
3304 if (h2c->connection->read->timer_set) { in ngx_http_v2_create_stream()
3305 ngx_del_timer(h2c->connection->read); in ngx_http_v2_create_stream()
3313 ngx_http_v2_get_node_by_id(ngx_http_v2_connection_t *h2c, ngx_uint_t sid, in ngx_http_v2_get_node_by_id() argument
3320 h2scf = ngx_http_get_module_srv_conf(h2c->http_connection->conf_ctx, in ngx_http_v2_get_node_by_id()
3325 for (node = h2c->streams_index[index]; node; node = node->index) { in ngx_http_v2_get_node_by_id()
3336 if (h2c->closed_nodes < 32) { in ngx_http_v2_get_node_by_id()
3337 node = ngx_pcalloc(h2c->connection->pool, sizeof(ngx_http_v2_node_t)); in ngx_http_v2_get_node_by_id()
3343 node = ngx_http_v2_get_closed_node(h2c); in ngx_http_v2_get_node_by_id()
3350 node->index = h2c->streams_index[index]; in ngx_http_v2_get_node_by_id()
3351 h2c->streams_index[index] = node; in ngx_http_v2_get_node_by_id()
3358 ngx_http_v2_get_closed_node(ngx_http_v2_connection_t *h2c) in ngx_http_v2_get_closed_node() argument
3365 h2scf = ngx_http_get_module_srv_conf(h2c->http_connection->conf_ctx, in ngx_http_v2_get_closed_node()
3368 h2c->closed_nodes--; in ngx_http_v2_get_closed_node()
3370 q = ngx_queue_head(&h2c->closed); in ngx_http_v2_get_closed_node()
3376 next = &h2c->streams_index[ngx_http_v2_index(h2scf, node->id)]; in ngx_http_v2_get_closed_node()
3420 children = &h2c->dependencies; in ngx_http_v2_get_closed_node()
3947 ngx_http_v2_connection_t *h2c; in ngx_http_v2_run_request() local
3979 h2c = r->stream->connection; in ngx_http_v2_run_request()
3981 h2c->payload_bytes += r->request_length; in ngx_http_v2_run_request()
4018 ngx_http_v2_connection_t *h2c; in ngx_http_v2_read_request_body() local
4119 h2c = stream->connection; in ngx_http_v2_read_request_body()
4121 if (!h2c->blocked) { in ngx_http_v2_read_request_body()
4122 if (ngx_http_v2_send_output_queue(h2c) == NGX_ERROR) { in ngx_http_v2_read_request_body()
4360 ngx_http_v2_connection_t *h2c; in ngx_http_v2_read_unbuffered_request_body() local
4403 h2c = stream->connection; in ngx_http_v2_read_unbuffered_request_body()
4405 if (h2c->state.stream == stream) { in ngx_http_v2_read_unbuffered_request_body()
4406 window -= h2c->state.length; in ngx_http_v2_read_unbuffered_request_body()
4420 if (ngx_http_v2_send_window_update(h2c, stream->node->id, in ngx_http_v2_read_unbuffered_request_body()
4428 if (ngx_http_v2_send_output_queue(h2c) == NGX_ERROR) { in ngx_http_v2_read_unbuffered_request_body()
4445 ngx_http_v2_terminate_stream(ngx_http_v2_connection_t *h2c, in ngx_http_v2_terminate_stream() argument
4455 if (ngx_http_v2_send_rst_stream(h2c, stream->node->id, status) in ngx_http_v2_terminate_stream()
4482 ngx_http_v2_connection_t *h2c; in ngx_http_v2_close_stream() local
4484 h2c = stream->connection; in ngx_http_v2_close_stream()
4487 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, in ngx_http_v2_close_stream()
4490 node->id, stream->queued, h2c->processing, h2c->pushing); in ngx_http_v2_close_stream()
4501 if (!stream->rst_sent && !h2c->connection->error) { in ngx_http_v2_close_stream()
4504 if (ngx_http_v2_send_rst_stream(h2c, node->id, in ngx_http_v2_close_stream()
4509 h2c->connection->error = 1; in ngx_http_v2_close_stream()
4513 if (ngx_http_v2_send_rst_stream(h2c, node->id, NGX_HTTP_V2_NO_ERROR) in ngx_http_v2_close_stream()
4516 h2c->connection->error = 1; in ngx_http_v2_close_stream()
4521 if (h2c->state.stream == stream) { in ngx_http_v2_close_stream()
4522 h2c->state.stream = NULL; in ngx_http_v2_close_stream()
4529 ngx_queue_insert_tail(&h2c->closed, &node->reuse); in ngx_http_v2_close_stream()
4530 h2c->closed_nodes++; in ngx_http_v2_close_stream()
4541 h2c->frames -= stream->frames; in ngx_http_v2_close_stream()
4545 if (pool != h2c->state.pool) { in ngx_http_v2_close_stream()
4550 h2c->state.keep_pool = 0; in ngx_http_v2_close_stream()
4573 fc->data = h2c->free_fake_connections; in ngx_http_v2_close_stream()
4574 h2c->free_fake_connections = fc; in ngx_http_v2_close_stream()
4577 h2c->pushing--; in ngx_http_v2_close_stream()
4580 h2c->processing--; in ngx_http_v2_close_stream()
4583 if (h2c->processing || h2c->pushing || h2c->blocked) { in ngx_http_v2_close_stream()
4587 ev = h2c->connection->read; in ngx_http_v2_close_stream()
4639 ngx_http_v2_connection_t *h2c; in ngx_http_v2_handle_connection_handler() local
4645 h2c = c->data; in ngx_http_v2_handle_connection_handler()
4648 ngx_http_v2_finalize_connection(h2c, 0); in ngx_http_v2_handle_connection_handler()
4659 if (h2c->last_out && ngx_http_v2_send_output_queue(h2c) == NGX_ERROR) { in ngx_http_v2_handle_connection_handler()
4660 ngx_http_v2_finalize_connection(h2c, 0); in ngx_http_v2_handle_connection_handler()
4673 ngx_http_v2_connection_t *h2c; in ngx_http_v2_idle_handler() local
4677 h2c = c->data; in ngx_http_v2_idle_handler()
4682 ngx_http_v2_finalize_connection(h2c, NGX_HTTP_V2_NO_ERROR); in ngx_http_v2_idle_handler()
4706 clcf = ngx_http_get_module_loc_conf(h2c->http_connection->conf_ctx, in ngx_http_v2_idle_handler()
4709 if (h2c->idle++ > 10 * clcf->keepalive_requests) { in ngx_http_v2_idle_handler()
4710 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, in ngx_http_v2_idle_handler()
4712 ngx_http_v2_finalize_connection(h2c, NGX_HTTP_V2_NO_ERROR); in ngx_http_v2_idle_handler()
4719 h2scf = ngx_http_get_module_srv_conf(h2c->http_connection->conf_ctx, in ngx_http_v2_idle_handler()
4722 h2c->pool = ngx_create_pool(h2scf->pool_size, h2c->connection->log); in ngx_http_v2_idle_handler()
4723 if (h2c->pool == NULL) { in ngx_http_v2_idle_handler()
4724 ngx_http_v2_finalize_connection(h2c, NGX_HTTP_V2_INTERNAL_ERROR); in ngx_http_v2_idle_handler()
4736 ngx_http_v2_finalize_connection(ngx_http_v2_connection_t *h2c, in ngx_http_v2_finalize_connection() argument
4747 c = h2c->connection; in ngx_http_v2_finalize_connection()
4749 h2c->blocked = 1; in ngx_http_v2_finalize_connection()
4751 if (!c->error && !h2c->goaway) { in ngx_http_v2_finalize_connection()
4752 h2c->goaway = 1; in ngx_http_v2_finalize_connection()
4754 if (ngx_http_v2_send_goaway(h2c, status) != NGX_ERROR) { in ngx_http_v2_finalize_connection()
4755 (void) ngx_http_v2_send_output_queue(h2c); in ngx_http_v2_finalize_connection()
4759 if (!h2c->processing && !h2c->pushing) { in ngx_http_v2_finalize_connection()
4766 h2c->last_out = NULL; in ngx_http_v2_finalize_connection()
4768 h2scf = ngx_http_get_module_srv_conf(h2c->http_connection->conf_ctx, in ngx_http_v2_finalize_connection()
4775 for (node = h2c->streams_index[i]; node; node = node->index) { in ngx_http_v2_finalize_connection()
4805 h2c->blocked = 0; in ngx_http_v2_finalize_connection()
4807 if (h2c->processing || h2c->pushing) { in ngx_http_v2_finalize_connection()
4824 ngx_http_v2_adjust_windows(ngx_http_v2_connection_t *h2c, ssize_t delta) in ngx_http_v2_adjust_windows() argument
4832 h2scf = ngx_http_get_module_srv_conf(h2c->http_connection->conf_ctx, in ngx_http_v2_adjust_windows()
4839 for (node = h2c->streams_index[i]; node; node = node->index) { in ngx_http_v2_adjust_windows()
4850 if (ngx_http_v2_terminate_stream(h2c, stream, in ngx_http_v2_adjust_windows()
4862 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, in ngx_http_v2_adjust_windows()
4886 ngx_http_v2_set_dependency(ngx_http_v2_connection_t *h2c, in ngx_http_v2_set_dependency() argument
4892 parent = depend ? ngx_http_v2_get_node_by_id(h2c, depend, 0) : NULL; in ngx_http_v2_set_dependency()
4904 children = &h2c->dependencies; in ngx_http_v2_set_dependency()
4945 ngx_queue_insert_tail(&h2c->closed, &parent->reuse); in ngx_http_v2_set_dependency()
4999 ngx_http_v2_connection_t *h2c = data; in ngx_http_v2_pool_cleanup() local
5001 if (h2c->state.pool) { in ngx_http_v2_pool_cleanup()
5002 ngx_destroy_pool(h2c->state.pool); in ngx_http_v2_pool_cleanup()
5005 if (h2c->pool) { in ngx_http_v2_pool_cleanup()
5006 ngx_destroy_pool(h2c->pool); in ngx_http_v2_pool_cleanup()