Mercurial > hg > nginx
annotate src/http/v2/ngx_http_v2_filter_module.c @ 7202:a49af443656f
HTTP/2: fixed build with -Werror=unused-but-set-variable.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Thu, 08 Feb 2018 12:11:30 +0300 |
parents | 641306096f5b |
children | 8b0553239592 |
rev | line source |
---|---|
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2 /* |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
3 * Copyright (C) Nginx, Inc. |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
4 * Copyright (C) Valentin V. Bartenev |
7201 | 5 * Copyright (C) Ruslan Ermilov |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
6 */ |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
7 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
8 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
9 #include <ngx_config.h> |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
10 #include <ngx_core.h> |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
11 #include <ngx_http.h> |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
12 #include <nginx.h> |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
13 #include <ngx_http_v2_module.h> |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
14 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
15 |
6279
c72eaf694d99
HTTP/2: improved the ngx_http_v2_integer_octets(v) macro.
Valentin Bartenev <vbart@nginx.com>
parents:
6277
diff
changeset
|
16 /* |
c72eaf694d99
HTTP/2: improved the ngx_http_v2_integer_octets(v) macro.
Valentin Bartenev <vbart@nginx.com>
parents:
6277
diff
changeset
|
17 * This returns precise number of octets for values in range 0..253 |
c72eaf694d99
HTTP/2: improved the ngx_http_v2_integer_octets(v) macro.
Valentin Bartenev <vbart@nginx.com>
parents:
6277
diff
changeset
|
18 * and estimate number for the rest, but not smaller than required. |
c72eaf694d99
HTTP/2: improved the ngx_http_v2_integer_octets(v) macro.
Valentin Bartenev <vbart@nginx.com>
parents:
6277
diff
changeset
|
19 */ |
c72eaf694d99
HTTP/2: improved the ngx_http_v2_integer_octets(v) macro.
Valentin Bartenev <vbart@nginx.com>
parents:
6277
diff
changeset
|
20 |
c72eaf694d99
HTTP/2: improved the ngx_http_v2_integer_octets(v) macro.
Valentin Bartenev <vbart@nginx.com>
parents:
6277
diff
changeset
|
21 #define ngx_http_v2_integer_octets(v) (1 + (v) / 127) |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
22 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
23 #define ngx_http_v2_literal_size(h) \ |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
24 (ngx_http_v2_integer_octets(sizeof(h) - 1) + sizeof(h) - 1) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
25 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
26 #define ngx_http_v2_indexed(i) (128 + (i)) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
27 #define ngx_http_v2_inc_indexed(i) (64 + (i)) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
28 |
6395
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
29 #define ngx_http_v2_write_name(dst, src, len, tmp) \ |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
30 ngx_http_v2_string_encode(dst, src, len, tmp, 1) |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
31 #define ngx_http_v2_write_value(dst, src, len, tmp) \ |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
32 ngx_http_v2_string_encode(dst, src, len, tmp, 0) |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
33 |
6276
0efc16d55adb
HTTP/2: introduced NGX_HTTP_V2_ENCODE_* macros.
Valentin Bartenev <vbart@nginx.com>
parents:
6275
diff
changeset
|
34 #define NGX_HTTP_V2_ENCODE_RAW 0 |
0efc16d55adb
HTTP/2: introduced NGX_HTTP_V2_ENCODE_* macros.
Valentin Bartenev <vbart@nginx.com>
parents:
6275
diff
changeset
|
35 #define NGX_HTTP_V2_ENCODE_HUFF 0x80 |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
36 |
7201 | 37 #define NGX_HTTP_V2_AUTHORITY_INDEX 1 |
38 #define NGX_HTTP_V2_METHOD_GET_INDEX 2 | |
39 #define NGX_HTTP_V2_PATH_INDEX 4 | |
40 | |
41 #define NGX_HTTP_V2_SCHEME_HTTP_INDEX 6 | |
42 #define NGX_HTTP_V2_SCHEME_HTTPS_INDEX 7 | |
43 | |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
44 #define NGX_HTTP_V2_STATUS_INDEX 8 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
45 #define NGX_HTTP_V2_STATUS_200_INDEX 8 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
46 #define NGX_HTTP_V2_STATUS_204_INDEX 9 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
47 #define NGX_HTTP_V2_STATUS_206_INDEX 10 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
48 #define NGX_HTTP_V2_STATUS_304_INDEX 11 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
49 #define NGX_HTTP_V2_STATUS_400_INDEX 12 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
50 #define NGX_HTTP_V2_STATUS_404_INDEX 13 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
51 #define NGX_HTTP_V2_STATUS_500_INDEX 14 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
52 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
53 #define NGX_HTTP_V2_CONTENT_LENGTH_INDEX 28 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
54 #define NGX_HTTP_V2_CONTENT_TYPE_INDEX 31 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
55 #define NGX_HTTP_V2_DATE_INDEX 33 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
56 #define NGX_HTTP_V2_LAST_MODIFIED_INDEX 44 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
57 #define NGX_HTTP_V2_LOCATION_INDEX 46 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
58 #define NGX_HTTP_V2_SERVER_INDEX 54 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
59 #define NGX_HTTP_V2_VARY_INDEX 59 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
60 |
7035
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
61 #define NGX_HTTP_V2_NO_TRAILERS (ngx_http_v2_out_frame_t *) -1 |
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
62 |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
63 |
7201 | 64 static ngx_int_t ngx_http_v2_push_resources(ngx_http_request_t *r); |
65 static ngx_int_t ngx_http_v2_push_resource(ngx_http_request_t *r, | |
66 ngx_str_t *path, ngx_str_t *authority); | |
67 | |
6395
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
68 static u_char *ngx_http_v2_string_encode(u_char *dst, u_char *src, size_t len, |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
69 u_char *tmp, ngx_uint_t lower); |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
70 static u_char *ngx_http_v2_write_int(u_char *pos, ngx_uint_t prefix, |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
71 ngx_uint_t value); |
6277
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
72 static ngx_http_v2_out_frame_t *ngx_http_v2_create_headers_frame( |
7035
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
73 ngx_http_request_t *r, u_char *pos, u_char *end, ngx_uint_t fin); |
7201 | 74 static ngx_http_v2_out_frame_t *ngx_http_v2_create_push_frame( |
75 ngx_http_request_t *r, u_char *pos, u_char *end); | |
7035
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
76 static ngx_http_v2_out_frame_t *ngx_http_v2_create_trailers_frame( |
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
77 ngx_http_request_t *r); |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
78 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
79 static ngx_chain_t *ngx_http_v2_send_chain(ngx_connection_t *fc, |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
80 ngx_chain_t *in, off_t limit); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
81 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
82 static ngx_chain_t *ngx_http_v2_filter_get_shadow( |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
83 ngx_http_v2_stream_t *stream, ngx_buf_t *buf, off_t offset, off_t size); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
84 static ngx_http_v2_out_frame_t *ngx_http_v2_filter_get_data_frame( |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
85 ngx_http_v2_stream_t *stream, size_t len, ngx_chain_t *first, |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
86 ngx_chain_t *last); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
87 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
88 static ngx_inline ngx_int_t ngx_http_v2_flow_control( |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
89 ngx_http_v2_connection_t *h2c, ngx_http_v2_stream_t *stream); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
90 static void ngx_http_v2_waiting_queue(ngx_http_v2_connection_t *h2c, |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
91 ngx_http_v2_stream_t *stream); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
92 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
93 static ngx_inline ngx_int_t ngx_http_v2_filter_send( |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
94 ngx_connection_t *fc, ngx_http_v2_stream_t *stream); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
95 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
96 static ngx_int_t ngx_http_v2_headers_frame_handler( |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
97 ngx_http_v2_connection_t *h2c, ngx_http_v2_out_frame_t *frame); |
7201 | 98 static ngx_int_t ngx_http_v2_push_frame_handler( |
99 ngx_http_v2_connection_t *h2c, ngx_http_v2_out_frame_t *frame); | |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
100 static ngx_int_t ngx_http_v2_data_frame_handler( |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
101 ngx_http_v2_connection_t *h2c, ngx_http_v2_out_frame_t *frame); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
102 static ngx_inline void ngx_http_v2_handle_frame( |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
103 ngx_http_v2_stream_t *stream, ngx_http_v2_out_frame_t *frame); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
104 static ngx_inline void ngx_http_v2_handle_stream( |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
105 ngx_http_v2_connection_t *h2c, ngx_http_v2_stream_t *stream); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
106 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
107 static void ngx_http_v2_filter_cleanup(void *data); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
108 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
109 static ngx_int_t ngx_http_v2_filter_init(ngx_conf_t *cf); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
110 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
111 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
112 static ngx_http_module_t ngx_http_v2_filter_module_ctx = { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
113 NULL, /* preconfiguration */ |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
114 ngx_http_v2_filter_init, /* postconfiguration */ |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
115 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
116 NULL, /* create main configuration */ |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
117 NULL, /* init main configuration */ |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
118 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
119 NULL, /* create server configuration */ |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
120 NULL, /* merge server configuration */ |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
121 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
122 NULL, /* create location configuration */ |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
123 NULL /* merge location configuration */ |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
124 }; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
125 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
126 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
127 ngx_module_t ngx_http_v2_filter_module = { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
128 NGX_MODULE_V1, |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
129 &ngx_http_v2_filter_module_ctx, /* module context */ |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
130 NULL, /* module directives */ |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
131 NGX_HTTP_MODULE, /* module type */ |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
132 NULL, /* init master */ |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
133 NULL, /* init module */ |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
134 NULL, /* init process */ |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
135 NULL, /* init thread */ |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
136 NULL, /* exit thread */ |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
137 NULL, /* exit process */ |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
138 NULL, /* exit master */ |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
139 NGX_MODULE_V1_PADDING |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
140 }; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
141 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
142 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
143 static ngx_http_output_header_filter_pt ngx_http_next_header_filter; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
144 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
145 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
146 static ngx_int_t |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
147 ngx_http_v2_header_filter(ngx_http_request_t *r) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
148 { |
6395
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
149 u_char status, *pos, *start, *p, *tmp; |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
150 size_t len, tmp_len; |
6451
155871d773cc
Backed out server_tokens changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6449
diff
changeset
|
151 ngx_str_t host, location; |
155871d773cc
Backed out server_tokens changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6449
diff
changeset
|
152 ngx_uint_t i, port; |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
153 ngx_list_part_t *part; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
154 ngx_table_elt_t *header; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
155 ngx_connection_t *fc; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
156 ngx_http_cleanup_t *cln; |
7191
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
157 ngx_http_v2_stream_t *stream; |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
158 ngx_http_v2_out_frame_t *frame; |
7100
12cadc4669a7
HTTP/2: signal 0-byte HPACK's dynamic table size.
Piotr Sikora <piotrsikora@google.com>
parents:
7035
diff
changeset
|
159 ngx_http_v2_connection_t *h2c; |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
160 ngx_http_core_loc_conf_t *clcf; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
161 ngx_http_core_srv_conf_t *cscf; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
162 u_char addr[NGX_SOCKADDR_STRLEN]; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
163 |
6395
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
164 static const u_char nginx[5] = "\x84\xaa\x63\x55\xe7"; |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
165 #if (NGX_HTTP_GZIP) |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
166 static const u_char accept_encoding[12] = |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
167 "\x8b\x84\x84\x2d\x69\x5b\x05\x44\x3c\x86\xaa\x6f"; |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
168 #endif |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
169 |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
170 static size_t nginx_ver_len = ngx_http_v2_literal_size(NGINX_VER); |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
171 static u_char nginx_ver[ngx_http_v2_literal_size(NGINX_VER)]; |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
172 |
6885
25203fc377fb
Implemented the "server_tokens build" option.
Ruslan Ermilov <ru@nginx.com>
parents:
6852
diff
changeset
|
173 static size_t nginx_ver_build_len = |
25203fc377fb
Implemented the "server_tokens build" option.
Ruslan Ermilov <ru@nginx.com>
parents:
6852
diff
changeset
|
174 ngx_http_v2_literal_size(NGINX_VER_BUILD); |
25203fc377fb
Implemented the "server_tokens build" option.
Ruslan Ermilov <ru@nginx.com>
parents:
6852
diff
changeset
|
175 static u_char nginx_ver_build[ngx_http_v2_literal_size(NGINX_VER_BUILD)]; |
25203fc377fb
Implemented the "server_tokens build" option.
Ruslan Ermilov <ru@nginx.com>
parents:
6852
diff
changeset
|
176 |
7191
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
177 stream = r->stream; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
178 |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
179 if (!stream) { |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
180 return ngx_http_next_header_filter(r); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
181 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
182 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
183 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
184 "http2 header filter"); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
185 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
186 if (r->header_sent) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
187 return NGX_OK; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
188 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
189 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
190 r->header_sent = 1; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
191 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
192 if (r != r->main) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
193 return NGX_OK; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
194 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
195 |
6637
699e409a3e0c
HTTP/2: prevented output of the HEADERS frame for canceled streams.
Valentin Bartenev <vbart@nginx.com>
parents:
6600
diff
changeset
|
196 fc = r->connection; |
699e409a3e0c
HTTP/2: prevented output of the HEADERS frame for canceled streams.
Valentin Bartenev <vbart@nginx.com>
parents:
6600
diff
changeset
|
197 |
699e409a3e0c
HTTP/2: prevented output of the HEADERS frame for canceled streams.
Valentin Bartenev <vbart@nginx.com>
parents:
6600
diff
changeset
|
198 if (fc->error) { |
699e409a3e0c
HTTP/2: prevented output of the HEADERS frame for canceled streams.
Valentin Bartenev <vbart@nginx.com>
parents:
6600
diff
changeset
|
199 return NGX_ERROR; |
699e409a3e0c
HTTP/2: prevented output of the HEADERS frame for canceled streams.
Valentin Bartenev <vbart@nginx.com>
parents:
6600
diff
changeset
|
200 } |
699e409a3e0c
HTTP/2: prevented output of the HEADERS frame for canceled streams.
Valentin Bartenev <vbart@nginx.com>
parents:
6600
diff
changeset
|
201 |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
202 if (r->method == NGX_HTTP_HEAD) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
203 r->header_only = 1; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
204 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
205 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
206 switch (r->headers_out.status) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
207 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
208 case NGX_HTTP_OK: |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
209 status = ngx_http_v2_indexed(NGX_HTTP_V2_STATUS_200_INDEX); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
210 break; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
211 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
212 case NGX_HTTP_NO_CONTENT: |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
213 r->header_only = 1; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
214 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
215 ngx_str_null(&r->headers_out.content_type); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
216 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
217 r->headers_out.content_length = NULL; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
218 r->headers_out.content_length_n = -1; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
219 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
220 r->headers_out.last_modified_time = -1; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
221 r->headers_out.last_modified = NULL; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
222 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
223 status = ngx_http_v2_indexed(NGX_HTTP_V2_STATUS_204_INDEX); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
224 break; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
225 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
226 case NGX_HTTP_PARTIAL_CONTENT: |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
227 status = ngx_http_v2_indexed(NGX_HTTP_V2_STATUS_206_INDEX); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
228 break; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
229 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
230 case NGX_HTTP_NOT_MODIFIED: |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
231 r->header_only = 1; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
232 status = ngx_http_v2_indexed(NGX_HTTP_V2_STATUS_304_INDEX); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
233 break; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
234 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
235 default: |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
236 r->headers_out.last_modified_time = -1; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
237 r->headers_out.last_modified = NULL; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
238 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
239 switch (r->headers_out.status) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
240 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
241 case NGX_HTTP_BAD_REQUEST: |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
242 status = ngx_http_v2_indexed(NGX_HTTP_V2_STATUS_400_INDEX); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
243 break; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
244 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
245 case NGX_HTTP_NOT_FOUND: |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
246 status = ngx_http_v2_indexed(NGX_HTTP_V2_STATUS_404_INDEX); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
247 break; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
248 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
249 case NGX_HTTP_INTERNAL_SERVER_ERROR: |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
250 status = ngx_http_v2_indexed(NGX_HTTP_V2_STATUS_500_INDEX); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
251 break; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
252 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
253 default: |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
254 status = 0; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
255 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
256 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
257 |
7191
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
258 h2c = stream->connection; |
7100
12cadc4669a7
HTTP/2: signal 0-byte HPACK's dynamic table size.
Piotr Sikora <piotrsikora@google.com>
parents:
7035
diff
changeset
|
259 |
7201 | 260 if (!h2c->push_disabled && !h2c->goaway |
261 && stream->node->id % 2 == 1 | |
262 && r->method != NGX_HTTP_HEAD) | |
263 { | |
264 if (ngx_http_v2_push_resources(r) != NGX_OK) { | |
265 return NGX_ERROR; | |
266 } | |
267 } | |
268 | |
7100
12cadc4669a7
HTTP/2: signal 0-byte HPACK's dynamic table size.
Piotr Sikora <piotrsikora@google.com>
parents:
7035
diff
changeset
|
269 len = h2c->table_update ? 1 : 0; |
12cadc4669a7
HTTP/2: signal 0-byte HPACK's dynamic table size.
Piotr Sikora <piotrsikora@google.com>
parents:
7035
diff
changeset
|
270 |
12cadc4669a7
HTTP/2: signal 0-byte HPACK's dynamic table size.
Piotr Sikora <piotrsikora@google.com>
parents:
7035
diff
changeset
|
271 len += status ? 1 : 1 + ngx_http_v2_literal_size("418"); |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
272 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
273 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
274 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
275 if (r->headers_out.server == NULL) { |
6885
25203fc377fb
Implemented the "server_tokens build" option.
Ruslan Ermilov <ru@nginx.com>
parents:
6852
diff
changeset
|
276 |
25203fc377fb
Implemented the "server_tokens build" option.
Ruslan Ermilov <ru@nginx.com>
parents:
6852
diff
changeset
|
277 if (clcf->server_tokens == NGX_HTTP_SERVER_TOKENS_ON) { |
25203fc377fb
Implemented the "server_tokens build" option.
Ruslan Ermilov <ru@nginx.com>
parents:
6852
diff
changeset
|
278 len += 1 + nginx_ver_len; |
25203fc377fb
Implemented the "server_tokens build" option.
Ruslan Ermilov <ru@nginx.com>
parents:
6852
diff
changeset
|
279 |
25203fc377fb
Implemented the "server_tokens build" option.
Ruslan Ermilov <ru@nginx.com>
parents:
6852
diff
changeset
|
280 } else if (clcf->server_tokens == NGX_HTTP_SERVER_TOKENS_BUILD) { |
25203fc377fb
Implemented the "server_tokens build" option.
Ruslan Ermilov <ru@nginx.com>
parents:
6852
diff
changeset
|
281 len += 1 + nginx_ver_build_len; |
25203fc377fb
Implemented the "server_tokens build" option.
Ruslan Ermilov <ru@nginx.com>
parents:
6852
diff
changeset
|
282 |
25203fc377fb
Implemented the "server_tokens build" option.
Ruslan Ermilov <ru@nginx.com>
parents:
6852
diff
changeset
|
283 } else { |
25203fc377fb
Implemented the "server_tokens build" option.
Ruslan Ermilov <ru@nginx.com>
parents:
6852
diff
changeset
|
284 len += 1 + sizeof(nginx); |
25203fc377fb
Implemented the "server_tokens build" option.
Ruslan Ermilov <ru@nginx.com>
parents:
6852
diff
changeset
|
285 } |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
286 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
287 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
288 if (r->headers_out.date == NULL) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
289 len += 1 + ngx_http_v2_literal_size("Wed, 31 Dec 1986 18:00:00 GMT"); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
290 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
291 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
292 if (r->headers_out.content_type.len) { |
6274
b2de4a56b860
HTTP/2: fixed header block size calculation.
Valentin Bartenev <vbart@nginx.com>
parents:
6251
diff
changeset
|
293 len += 1 + NGX_HTTP_V2_INT_OCTETS + r->headers_out.content_type.len; |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
294 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
295 if (r->headers_out.content_type_len == r->headers_out.content_type.len |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
296 && r->headers_out.charset.len) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
297 { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
298 len += sizeof("; charset=") - 1 + r->headers_out.charset.len; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
299 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
300 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
301 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
302 if (r->headers_out.content_length == NULL |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
303 && r->headers_out.content_length_n >= 0) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
304 { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
305 len += 1 + ngx_http_v2_integer_octets(NGX_OFF_T_LEN) + NGX_OFF_T_LEN; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
306 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
307 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
308 if (r->headers_out.last_modified == NULL |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
309 && r->headers_out.last_modified_time != -1) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
310 { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
311 len += 1 + ngx_http_v2_literal_size("Wed, 31 Dec 1986 18:00:00 GMT"); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
312 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
313 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
314 if (r->headers_out.location && r->headers_out.location->value.len) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
315 |
6852
d15172ebb400
Core: relative redirects (closes #1000).
Ruslan Ermilov <ru@nginx.com>
parents:
6833
diff
changeset
|
316 if (r->headers_out.location->value.data[0] == '/' |
d15172ebb400
Core: relative redirects (closes #1000).
Ruslan Ermilov <ru@nginx.com>
parents:
6833
diff
changeset
|
317 && clcf->absolute_redirect) |
d15172ebb400
Core: relative redirects (closes #1000).
Ruslan Ermilov <ru@nginx.com>
parents:
6833
diff
changeset
|
318 { |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
319 if (clcf->server_name_in_redirect) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
320 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
321 host = cscf->server_name; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
322 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
323 } else if (r->headers_in.server.len) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
324 host = r->headers_in.server; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
325 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
326 } else { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
327 host.len = NGX_SOCKADDR_STRLEN; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
328 host.data = addr; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
329 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
330 if (ngx_connection_local_sockaddr(fc, &host, 0) != NGX_OK) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
331 return NGX_ERROR; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
332 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
333 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
334 |
6593
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6451
diff
changeset
|
335 port = ngx_inet_get_port(fc->local_sockaddr); |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
336 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
337 location.len = sizeof("https://") - 1 + host.len |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
338 + r->headers_out.location->value.len; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
339 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
340 if (clcf->port_in_redirect) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
341 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
342 #if (NGX_HTTP_SSL) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
343 if (fc->ssl) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
344 port = (port == 443) ? 0 : port; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
345 else |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
346 #endif |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
347 port = (port == 80) ? 0 : port; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
348 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
349 } else { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
350 port = 0; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
351 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
352 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
353 if (port) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
354 location.len += sizeof(":65535") - 1; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
355 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
356 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
357 location.data = ngx_pnalloc(r->pool, location.len); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
358 if (location.data == NULL) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
359 return NGX_ERROR; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
360 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
361 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
362 p = ngx_cpymem(location.data, "http", sizeof("http") - 1); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
363 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
364 #if (NGX_HTTP_SSL) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
365 if (fc->ssl) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
366 *p++ = 's'; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
367 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
368 #endif |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
369 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
370 *p++ = ':'; *p++ = '/'; *p++ = '/'; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
371 p = ngx_cpymem(p, host.data, host.len); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
372 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
373 if (port) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
374 p = ngx_sprintf(p, ":%ui", port); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
375 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
376 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
377 p = ngx_cpymem(p, r->headers_out.location->value.data, |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
378 r->headers_out.location->value.len); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
379 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
380 /* update r->headers_out.location->value for possible logging */ |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
381 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
382 r->headers_out.location->value.len = p - location.data; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
383 r->headers_out.location->value.data = location.data; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
384 ngx_str_set(&r->headers_out.location->key, "Location"); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
385 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
386 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
387 r->headers_out.location->hash = 0; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
388 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
389 len += 1 + NGX_HTTP_V2_INT_OCTETS + r->headers_out.location->value.len; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
390 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
391 |
6395
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
392 tmp_len = len; |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
393 |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
394 #if (NGX_HTTP_GZIP) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
395 if (r->gzip_vary) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
396 if (clcf->gzip_vary) { |
6395
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
397 len += 1 + sizeof(accept_encoding); |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
398 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
399 } else { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
400 r->gzip_vary = 0; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
401 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
402 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
403 #endif |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
404 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
405 part = &r->headers_out.headers.part; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
406 header = part->elts; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
407 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
408 for (i = 0; /* void */; i++) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
409 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
410 if (i >= part->nelts) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
411 if (part->next == NULL) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
412 break; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
413 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
414 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
415 part = part->next; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
416 header = part->elts; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
417 i = 0; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
418 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
419 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
420 if (header[i].hash == 0) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
421 continue; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
422 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
423 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
424 if (header[i].key.len > NGX_HTTP_V2_MAX_FIELD) { |
6400
b4c28876d2c3
HTTP/2: use local pointer instead of r->connection.
Valentin Bartenev <vbart@nginx.com>
parents:
6395
diff
changeset
|
425 ngx_log_error(NGX_LOG_CRIT, fc->log, 0, |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
426 "too long response header name: \"%V\"", |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
427 &header[i].key); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
428 return NGX_ERROR; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
429 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
430 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
431 if (header[i].value.len > NGX_HTTP_V2_MAX_FIELD) { |
6400
b4c28876d2c3
HTTP/2: use local pointer instead of r->connection.
Valentin Bartenev <vbart@nginx.com>
parents:
6395
diff
changeset
|
432 ngx_log_error(NGX_LOG_CRIT, fc->log, 0, |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
433 "too long response header value: \"%V: %V\"", |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
434 &header[i].key, &header[i].value); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
435 return NGX_ERROR; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
436 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
437 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
438 len += 1 + NGX_HTTP_V2_INT_OCTETS + header[i].key.len |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
439 + NGX_HTTP_V2_INT_OCTETS + header[i].value.len; |
6395
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
440 |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
441 if (header[i].key.len > tmp_len) { |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
442 tmp_len = header[i].key.len; |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
443 } |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
444 |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
445 if (header[i].value.len > tmp_len) { |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
446 tmp_len = header[i].value.len; |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
447 } |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
448 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
449 |
6395
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
450 tmp = ngx_palloc(r->pool, tmp_len); |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
451 pos = ngx_pnalloc(r->pool, len); |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
452 |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
453 if (pos == NULL || tmp == NULL) { |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
454 return NGX_ERROR; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
455 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
456 |
6277
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
457 start = pos; |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
458 |
7100
12cadc4669a7
HTTP/2: signal 0-byte HPACK's dynamic table size.
Piotr Sikora <piotrsikora@google.com>
parents:
7035
diff
changeset
|
459 if (h2c->table_update) { |
12cadc4669a7
HTTP/2: signal 0-byte HPACK's dynamic table size.
Piotr Sikora <piotrsikora@google.com>
parents:
7035
diff
changeset
|
460 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, fc->log, 0, |
12cadc4669a7
HTTP/2: signal 0-byte HPACK's dynamic table size.
Piotr Sikora <piotrsikora@google.com>
parents:
7035
diff
changeset
|
461 "http2 table size update: 0"); |
12cadc4669a7
HTTP/2: signal 0-byte HPACK's dynamic table size.
Piotr Sikora <piotrsikora@google.com>
parents:
7035
diff
changeset
|
462 *pos++ = (1 << 5) | 0; |
12cadc4669a7
HTTP/2: signal 0-byte HPACK's dynamic table size.
Piotr Sikora <piotrsikora@google.com>
parents:
7035
diff
changeset
|
463 h2c->table_update = 0; |
12cadc4669a7
HTTP/2: signal 0-byte HPACK's dynamic table size.
Piotr Sikora <piotrsikora@google.com>
parents:
7035
diff
changeset
|
464 } |
12cadc4669a7
HTTP/2: signal 0-byte HPACK's dynamic table size.
Piotr Sikora <piotrsikora@google.com>
parents:
7035
diff
changeset
|
465 |
6401
6812ca9a8002
HTTP/2: added debug logging of response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6400
diff
changeset
|
466 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, fc->log, 0, |
6812ca9a8002
HTTP/2: added debug logging of response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6400
diff
changeset
|
467 "http2 output header: \":status: %03ui\"", |
6812ca9a8002
HTTP/2: added debug logging of response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6400
diff
changeset
|
468 r->headers_out.status); |
6812ca9a8002
HTTP/2: added debug logging of response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6400
diff
changeset
|
469 |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
470 if (status) { |
6277
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
471 *pos++ = status; |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
472 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
473 } else { |
6277
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
474 *pos++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_STATUS_INDEX); |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
475 *pos++ = NGX_HTTP_V2_ENCODE_RAW | 3; |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
476 pos = ngx_sprintf(pos, "%03ui", r->headers_out.status); |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
477 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
478 |
6449
e5076b96fd01
Reconsidered server_tokens with an empty value.
Ruslan Ermilov <ru@nginx.com>
parents:
6434
diff
changeset
|
479 if (r->headers_out.server == NULL) { |
6885
25203fc377fb
Implemented the "server_tokens build" option.
Ruslan Ermilov <ru@nginx.com>
parents:
6852
diff
changeset
|
480 |
25203fc377fb
Implemented the "server_tokens build" option.
Ruslan Ermilov <ru@nginx.com>
parents:
6852
diff
changeset
|
481 if (clcf->server_tokens == NGX_HTTP_SERVER_TOKENS_ON) { |
25203fc377fb
Implemented the "server_tokens build" option.
Ruslan Ermilov <ru@nginx.com>
parents:
6852
diff
changeset
|
482 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, fc->log, 0, |
25203fc377fb
Implemented the "server_tokens build" option.
Ruslan Ermilov <ru@nginx.com>
parents:
6852
diff
changeset
|
483 "http2 output header: \"server: %s\"", |
25203fc377fb
Implemented the "server_tokens build" option.
Ruslan Ermilov <ru@nginx.com>
parents:
6852
diff
changeset
|
484 NGINX_VER); |
25203fc377fb
Implemented the "server_tokens build" option.
Ruslan Ermilov <ru@nginx.com>
parents:
6852
diff
changeset
|
485 |
25203fc377fb
Implemented the "server_tokens build" option.
Ruslan Ermilov <ru@nginx.com>
parents:
6852
diff
changeset
|
486 } else if (clcf->server_tokens == NGX_HTTP_SERVER_TOKENS_BUILD) { |
25203fc377fb
Implemented the "server_tokens build" option.
Ruslan Ermilov <ru@nginx.com>
parents:
6852
diff
changeset
|
487 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, fc->log, 0, |
25203fc377fb
Implemented the "server_tokens build" option.
Ruslan Ermilov <ru@nginx.com>
parents:
6852
diff
changeset
|
488 "http2 output header: \"server: %s\"", |
25203fc377fb
Implemented the "server_tokens build" option.
Ruslan Ermilov <ru@nginx.com>
parents:
6852
diff
changeset
|
489 NGINX_VER_BUILD); |
25203fc377fb
Implemented the "server_tokens build" option.
Ruslan Ermilov <ru@nginx.com>
parents:
6852
diff
changeset
|
490 |
25203fc377fb
Implemented the "server_tokens build" option.
Ruslan Ermilov <ru@nginx.com>
parents:
6852
diff
changeset
|
491 } else { |
25203fc377fb
Implemented the "server_tokens build" option.
Ruslan Ermilov <ru@nginx.com>
parents:
6852
diff
changeset
|
492 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, fc->log, 0, |
25203fc377fb
Implemented the "server_tokens build" option.
Ruslan Ermilov <ru@nginx.com>
parents:
6852
diff
changeset
|
493 "http2 output header: \"server: nginx\""); |
25203fc377fb
Implemented the "server_tokens build" option.
Ruslan Ermilov <ru@nginx.com>
parents:
6852
diff
changeset
|
494 } |
6401
6812ca9a8002
HTTP/2: added debug logging of response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6400
diff
changeset
|
495 |
6277
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
496 *pos++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_SERVER_INDEX); |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
497 |
6885
25203fc377fb
Implemented the "server_tokens build" option.
Ruslan Ermilov <ru@nginx.com>
parents:
6852
diff
changeset
|
498 if (clcf->server_tokens == NGX_HTTP_SERVER_TOKENS_ON) { |
6395
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
499 if (nginx_ver[0] == '\0') { |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
500 p = ngx_http_v2_write_value(nginx_ver, (u_char *) NGINX_VER, |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
501 sizeof(NGINX_VER) - 1, tmp); |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
502 nginx_ver_len = p - nginx_ver; |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
503 } |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
504 |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
505 pos = ngx_cpymem(pos, nginx_ver, nginx_ver_len); |
6451
155871d773cc
Backed out server_tokens changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6449
diff
changeset
|
506 |
6885
25203fc377fb
Implemented the "server_tokens build" option.
Ruslan Ermilov <ru@nginx.com>
parents:
6852
diff
changeset
|
507 } else if (clcf->server_tokens == NGX_HTTP_SERVER_TOKENS_BUILD) { |
25203fc377fb
Implemented the "server_tokens build" option.
Ruslan Ermilov <ru@nginx.com>
parents:
6852
diff
changeset
|
508 if (nginx_ver_build[0] == '\0') { |
25203fc377fb
Implemented the "server_tokens build" option.
Ruslan Ermilov <ru@nginx.com>
parents:
6852
diff
changeset
|
509 p = ngx_http_v2_write_value(nginx_ver_build, |
25203fc377fb
Implemented the "server_tokens build" option.
Ruslan Ermilov <ru@nginx.com>
parents:
6852
diff
changeset
|
510 (u_char *) NGINX_VER_BUILD, |
25203fc377fb
Implemented the "server_tokens build" option.
Ruslan Ermilov <ru@nginx.com>
parents:
6852
diff
changeset
|
511 sizeof(NGINX_VER_BUILD) - 1, tmp); |
25203fc377fb
Implemented the "server_tokens build" option.
Ruslan Ermilov <ru@nginx.com>
parents:
6852
diff
changeset
|
512 nginx_ver_build_len = p - nginx_ver_build; |
25203fc377fb
Implemented the "server_tokens build" option.
Ruslan Ermilov <ru@nginx.com>
parents:
6852
diff
changeset
|
513 } |
25203fc377fb
Implemented the "server_tokens build" option.
Ruslan Ermilov <ru@nginx.com>
parents:
6852
diff
changeset
|
514 |
25203fc377fb
Implemented the "server_tokens build" option.
Ruslan Ermilov <ru@nginx.com>
parents:
6852
diff
changeset
|
515 pos = ngx_cpymem(pos, nginx_ver_build, nginx_ver_build_len); |
25203fc377fb
Implemented the "server_tokens build" option.
Ruslan Ermilov <ru@nginx.com>
parents:
6852
diff
changeset
|
516 |
6451
155871d773cc
Backed out server_tokens changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6449
diff
changeset
|
517 } else { |
155871d773cc
Backed out server_tokens changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6449
diff
changeset
|
518 pos = ngx_cpymem(pos, nginx, sizeof(nginx)); |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
519 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
520 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
521 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
522 if (r->headers_out.date == NULL) { |
6401
6812ca9a8002
HTTP/2: added debug logging of response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6400
diff
changeset
|
523 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, fc->log, 0, |
6812ca9a8002
HTTP/2: added debug logging of response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6400
diff
changeset
|
524 "http2 output header: \"date: %V\"", |
6812ca9a8002
HTTP/2: added debug logging of response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6400
diff
changeset
|
525 &ngx_cached_http_time); |
6812ca9a8002
HTTP/2: added debug logging of response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6400
diff
changeset
|
526 |
6277
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
527 *pos++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_DATE_INDEX); |
6395
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
528 pos = ngx_http_v2_write_value(pos, ngx_cached_http_time.data, |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
529 ngx_cached_http_time.len, tmp); |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
530 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
531 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
532 if (r->headers_out.content_type.len) { |
6277
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
533 *pos++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_CONTENT_TYPE_INDEX); |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
534 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
535 if (r->headers_out.content_type_len == r->headers_out.content_type.len |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
536 && r->headers_out.charset.len) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
537 { |
6395
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
538 len = r->headers_out.content_type.len + sizeof("; charset=") - 1 |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
539 + r->headers_out.charset.len; |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
540 |
6395
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
541 p = ngx_pnalloc(r->pool, len); |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
542 if (p == NULL) { |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
543 return NGX_ERROR; |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
544 } |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
545 |
6395
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
546 p = ngx_cpymem(p, r->headers_out.content_type.data, |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
547 r->headers_out.content_type.len); |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
548 |
6395
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
549 p = ngx_cpymem(p, "; charset=", sizeof("; charset=") - 1); |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
550 |
6395
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
551 p = ngx_cpymem(p, r->headers_out.charset.data, |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
552 r->headers_out.charset.len); |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
553 |
6395
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
554 /* updated r->headers_out.content_type is also needed for logging */ |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
555 |
6395
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
556 r->headers_out.content_type.len = len; |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
557 r->headers_out.content_type.data = p - len; |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
558 } |
6395
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
559 |
6401
6812ca9a8002
HTTP/2: added debug logging of response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6400
diff
changeset
|
560 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, fc->log, 0, |
6812ca9a8002
HTTP/2: added debug logging of response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6400
diff
changeset
|
561 "http2 output header: \"content-type: %V\"", |
6812ca9a8002
HTTP/2: added debug logging of response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6400
diff
changeset
|
562 &r->headers_out.content_type); |
6812ca9a8002
HTTP/2: added debug logging of response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6400
diff
changeset
|
563 |
6395
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
564 pos = ngx_http_v2_write_value(pos, r->headers_out.content_type.data, |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
565 r->headers_out.content_type.len, tmp); |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
566 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
567 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
568 if (r->headers_out.content_length == NULL |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
569 && r->headers_out.content_length_n >= 0) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
570 { |
6401
6812ca9a8002
HTTP/2: added debug logging of response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6400
diff
changeset
|
571 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, fc->log, 0, |
6812ca9a8002
HTTP/2: added debug logging of response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6400
diff
changeset
|
572 "http2 output header: \"content-length: %O\"", |
6812ca9a8002
HTTP/2: added debug logging of response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6400
diff
changeset
|
573 r->headers_out.content_length_n); |
6812ca9a8002
HTTP/2: added debug logging of response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6400
diff
changeset
|
574 |
6277
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
575 *pos++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_CONTENT_LENGTH_INDEX); |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
576 |
6277
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
577 p = pos; |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
578 pos = ngx_sprintf(pos + 1, "%O", r->headers_out.content_length_n); |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
579 *p = NGX_HTTP_V2_ENCODE_RAW | (u_char) (pos - p - 1); |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
580 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
581 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
582 if (r->headers_out.last_modified == NULL |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
583 && r->headers_out.last_modified_time != -1) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
584 { |
6277
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
585 *pos++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_LAST_MODIFIED_INDEX); |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
586 |
6395
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
587 ngx_http_time(pos, r->headers_out.last_modified_time); |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
588 len = sizeof("Wed, 31 Dec 1986 18:00:00 GMT") - 1; |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
589 |
6401
6812ca9a8002
HTTP/2: added debug logging of response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6400
diff
changeset
|
590 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, fc->log, 0, |
6812ca9a8002
HTTP/2: added debug logging of response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6400
diff
changeset
|
591 "http2 output header: \"last-modified: %*s\"", |
6812ca9a8002
HTTP/2: added debug logging of response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6400
diff
changeset
|
592 len, pos); |
6812ca9a8002
HTTP/2: added debug logging of response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6400
diff
changeset
|
593 |
6395
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
594 /* |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
595 * Date will always be encoded using huffman in the temporary buffer, |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
596 * so it's safe here to use src and dst pointing to the same address. |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
597 */ |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
598 pos = ngx_http_v2_write_value(pos, pos, len, tmp); |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
599 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
600 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
601 if (r->headers_out.location && r->headers_out.location->value.len) { |
6401
6812ca9a8002
HTTP/2: added debug logging of response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6400
diff
changeset
|
602 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, fc->log, 0, |
6812ca9a8002
HTTP/2: added debug logging of response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6400
diff
changeset
|
603 "http2 output header: \"location: %V\"", |
6812ca9a8002
HTTP/2: added debug logging of response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6400
diff
changeset
|
604 &r->headers_out.location->value); |
6812ca9a8002
HTTP/2: added debug logging of response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6400
diff
changeset
|
605 |
6277
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
606 *pos++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_LOCATION_INDEX); |
6395
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
607 pos = ngx_http_v2_write_value(pos, r->headers_out.location->value.data, |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
608 r->headers_out.location->value.len, tmp); |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
609 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
610 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
611 #if (NGX_HTTP_GZIP) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
612 if (r->gzip_vary) { |
6401
6812ca9a8002
HTTP/2: added debug logging of response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6400
diff
changeset
|
613 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, fc->log, 0, |
6812ca9a8002
HTTP/2: added debug logging of response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6400
diff
changeset
|
614 "http2 output header: \"vary: Accept-Encoding\""); |
6812ca9a8002
HTTP/2: added debug logging of response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6400
diff
changeset
|
615 |
6277
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
616 *pos++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_VARY_INDEX); |
6395
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
617 pos = ngx_cpymem(pos, accept_encoding, sizeof(accept_encoding)); |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
618 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
619 #endif |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
620 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
621 part = &r->headers_out.headers.part; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
622 header = part->elts; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
623 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
624 for (i = 0; /* void */; i++) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
625 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
626 if (i >= part->nelts) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
627 if (part->next == NULL) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
628 break; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
629 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
630 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
631 part = part->next; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
632 header = part->elts; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
633 i = 0; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
634 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
635 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
636 if (header[i].hash == 0) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
637 continue; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
638 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
639 |
6401
6812ca9a8002
HTTP/2: added debug logging of response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6400
diff
changeset
|
640 #if (NGX_DEBUG) |
6812ca9a8002
HTTP/2: added debug logging of response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6400
diff
changeset
|
641 if (fc->log->log_level & NGX_LOG_DEBUG_HTTP) { |
6812ca9a8002
HTTP/2: added debug logging of response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6400
diff
changeset
|
642 ngx_strlow(tmp, header[i].key.data, header[i].key.len); |
6812ca9a8002
HTTP/2: added debug logging of response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6400
diff
changeset
|
643 |
6812ca9a8002
HTTP/2: added debug logging of response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6400
diff
changeset
|
644 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, fc->log, 0, |
6812ca9a8002
HTTP/2: added debug logging of response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6400
diff
changeset
|
645 "http2 output header: \"%*s: %V\"", |
6812ca9a8002
HTTP/2: added debug logging of response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6400
diff
changeset
|
646 header[i].key.len, tmp, &header[i].value); |
6812ca9a8002
HTTP/2: added debug logging of response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6400
diff
changeset
|
647 } |
6812ca9a8002
HTTP/2: added debug logging of response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6400
diff
changeset
|
648 #endif |
6812ca9a8002
HTTP/2: added debug logging of response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6400
diff
changeset
|
649 |
6277
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
650 *pos++ = 0; |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
651 |
6395
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
652 pos = ngx_http_v2_write_name(pos, header[i].key.data, |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
653 header[i].key.len, tmp); |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
654 |
6395
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
655 pos = ngx_http_v2_write_value(pos, header[i].value.data, |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
656 header[i].value.len, tmp); |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
657 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
658 |
7035
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
659 frame = ngx_http_v2_create_headers_frame(r, start, pos, r->header_only); |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
660 if (frame == NULL) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
661 return NGX_ERROR; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
662 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
663 |
7191
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
664 ngx_http_v2_queue_blocked_frame(h2c, frame); |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
665 |
7201 | 666 stream->queued++; |
7004
b624fbf7bee2
HTTP/2: fixed segfault when memory allocation failed.
Valentin Bartenev <vbart@nginx.com>
parents:
6953
diff
changeset
|
667 |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
668 cln = ngx_http_cleanup_add(r, 0); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
669 if (cln == NULL) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
670 return NGX_ERROR; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
671 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
672 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
673 cln->handler = ngx_http_v2_filter_cleanup; |
7191
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
674 cln->data = stream; |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
675 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
676 fc->send_chain = ngx_http_v2_send_chain; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
677 fc->need_last_buf = 1; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
678 |
7191
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
679 return ngx_http_v2_filter_send(fc, stream); |
7035
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
680 } |
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
681 |
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
682 |
7201 | 683 static ngx_int_t |
684 ngx_http_v2_push_resources(ngx_http_request_t *r) | |
685 { | |
686 u_char *start, *end, *last; | |
687 ngx_int_t rc; | |
688 ngx_str_t path, authority; | |
689 ngx_uint_t i, push; | |
690 ngx_table_elt_t **h; | |
691 ngx_http_v2_loc_conf_t *h2lcf; | |
692 ngx_http_complex_value_t *pushes; | |
693 | |
7202
a49af443656f
HTTP/2: fixed build with -Werror=unused-but-set-variable.
Ruslan Ermilov <ru@nginx.com>
parents:
7201
diff
changeset
|
694 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
a49af443656f
HTTP/2: fixed build with -Werror=unused-but-set-variable.
Ruslan Ermilov <ru@nginx.com>
parents:
7201
diff
changeset
|
695 "http2 push resources"); |
7201 | 696 |
697 ngx_str_null(&authority); | |
698 | |
699 h2lcf = ngx_http_get_module_loc_conf(r, ngx_http_v2_module); | |
700 | |
701 if (h2lcf->pushes) { | |
702 pushes = h2lcf->pushes->elts; | |
703 | |
704 for (i = 0; i < h2lcf->pushes->nelts; i++) { | |
705 | |
706 if (ngx_http_complex_value(r, &pushes[i], &path) != NGX_OK) { | |
707 return NGX_ERROR; | |
708 } | |
709 | |
710 if (path.len == 0) { | |
711 continue; | |
712 } | |
713 | |
714 if (path.len == 3 && ngx_strncmp(path.data, "off", 3) == 0) { | |
715 continue; | |
716 } | |
717 | |
718 rc = ngx_http_v2_push_resource(r, &path, &authority); | |
719 | |
720 if (rc == NGX_ERROR) { | |
721 return NGX_ERROR; | |
722 } | |
723 | |
724 if (rc == NGX_ABORT) { | |
725 return NGX_OK; | |
726 } | |
727 | |
728 /* NGX_OK, NGX_DECLINED */ | |
729 } | |
730 } | |
731 | |
732 if (!h2lcf->push_preload) { | |
733 return NGX_OK; | |
734 } | |
735 | |
736 h = r->headers_out.link.elts; | |
737 | |
738 for (i = 0; i < r->headers_out.link.nelts; i++) { | |
739 | |
7202
a49af443656f
HTTP/2: fixed build with -Werror=unused-but-set-variable.
Ruslan Ermilov <ru@nginx.com>
parents:
7201
diff
changeset
|
740 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
7201 | 741 "http2 parse link: \"%V\"", &h[i]->value); |
742 | |
743 start = h[i]->value.data; | |
744 end = h[i]->value.data + h[i]->value.len; | |
745 | |
746 next_link: | |
747 | |
748 while (start < end && *start == ' ') { start++; } | |
749 | |
750 if (start == end || *start++ != '<') { | |
751 continue; | |
752 } | |
753 | |
754 while (start < end && *start == ' ') { start++; } | |
755 | |
756 for (last = start; last < end && *last != '>'; last++) { | |
757 /* void */ | |
758 } | |
759 | |
760 if (last == start || last == end) { | |
761 continue; | |
762 } | |
763 | |
764 path.len = last - start; | |
765 path.data = start; | |
766 | |
767 start = last + 1; | |
768 | |
769 while (start < end && *start == ' ') { start++; } | |
770 | |
771 if (start == end) { | |
772 continue; | |
773 } | |
774 | |
775 if (*start == ',') { | |
776 start++; | |
777 goto next_link; | |
778 } | |
779 | |
780 if (*start++ != ';') { | |
781 continue; | |
782 } | |
783 | |
784 last = ngx_strlchr(start, end, ','); | |
785 | |
786 if (last == NULL) { | |
787 last = end; | |
788 } | |
789 | |
790 push = 0; | |
791 | |
792 for ( ;; ) { | |
793 | |
794 while (start < last && *start == ' ') { start++; } | |
795 | |
796 if (last - start >= 6 | |
797 && ngx_strncasecmp(start, (u_char *) "nopush", 6) == 0) | |
798 { | |
799 start += 6; | |
800 | |
801 if (start == last || *start == ' ' || *start == ';') { | |
802 push = 0; | |
803 break; | |
804 } | |
805 | |
806 goto next_param; | |
807 } | |
808 | |
809 if (last - start >= 11 | |
810 && ngx_strncasecmp(start, (u_char *) "rel=preload", 11) == 0) | |
811 { | |
812 start += 11; | |
813 | |
814 if (start == last || *start == ' ' || *start == ';') { | |
815 push = 1; | |
816 } | |
817 | |
818 goto next_param; | |
819 } | |
820 | |
821 if (last - start >= 4 | |
822 && ngx_strncasecmp(start, (u_char *) "rel=", 4) == 0) | |
823 { | |
824 start += 4; | |
825 | |
826 while (start < last && *start == ' ') { start++; } | |
827 | |
828 if (start == last || *start++ != '"') { | |
829 goto next_param; | |
830 } | |
831 | |
832 for ( ;; ) { | |
833 | |
834 while (start < last && *start == ' ') { start++; } | |
835 | |
836 if (last - start >= 7 | |
837 && ngx_strncasecmp(start, (u_char *) "preload", 7) == 0) | |
838 { | |
839 start += 7; | |
840 | |
841 if (start < last && (*start == ' ' || *start == '"')) { | |
842 push = 1; | |
843 break; | |
844 } | |
845 } | |
846 | |
847 while (start < last && *start != ' ' && *start != '"') { | |
848 start++; | |
849 } | |
850 | |
851 if (start == last) { | |
852 break; | |
853 } | |
854 | |
855 if (*start == '"') { | |
856 break; | |
857 } | |
858 | |
859 start++; | |
860 } | |
861 } | |
862 | |
863 next_param: | |
864 | |
865 start = ngx_strlchr(start, last, ';'); | |
866 | |
867 if (start == NULL) { | |
868 break; | |
869 } | |
870 | |
871 start++; | |
872 } | |
873 | |
874 if (push) { | |
875 while (path.len && path.data[path.len - 1] == ' ') { | |
876 path.len--; | |
877 } | |
878 } | |
879 | |
880 if (push && path.len | |
881 && !(path.len > 1 && path.data[0] == '/' && path.data[1] == '/')) | |
882 { | |
883 rc = ngx_http_v2_push_resource(r, &path, &authority); | |
884 | |
885 if (rc == NGX_ERROR) { | |
886 return NGX_ERROR; | |
887 } | |
888 | |
889 if (rc == NGX_ABORT) { | |
890 return NGX_OK; | |
891 } | |
892 | |
893 /* NGX_OK, NGX_DECLINED */ | |
894 } | |
895 | |
896 if (last < end) { | |
897 start = last + 1; | |
898 goto next_link; | |
899 } | |
900 } | |
901 | |
902 return NGX_OK; | |
903 } | |
904 | |
905 | |
906 static ngx_int_t | |
907 ngx_http_v2_push_resource(ngx_http_request_t *r, ngx_str_t *path, | |
908 ngx_str_t *authority) | |
909 { | |
910 u_char *start, *pos, *tmp; | |
911 size_t len; | |
912 ngx_table_elt_t *host; | |
913 ngx_connection_t *fc; | |
914 ngx_http_v2_stream_t *stream; | |
915 ngx_http_v2_out_frame_t *frame; | |
916 ngx_http_v2_connection_t *h2c; | |
917 | |
918 fc = r->connection; | |
919 | |
920 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, fc->log, 0, "http2 push resource"); | |
921 | |
922 stream = r->stream; | |
923 h2c = stream->connection; | |
924 | |
925 if (!ngx_path_separator(path->data[0])) { | |
926 ngx_log_error(NGX_LOG_WARN, fc->log, 0, | |
927 "non-absolute path \"%V\" not pushed", path); | |
928 return NGX_DECLINED; | |
929 } | |
930 | |
931 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, | |
932 "http2 pushing:%ui limit:%ui", | |
933 h2c->pushing, h2c->concurrent_pushes); | |
934 | |
935 if (h2c->pushing >= h2c->concurrent_pushes) { | |
936 return NGX_ABORT; | |
937 } | |
938 | |
939 if (h2c->last_push == 0x7ffffffe) { | |
940 return NGX_ABORT; | |
941 } | |
942 | |
943 if (path->len > NGX_HTTP_V2_MAX_FIELD) { | |
944 return NGX_DECLINED; | |
945 } | |
946 | |
947 host = r->headers_in.host; | |
948 | |
949 if (authority->len == 0 && host) { | |
950 | |
951 len = 1 + NGX_HTTP_V2_INT_OCTETS + host->value.len; | |
952 | |
953 tmp = ngx_palloc(r->pool, len); | |
954 pos = ngx_pnalloc(r->pool, len); | |
955 | |
956 if (pos == NULL || tmp == NULL) { | |
957 return NGX_ERROR; | |
958 } | |
959 | |
960 authority->data = pos; | |
961 | |
962 *pos++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_AUTHORITY_INDEX); | |
963 pos = ngx_http_v2_write_value(pos, host->value.data, host->value.len, | |
964 tmp); | |
965 | |
966 authority->len = pos - authority->data; | |
967 } | |
968 | |
969 len = (h2c->table_update ? 1 : 0) | |
970 + 1 | |
971 + 1 + NGX_HTTP_V2_INT_OCTETS + path->len | |
972 + authority->len | |
973 + 1; | |
974 | |
975 tmp = ngx_palloc(r->pool, len); | |
976 pos = ngx_pnalloc(r->pool, len); | |
977 | |
978 if (pos == NULL || tmp == NULL) { | |
979 return NGX_ERROR; | |
980 } | |
981 | |
982 start = pos; | |
983 | |
984 if (h2c->table_update) { | |
985 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, fc->log, 0, | |
986 "http2 table size update: 0"); | |
987 *pos++ = (1 << 5) | 0; | |
988 h2c->table_update = 0; | |
989 } | |
990 | |
991 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, fc->log, 0, | |
992 "http2 push header: \":method: GET\""); | |
993 | |
994 *pos++ = ngx_http_v2_indexed(NGX_HTTP_V2_METHOD_GET_INDEX); | |
995 | |
996 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, fc->log, 0, | |
997 "http2 push header: \":path: %V\"", path); | |
998 | |
999 *pos++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_PATH_INDEX); | |
1000 pos = ngx_http_v2_write_value(pos, path->data, path->len, tmp); | |
1001 | |
1002 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, fc->log, 0, | |
1003 "http2 push header: \":authority: %V\"", &host->value); | |
1004 | |
1005 pos = ngx_cpymem(pos, authority->data, authority->len); | |
1006 | |
1007 #if (NGX_HTTP_SSL) | |
1008 if (fc->ssl) { | |
1009 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, fc->log, 0, | |
1010 "http2 push header: \":scheme: https\""); | |
1011 *pos++ = ngx_http_v2_indexed(NGX_HTTP_V2_SCHEME_HTTPS_INDEX); | |
1012 | |
1013 } else | |
1014 #endif | |
1015 { | |
1016 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, fc->log, 0, | |
1017 "http2 push header: \":scheme: http\""); | |
1018 *pos++ = ngx_http_v2_indexed(NGX_HTTP_V2_SCHEME_HTTP_INDEX); | |
1019 } | |
1020 | |
1021 frame = ngx_http_v2_create_push_frame(r, start, pos); | |
1022 if (frame == NULL) { | |
1023 return NGX_ERROR; | |
1024 } | |
1025 | |
1026 ngx_http_v2_queue_blocked_frame(h2c, frame); | |
1027 | |
1028 stream->queued++; | |
1029 | |
1030 return ngx_http_v2_push_stream(h2c, stream->node->id, pos - start, | |
1031 path, &host->value); | |
1032 } | |
1033 | |
1034 | |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1035 static u_char * |
6395
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
1036 ngx_http_v2_string_encode(u_char *dst, u_char *src, size_t len, u_char *tmp, |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
1037 ngx_uint_t lower) |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
1038 { |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
1039 size_t hlen; |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
1040 |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
1041 hlen = ngx_http_v2_huff_encode(src, len, tmp, lower); |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
1042 |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
1043 if (hlen > 0) { |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
1044 *dst = NGX_HTTP_V2_ENCODE_HUFF; |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
1045 dst = ngx_http_v2_write_int(dst, ngx_http_v2_prefix(7), hlen); |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
1046 return ngx_cpymem(dst, tmp, hlen); |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
1047 } |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
1048 |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
1049 *dst = NGX_HTTP_V2_ENCODE_RAW; |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
1050 dst = ngx_http_v2_write_int(dst, ngx_http_v2_prefix(7), len); |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
1051 |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
1052 if (lower) { |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
1053 ngx_strlow(dst, src, len); |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
1054 return dst + len; |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
1055 } |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
1056 |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
1057 return ngx_cpymem(dst, src, len); |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
1058 } |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
1059 |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
1060 |
ba3c2ca21aa5
HTTP/2: implemented HPACK Huffman encoding for response headers.
Valentin Bartenev <vbart@nginx.com>
parents:
6377
diff
changeset
|
1061 static u_char * |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1062 ngx_http_v2_write_int(u_char *pos, ngx_uint_t prefix, ngx_uint_t value) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1063 { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1064 if (value < prefix) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1065 *pos++ |= value; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1066 return pos; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1067 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1068 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1069 *pos++ |= prefix; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1070 value -= prefix; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1071 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1072 while (value >= 128) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1073 *pos++ = value % 128 + 128; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1074 value /= 128; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1075 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1076 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1077 *pos++ = (u_char) value; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1078 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1079 return pos; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1080 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1081 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1082 |
6277
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1083 static ngx_http_v2_out_frame_t * |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1084 ngx_http_v2_create_headers_frame(ngx_http_request_t *r, u_char *pos, |
7035
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
1085 u_char *end, ngx_uint_t fin) |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1086 { |
6277
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1087 u_char type, flags; |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1088 size_t rest, frame_size; |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1089 ngx_buf_t *b; |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1090 ngx_chain_t *cl, **ll; |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1091 ngx_http_v2_stream_t *stream; |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1092 ngx_http_v2_out_frame_t *frame; |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1093 |
6277
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1094 stream = r->stream; |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1095 rest = end - pos; |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1096 |
6277
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1097 frame = ngx_palloc(r->pool, sizeof(ngx_http_v2_out_frame_t)); |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1098 if (frame == NULL) { |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1099 return NULL; |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1100 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1101 |
6277
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1102 frame->handler = ngx_http_v2_headers_frame_handler; |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1103 frame->stream = stream; |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1104 frame->length = rest; |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1105 frame->blocked = 1; |
7035
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
1106 frame->fin = fin; |
6277
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1107 |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1108 ll = &frame->first; |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1109 |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1110 type = NGX_HTTP_V2_HEADERS_FRAME; |
7035
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
1111 flags = fin ? NGX_HTTP_V2_END_STREAM_FLAG : NGX_HTTP_V2_NO_FLAG; |
6277
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1112 frame_size = stream->connection->frame_size; |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1113 |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1114 for ( ;; ) { |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1115 if (rest <= frame_size) { |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1116 frame_size = rest; |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1117 flags |= NGX_HTTP_V2_END_HEADERS_FLAG; |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1118 } |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1119 |
6277
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1120 b = ngx_create_temp_buf(r->pool, NGX_HTTP_V2_FRAME_HEADER_SIZE); |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1121 if (b == NULL) { |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1122 return NULL; |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1123 } |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1124 |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1125 b->last = ngx_http_v2_write_len_and_type(b->last, frame_size, type); |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1126 *b->last++ = flags; |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1127 b->last = ngx_http_v2_write_sid(b->last, stream->node->id); |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1128 |
6293
ec6b07be88a5
HTTP/2: reused HEADERS and CONTINUATION frames buffers.
Valentin Bartenev <vbart@nginx.com>
parents:
6292
diff
changeset
|
1129 b->tag = (ngx_buf_tag_t) &ngx_http_v2_module; |
ec6b07be88a5
HTTP/2: reused HEADERS and CONTINUATION frames buffers.
Valentin Bartenev <vbart@nginx.com>
parents:
6292
diff
changeset
|
1130 |
6277
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1131 cl = ngx_alloc_chain_link(r->pool); |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1132 if (cl == NULL) { |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1133 return NULL; |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1134 } |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1135 |
6277
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1136 cl->buf = b; |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1137 |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1138 *ll = cl; |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1139 ll = &cl->next; |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1140 |
6277
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1141 b = ngx_calloc_buf(r->pool); |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1142 if (b == NULL) { |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1143 return NULL; |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1144 } |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1145 |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1146 b->pos = pos; |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1147 |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1148 pos += frame_size; |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1149 |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1150 b->last = pos; |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1151 b->start = b->pos; |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1152 b->end = b->last; |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1153 b->temporary = 1; |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1154 |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1155 cl = ngx_alloc_chain_link(r->pool); |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1156 if (cl == NULL) { |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1157 return NULL; |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1158 } |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1159 |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1160 cl->buf = b; |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1161 |
6277
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1162 *ll = cl; |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1163 ll = &cl->next; |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1164 |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1165 rest -= frame_size; |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1166 |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1167 if (rest) { |
6952
afc60bd9008f
HTTP/2: fix $bytes_sent variable.
Piotr Sikora <piotrsikora@google.com>
parents:
6885
diff
changeset
|
1168 frame->length += NGX_HTTP_V2_FRAME_HEADER_SIZE; |
afc60bd9008f
HTTP/2: fix $bytes_sent variable.
Piotr Sikora <piotrsikora@google.com>
parents:
6885
diff
changeset
|
1169 |
6277
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1170 type = NGX_HTTP_V2_CONTINUATION_FRAME; |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1171 flags = NGX_HTTP_V2_NO_FLAG; |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1172 continue; |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1173 } |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1174 |
7035
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
1175 b->last_buf = fin; |
6277
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1176 cl->next = NULL; |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1177 frame->last = cl; |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1178 |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1179 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1180 "http2:%ui create HEADERS frame %p: len:%uz", |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1181 stream->node->id, frame, frame->length); |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1182 |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1183 return frame; |
b930e598a199
HTTP/2: fixed splitting of response headers on CONTINUATION frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6276
diff
changeset
|
1184 } |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1185 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1186 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1187 |
7191
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1188 static ngx_http_v2_out_frame_t * |
7201 | 1189 ngx_http_v2_create_push_frame(ngx_http_request_t *r, u_char *pos, u_char *end) |
1190 { | |
1191 u_char type, flags; | |
1192 size_t rest, frame_size, len; | |
1193 ngx_buf_t *b; | |
1194 ngx_chain_t *cl, **ll; | |
1195 ngx_http_v2_stream_t *stream; | |
1196 ngx_http_v2_out_frame_t *frame; | |
1197 ngx_http_v2_connection_t *h2c; | |
1198 | |
1199 stream = r->stream; | |
1200 h2c = stream->connection; | |
1201 rest = NGX_HTTP_V2_STREAM_ID_SIZE + (end - pos); | |
1202 | |
1203 frame = ngx_palloc(r->pool, sizeof(ngx_http_v2_out_frame_t)); | |
1204 if (frame == NULL) { | |
1205 return NULL; | |
1206 } | |
1207 | |
1208 frame->handler = ngx_http_v2_push_frame_handler; | |
1209 frame->stream = stream; | |
1210 frame->length = rest; | |
1211 frame->blocked = 1; | |
1212 frame->fin = 0; | |
1213 | |
1214 ll = &frame->first; | |
1215 | |
1216 type = NGX_HTTP_V2_PUSH_PROMISE_FRAME; | |
1217 flags = NGX_HTTP_V2_NO_FLAG; | |
1218 frame_size = h2c->frame_size; | |
1219 | |
1220 for ( ;; ) { | |
1221 if (rest <= frame_size) { | |
1222 frame_size = rest; | |
1223 flags |= NGX_HTTP_V2_END_HEADERS_FLAG; | |
1224 } | |
1225 | |
1226 b = ngx_create_temp_buf(r->pool, | |
1227 NGX_HTTP_V2_FRAME_HEADER_SIZE | |
1228 + ((type == NGX_HTTP_V2_PUSH_PROMISE_FRAME) | |
1229 ? NGX_HTTP_V2_STREAM_ID_SIZE : 0)); | |
1230 if (b == NULL) { | |
1231 return NULL; | |
1232 } | |
1233 | |
1234 b->last = ngx_http_v2_write_len_and_type(b->last, frame_size, type); | |
1235 *b->last++ = flags; | |
1236 b->last = ngx_http_v2_write_sid(b->last, stream->node->id); | |
1237 | |
1238 b->tag = (ngx_buf_tag_t) &ngx_http_v2_module; | |
1239 | |
1240 if (type == NGX_HTTP_V2_PUSH_PROMISE_FRAME) { | |
1241 h2c->last_push += 2; | |
1242 | |
1243 b->last = ngx_http_v2_write_sid(b->last, h2c->last_push); | |
1244 len = frame_size - NGX_HTTP_V2_STREAM_ID_SIZE; | |
1245 | |
1246 } else { | |
1247 len = frame_size; | |
1248 } | |
1249 | |
1250 cl = ngx_alloc_chain_link(r->pool); | |
1251 if (cl == NULL) { | |
1252 return NULL; | |
1253 } | |
1254 | |
1255 cl->buf = b; | |
1256 | |
1257 *ll = cl; | |
1258 ll = &cl->next; | |
1259 | |
1260 b = ngx_calloc_buf(r->pool); | |
1261 if (b == NULL) { | |
1262 return NULL; | |
1263 } | |
1264 | |
1265 b->pos = pos; | |
1266 | |
1267 pos += len; | |
1268 | |
1269 b->last = pos; | |
1270 b->start = b->pos; | |
1271 b->end = b->last; | |
1272 b->temporary = 1; | |
1273 | |
1274 cl = ngx_alloc_chain_link(r->pool); | |
1275 if (cl == NULL) { | |
1276 return NULL; | |
1277 } | |
1278 | |
1279 cl->buf = b; | |
1280 | |
1281 *ll = cl; | |
1282 ll = &cl->next; | |
1283 | |
1284 rest -= frame_size; | |
1285 | |
1286 if (rest) { | |
1287 frame->length += NGX_HTTP_V2_FRAME_HEADER_SIZE; | |
1288 | |
1289 type = NGX_HTTP_V2_CONTINUATION_FRAME; | |
1290 continue; | |
1291 } | |
1292 | |
1293 cl->next = NULL; | |
1294 frame->last = cl; | |
1295 | |
1296 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1297 "http2:%ui create PUSH_PROMISE frame %p: " | |
1298 "sid:%ui len:%uz", | |
1299 stream->node->id, frame, h2c->last_push, | |
1300 frame->length); | |
1301 | |
1302 return frame; | |
1303 } | |
1304 } | |
1305 | |
1306 | |
1307 static ngx_http_v2_out_frame_t * | |
7191
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1308 ngx_http_v2_create_trailers_frame(ngx_http_request_t *r) |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1309 { |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1310 u_char *pos, *start, *tmp; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1311 size_t len, tmp_len; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1312 ngx_uint_t i; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1313 ngx_list_part_t *part; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1314 ngx_table_elt_t *header; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1315 ngx_connection_t *fc; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1316 |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1317 fc = r->connection; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1318 len = 0; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1319 tmp_len = 0; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1320 |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1321 part = &r->headers_out.trailers.part; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1322 header = part->elts; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1323 |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1324 for (i = 0; /* void */; i++) { |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1325 |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1326 if (i >= part->nelts) { |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1327 if (part->next == NULL) { |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1328 break; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1329 } |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1330 |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1331 part = part->next; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1332 header = part->elts; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1333 i = 0; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1334 } |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1335 |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1336 if (header[i].hash == 0) { |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1337 continue; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1338 } |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1339 |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1340 if (header[i].key.len > NGX_HTTP_V2_MAX_FIELD) { |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1341 ngx_log_error(NGX_LOG_CRIT, fc->log, 0, |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1342 "too long response trailer name: \"%V\"", |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1343 &header[i].key); |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1344 return NULL; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1345 } |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1346 |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1347 if (header[i].value.len > NGX_HTTP_V2_MAX_FIELD) { |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1348 ngx_log_error(NGX_LOG_CRIT, fc->log, 0, |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1349 "too long response trailer value: \"%V: %V\"", |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1350 &header[i].key, &header[i].value); |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1351 return NULL; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1352 } |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1353 |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1354 len += 1 + NGX_HTTP_V2_INT_OCTETS + header[i].key.len |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1355 + NGX_HTTP_V2_INT_OCTETS + header[i].value.len; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1356 |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1357 if (header[i].key.len > tmp_len) { |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1358 tmp_len = header[i].key.len; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1359 } |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1360 |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1361 if (header[i].value.len > tmp_len) { |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1362 tmp_len = header[i].value.len; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1363 } |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1364 } |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1365 |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1366 if (len == 0) { |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1367 return NGX_HTTP_V2_NO_TRAILERS; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1368 } |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1369 |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1370 tmp = ngx_palloc(r->pool, tmp_len); |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1371 pos = ngx_pnalloc(r->pool, len); |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1372 |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1373 if (pos == NULL || tmp == NULL) { |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1374 return NULL; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1375 } |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1376 |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1377 start = pos; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1378 |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1379 part = &r->headers_out.trailers.part; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1380 header = part->elts; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1381 |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1382 for (i = 0; /* void */; i++) { |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1383 |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1384 if (i >= part->nelts) { |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1385 if (part->next == NULL) { |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1386 break; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1387 } |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1388 |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1389 part = part->next; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1390 header = part->elts; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1391 i = 0; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1392 } |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1393 |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1394 if (header[i].hash == 0) { |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1395 continue; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1396 } |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1397 |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1398 #if (NGX_DEBUG) |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1399 if (fc->log->log_level & NGX_LOG_DEBUG_HTTP) { |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1400 ngx_strlow(tmp, header[i].key.data, header[i].key.len); |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1401 |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1402 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, fc->log, 0, |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1403 "http2 output trailer: \"%*s: %V\"", |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1404 header[i].key.len, tmp, &header[i].value); |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1405 } |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1406 #endif |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1407 |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1408 *pos++ = 0; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1409 |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1410 pos = ngx_http_v2_write_name(pos, header[i].key.data, |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1411 header[i].key.len, tmp); |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1412 |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1413 pos = ngx_http_v2_write_value(pos, header[i].value.data, |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1414 header[i].value.len, tmp); |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1415 } |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1416 |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1417 return ngx_http_v2_create_headers_frame(r, start, pos, 1); |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1418 } |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1419 |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1420 |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1421 static ngx_chain_t * |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1422 ngx_http_v2_send_chain(ngx_connection_t *fc, ngx_chain_t *in, off_t limit) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1423 { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1424 off_t size, offset; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1425 size_t rest, frame_size; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1426 ngx_chain_t *cl, *out, **ln; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1427 ngx_http_request_t *r; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1428 ngx_http_v2_stream_t *stream; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1429 ngx_http_v2_loc_conf_t *h2lcf; |
7035
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
1430 ngx_http_v2_out_frame_t *frame, *trailers; |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1431 ngx_http_v2_connection_t *h2c; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1432 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1433 r = fc->data; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1434 stream = r->stream; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1435 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1436 #if (NGX_SUPPRESS_WARN) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1437 size = 0; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1438 #endif |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1439 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1440 while (in) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1441 size = ngx_buf_size(in->buf); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1442 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1443 if (size || in->buf->last_buf) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1444 break; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1445 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1446 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1447 in = in->next; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1448 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1449 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1450 if (in == NULL) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1451 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1452 if (stream->queued) { |
6412
4ba91a4c66a3
HTTP/2: implemented per request timeouts (closes #626).
Valentin Bartenev <vbart@nginx.com>
parents:
6401
diff
changeset
|
1453 fc->write->active = 1; |
4ba91a4c66a3
HTTP/2: implemented per request timeouts (closes #626).
Valentin Bartenev <vbart@nginx.com>
parents:
6401
diff
changeset
|
1454 fc->write->ready = 0; |
4ba91a4c66a3
HTTP/2: implemented per request timeouts (closes #626).
Valentin Bartenev <vbart@nginx.com>
parents:
6401
diff
changeset
|
1455 |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1456 } else { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1457 fc->buffered &= ~NGX_HTTP_V2_BUFFERED; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1458 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1459 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1460 return NULL; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1461 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1462 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1463 h2c = stream->connection; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1464 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1465 if (size && ngx_http_v2_flow_control(h2c, stream) == NGX_DECLINED) { |
6412
4ba91a4c66a3
HTTP/2: implemented per request timeouts (closes #626).
Valentin Bartenev <vbart@nginx.com>
parents:
6401
diff
changeset
|
1466 fc->write->active = 1; |
4ba91a4c66a3
HTTP/2: implemented per request timeouts (closes #626).
Valentin Bartenev <vbart@nginx.com>
parents:
6401
diff
changeset
|
1467 fc->write->ready = 0; |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1468 return in; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1469 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1470 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1471 if (in->buf->tag == (ngx_buf_tag_t) &ngx_http_v2_filter_get_shadow) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1472 cl = ngx_alloc_chain_link(r->pool); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1473 if (cl == NULL) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1474 return NGX_CHAIN_ERROR; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1475 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1476 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1477 cl->buf = in->buf; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1478 in->buf = cl->buf->shadow; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1479 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1480 offset = ngx_buf_in_memory(in->buf) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1481 ? (cl->buf->pos - in->buf->pos) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1482 : (cl->buf->file_pos - in->buf->file_pos); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1483 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1484 cl->next = stream->free_bufs; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1485 stream->free_bufs = cl; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1486 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1487 } else { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1488 offset = 0; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1489 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1490 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1491 if (limit == 0 || limit > (off_t) h2c->send_window) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1492 limit = h2c->send_window; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1493 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1494 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1495 if (limit > stream->send_window) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1496 limit = (stream->send_window > 0) ? stream->send_window : 0; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1497 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1498 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1499 h2lcf = ngx_http_get_module_loc_conf(r, ngx_http_v2_module); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1500 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1501 frame_size = (h2lcf->chunk_size < h2c->frame_size) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1502 ? h2lcf->chunk_size : h2c->frame_size; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1503 |
7035
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
1504 trailers = NGX_HTTP_V2_NO_TRAILERS; |
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
1505 |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1506 #if (NGX_SUPPRESS_WARN) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1507 cl = NULL; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1508 #endif |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1509 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1510 for ( ;; ) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1511 if ((off_t) frame_size > limit) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1512 frame_size = (size_t) limit; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1513 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1514 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1515 ln = &out; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1516 rest = frame_size; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1517 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1518 while ((off_t) rest >= size) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1519 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1520 if (offset) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1521 cl = ngx_http_v2_filter_get_shadow(stream, in->buf, |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1522 offset, size); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1523 if (cl == NULL) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1524 return NGX_CHAIN_ERROR; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1525 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1526 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1527 offset = 0; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1528 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1529 } else { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1530 cl = ngx_alloc_chain_link(r->pool); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1531 if (cl == NULL) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1532 return NGX_CHAIN_ERROR; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1533 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1534 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1535 cl->buf = in->buf; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1536 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1537 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1538 *ln = cl; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1539 ln = &cl->next; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1540 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1541 rest -= (size_t) size; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1542 in = in->next; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1543 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1544 if (in == NULL) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1545 frame_size -= rest; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1546 rest = 0; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1547 break; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1548 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1549 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1550 size = ngx_buf_size(in->buf); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1551 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1552 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1553 if (rest) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1554 cl = ngx_http_v2_filter_get_shadow(stream, in->buf, offset, rest); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1555 if (cl == NULL) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1556 return NGX_CHAIN_ERROR; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1557 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1558 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1559 cl->buf->flush = 0; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1560 cl->buf->last_buf = 0; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1561 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1562 *ln = cl; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1563 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1564 offset += rest; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1565 size -= rest; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1566 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1567 |
7035
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
1568 if (cl->buf->last_buf) { |
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
1569 trailers = ngx_http_v2_create_trailers_frame(r); |
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
1570 if (trailers == NULL) { |
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
1571 return NGX_CHAIN_ERROR; |
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
1572 } |
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
1573 |
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
1574 if (trailers != NGX_HTTP_V2_NO_TRAILERS) { |
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
1575 cl->buf->last_buf = 0; |
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
1576 } |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1577 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1578 |
7035
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
1579 if (frame_size || cl->buf->last_buf) { |
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
1580 frame = ngx_http_v2_filter_get_data_frame(stream, frame_size, |
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
1581 out, cl); |
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
1582 if (frame == NULL) { |
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
1583 return NGX_CHAIN_ERROR; |
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
1584 } |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1585 |
7035
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
1586 ngx_http_v2_queue_frame(h2c, frame); |
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
1587 |
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
1588 h2c->send_window -= frame_size; |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1589 |
7035
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
1590 stream->send_window -= frame_size; |
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
1591 stream->queued++; |
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
1592 } |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1593 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1594 if (in == NULL) { |
7035
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
1595 |
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
1596 if (trailers != NGX_HTTP_V2_NO_TRAILERS) { |
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
1597 ngx_http_v2_queue_frame(h2c, trailers); |
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
1598 stream->queued++; |
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
1599 } |
4e784e095a97
HTTP/2: added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
7004
diff
changeset
|
1600 |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1601 break; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1602 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1603 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1604 limit -= frame_size; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1605 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1606 if (limit == 0) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1607 break; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1608 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1609 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1610 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1611 if (offset) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1612 cl = ngx_http_v2_filter_get_shadow(stream, in->buf, offset, size); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1613 if (cl == NULL) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1614 return NGX_CHAIN_ERROR; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1615 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1616 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1617 in->buf = cl->buf; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1618 ngx_free_chain(r->pool, cl); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1619 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1620 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1621 if (ngx_http_v2_filter_send(fc, stream) == NGX_ERROR) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1622 return NGX_CHAIN_ERROR; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1623 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1624 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1625 if (in && ngx_http_v2_flow_control(h2c, stream) == NGX_DECLINED) { |
6412
4ba91a4c66a3
HTTP/2: implemented per request timeouts (closes #626).
Valentin Bartenev <vbart@nginx.com>
parents:
6401
diff
changeset
|
1626 fc->write->active = 1; |
4ba91a4c66a3
HTTP/2: implemented per request timeouts (closes #626).
Valentin Bartenev <vbart@nginx.com>
parents:
6401
diff
changeset
|
1627 fc->write->ready = 0; |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1628 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1629 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1630 return in; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1631 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1632 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1633 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1634 static ngx_chain_t * |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1635 ngx_http_v2_filter_get_shadow(ngx_http_v2_stream_t *stream, ngx_buf_t *buf, |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1636 off_t offset, off_t size) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1637 { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1638 ngx_buf_t *chunk; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1639 ngx_chain_t *cl; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1640 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1641 cl = ngx_chain_get_free_buf(stream->request->pool, &stream->free_bufs); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1642 if (cl == NULL) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1643 return NULL; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1644 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1645 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1646 chunk = cl->buf; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1647 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1648 ngx_memcpy(chunk, buf, sizeof(ngx_buf_t)); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1649 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1650 chunk->tag = (ngx_buf_tag_t) &ngx_http_v2_filter_get_shadow; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1651 chunk->shadow = buf; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1652 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1653 if (ngx_buf_in_memory(chunk)) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1654 chunk->pos += offset; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1655 chunk->last = chunk->pos + size; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1656 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1657 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1658 if (chunk->in_file) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1659 chunk->file_pos += offset; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1660 chunk->file_last = chunk->file_pos + size; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1661 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1662 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1663 return cl; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1664 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1665 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1666 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1667 static ngx_http_v2_out_frame_t * |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1668 ngx_http_v2_filter_get_data_frame(ngx_http_v2_stream_t *stream, |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1669 size_t len, ngx_chain_t *first, ngx_chain_t *last) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1670 { |
6600 | 1671 u_char flags; |
1672 ngx_buf_t *buf; | |
1673 ngx_chain_t *cl; | |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1674 ngx_http_v2_out_frame_t *frame; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1675 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1676 frame = stream->free_frames; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1677 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1678 if (frame) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1679 stream->free_frames = frame->next; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1680 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1681 } else { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1682 frame = ngx_palloc(stream->request->pool, |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1683 sizeof(ngx_http_v2_out_frame_t)); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1684 if (frame == NULL) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1685 return NULL; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1686 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1687 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1688 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1689 flags = last->buf->last_buf ? NGX_HTTP_V2_END_STREAM_FLAG : 0; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1690 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1691 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, stream->request->connection->log, 0, |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1692 "http2:%ui create DATA frame %p: len:%uz flags:%ui", |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1693 stream->node->id, frame, len, (ngx_uint_t) flags); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1694 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1695 cl = ngx_chain_get_free_buf(stream->request->pool, |
6293
ec6b07be88a5
HTTP/2: reused HEADERS and CONTINUATION frames buffers.
Valentin Bartenev <vbart@nginx.com>
parents:
6292
diff
changeset
|
1696 &stream->free_frame_headers); |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1697 if (cl == NULL) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1698 return NULL; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1699 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1700 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1701 buf = cl->buf; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1702 |
6600 | 1703 if (buf->start == NULL) { |
6251 | 1704 buf->start = ngx_palloc(stream->request->pool, |
1705 NGX_HTTP_V2_FRAME_HEADER_SIZE); | |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1706 if (buf->start == NULL) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1707 return NULL; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1708 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1709 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1710 buf->end = buf->start + NGX_HTTP_V2_FRAME_HEADER_SIZE; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1711 buf->last = buf->end; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1712 |
6293
ec6b07be88a5
HTTP/2: reused HEADERS and CONTINUATION frames buffers.
Valentin Bartenev <vbart@nginx.com>
parents:
6292
diff
changeset
|
1713 buf->tag = (ngx_buf_tag_t) &ngx_http_v2_module; |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1714 buf->memory = 1; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1715 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1716 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1717 buf->pos = buf->start; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1718 buf->last = buf->pos; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1719 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1720 buf->last = ngx_http_v2_write_len_and_type(buf->last, len, |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1721 NGX_HTTP_V2_DATA_FRAME); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1722 *buf->last++ = flags; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1723 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1724 buf->last = ngx_http_v2_write_sid(buf->last, stream->node->id); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1725 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1726 cl->next = first; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1727 first = cl; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1728 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1729 last->buf->flush = 1; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1730 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1731 frame->first = first; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1732 frame->last = last; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1733 frame->handler = ngx_http_v2_data_frame_handler; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1734 frame->stream = stream; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1735 frame->length = len; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1736 frame->blocked = 0; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1737 frame->fin = last->buf->last_buf; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1738 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1739 return frame; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1740 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1741 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1742 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1743 static ngx_inline ngx_int_t |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1744 ngx_http_v2_flow_control(ngx_http_v2_connection_t *h2c, |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1745 ngx_http_v2_stream_t *stream) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1746 { |
6792
45d553812055
HTTP/2: flow control debugging.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6638
diff
changeset
|
1747 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, |
7108
2bf605c6edf7
HTTP/2: shortened some debug log messages.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7100
diff
changeset
|
1748 "http2:%ui windows: conn:%uz stream:%z", |
6792
45d553812055
HTTP/2: flow control debugging.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6638
diff
changeset
|
1749 stream->node->id, h2c->send_window, stream->send_window); |
45d553812055
HTTP/2: flow control debugging.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6638
diff
changeset
|
1750 |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1751 if (stream->send_window <= 0) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1752 stream->exhausted = 1; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1753 return NGX_DECLINED; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1754 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1755 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1756 if (h2c->send_window == 0) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1757 ngx_http_v2_waiting_queue(h2c, stream); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1758 return NGX_DECLINED; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1759 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1760 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1761 return NGX_OK; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1762 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1763 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1764 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1765 static void |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1766 ngx_http_v2_waiting_queue(ngx_http_v2_connection_t *h2c, |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1767 ngx_http_v2_stream_t *stream) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1768 { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1769 ngx_queue_t *q; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1770 ngx_http_v2_stream_t *s; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1771 |
6833
3834951e32ab
HTTP/2: fixed posted streams handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6792
diff
changeset
|
1772 if (stream->waiting) { |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1773 return; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1774 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1775 |
6833
3834951e32ab
HTTP/2: fixed posted streams handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6792
diff
changeset
|
1776 stream->waiting = 1; |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1777 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1778 for (q = ngx_queue_last(&h2c->waiting); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1779 q != ngx_queue_sentinel(&h2c->waiting); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1780 q = ngx_queue_prev(q)) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1781 { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1782 s = ngx_queue_data(q, ngx_http_v2_stream_t, queue); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1783 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1784 if (s->node->rank < stream->node->rank |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1785 || (s->node->rank == stream->node->rank |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1786 && s->node->rel_weight >= stream->node->rel_weight)) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1787 { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1788 break; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1789 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1790 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1791 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1792 ngx_queue_insert_after(q, &stream->queue); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1793 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1794 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1795 |
7191
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1796 static ngx_inline ngx_int_t |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1797 ngx_http_v2_filter_send(ngx_connection_t *fc, ngx_http_v2_stream_t *stream) |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1798 { |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1799 stream->blocked = 1; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1800 |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1801 if (ngx_http_v2_send_output_queue(stream->connection) == NGX_ERROR) { |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1802 fc->error = 1; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1803 return NGX_ERROR; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1804 } |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1805 |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1806 stream->blocked = 0; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1807 |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1808 if (stream->queued) { |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1809 fc->buffered |= NGX_HTTP_V2_BUFFERED; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1810 fc->write->active = 1; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1811 fc->write->ready = 0; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1812 return NGX_AGAIN; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1813 } |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1814 |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1815 fc->buffered &= ~NGX_HTTP_V2_BUFFERED; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1816 |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1817 return NGX_OK; |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1818 } |
61d276dcd493
HTTP/2: more style, comments, and debugging.
Ruslan Ermilov <ru@nginx.com>
parents:
7108
diff
changeset
|
1819 |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1820 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1821 static ngx_int_t |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1822 ngx_http_v2_headers_frame_handler(ngx_http_v2_connection_t *h2c, |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1823 ngx_http_v2_out_frame_t *frame) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1824 { |
6293
ec6b07be88a5
HTTP/2: reused HEADERS and CONTINUATION frames buffers.
Valentin Bartenev <vbart@nginx.com>
parents:
6292
diff
changeset
|
1825 ngx_chain_t *cl, *ln; |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1826 ngx_http_v2_stream_t *stream; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1827 |
6292
f72d3129cd35
HTTP/2: fixed handling of output HEADERS frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6279
diff
changeset
|
1828 stream = frame->stream; |
f72d3129cd35
HTTP/2: fixed handling of output HEADERS frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6279
diff
changeset
|
1829 cl = frame->first; |
f72d3129cd35
HTTP/2: fixed handling of output HEADERS frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6279
diff
changeset
|
1830 |
f72d3129cd35
HTTP/2: fixed handling of output HEADERS frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6279
diff
changeset
|
1831 for ( ;; ) { |
f72d3129cd35
HTTP/2: fixed handling of output HEADERS frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6279
diff
changeset
|
1832 if (cl->buf->pos != cl->buf->last) { |
f72d3129cd35
HTTP/2: fixed handling of output HEADERS frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6279
diff
changeset
|
1833 frame->first = cl; |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1834 |
6292
f72d3129cd35
HTTP/2: fixed handling of output HEADERS frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6279
diff
changeset
|
1835 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, |
f72d3129cd35
HTTP/2: fixed handling of output HEADERS frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6279
diff
changeset
|
1836 "http2:%ui HEADERS frame %p was sent partially", |
f72d3129cd35
HTTP/2: fixed handling of output HEADERS frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6279
diff
changeset
|
1837 stream->node->id, frame); |
f72d3129cd35
HTTP/2: fixed handling of output HEADERS frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6279
diff
changeset
|
1838 |
f72d3129cd35
HTTP/2: fixed handling of output HEADERS frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6279
diff
changeset
|
1839 return NGX_AGAIN; |
f72d3129cd35
HTTP/2: fixed handling of output HEADERS frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6279
diff
changeset
|
1840 } |
f72d3129cd35
HTTP/2: fixed handling of output HEADERS frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6279
diff
changeset
|
1841 |
6293
ec6b07be88a5
HTTP/2: reused HEADERS and CONTINUATION frames buffers.
Valentin Bartenev <vbart@nginx.com>
parents:
6292
diff
changeset
|
1842 ln = cl->next; |
ec6b07be88a5
HTTP/2: reused HEADERS and CONTINUATION frames buffers.
Valentin Bartenev <vbart@nginx.com>
parents:
6292
diff
changeset
|
1843 |
ec6b07be88a5
HTTP/2: reused HEADERS and CONTINUATION frames buffers.
Valentin Bartenev <vbart@nginx.com>
parents:
6292
diff
changeset
|
1844 if (cl->buf->tag == (ngx_buf_tag_t) &ngx_http_v2_module) { |
ec6b07be88a5
HTTP/2: reused HEADERS and CONTINUATION frames buffers.
Valentin Bartenev <vbart@nginx.com>
parents:
6292
diff
changeset
|
1845 cl->next = stream->free_frame_headers; |
ec6b07be88a5
HTTP/2: reused HEADERS and CONTINUATION frames buffers.
Valentin Bartenev <vbart@nginx.com>
parents:
6292
diff
changeset
|
1846 stream->free_frame_headers = cl; |
ec6b07be88a5
HTTP/2: reused HEADERS and CONTINUATION frames buffers.
Valentin Bartenev <vbart@nginx.com>
parents:
6292
diff
changeset
|
1847 |
ec6b07be88a5
HTTP/2: reused HEADERS and CONTINUATION frames buffers.
Valentin Bartenev <vbart@nginx.com>
parents:
6292
diff
changeset
|
1848 } else { |
ec6b07be88a5
HTTP/2: reused HEADERS and CONTINUATION frames buffers.
Valentin Bartenev <vbart@nginx.com>
parents:
6292
diff
changeset
|
1849 cl->next = stream->free_bufs; |
ec6b07be88a5
HTTP/2: reused HEADERS and CONTINUATION frames buffers.
Valentin Bartenev <vbart@nginx.com>
parents:
6292
diff
changeset
|
1850 stream->free_bufs = cl; |
ec6b07be88a5
HTTP/2: reused HEADERS and CONTINUATION frames buffers.
Valentin Bartenev <vbart@nginx.com>
parents:
6292
diff
changeset
|
1851 } |
ec6b07be88a5
HTTP/2: reused HEADERS and CONTINUATION frames buffers.
Valentin Bartenev <vbart@nginx.com>
parents:
6292
diff
changeset
|
1852 |
6292
f72d3129cd35
HTTP/2: fixed handling of output HEADERS frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6279
diff
changeset
|
1853 if (cl == frame->last) { |
f72d3129cd35
HTTP/2: fixed handling of output HEADERS frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6279
diff
changeset
|
1854 break; |
f72d3129cd35
HTTP/2: fixed handling of output HEADERS frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6279
diff
changeset
|
1855 } |
f72d3129cd35
HTTP/2: fixed handling of output HEADERS frames.
Valentin Bartenev <vbart@nginx.com>
parents:
6279
diff
changeset
|
1856 |
6293
ec6b07be88a5
HTTP/2: reused HEADERS and CONTINUATION frames buffers.
Valentin Bartenev <vbart@nginx.com>
parents:
6292
diff
changeset
|
1857 cl = ln; |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1858 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1859 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1860 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1861 "http2:%ui HEADERS frame %p was sent", |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1862 stream->node->id, frame); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1863 |
6953
663e6a48bfcb
HTTP/2: fix $body_bytes_sent variable.
Piotr Sikora <piotrsikora@google.com>
parents:
6952
diff
changeset
|
1864 stream->request->header_size += NGX_HTTP_V2_FRAME_HEADER_SIZE |
663e6a48bfcb
HTTP/2: fix $body_bytes_sent variable.
Piotr Sikora <piotrsikora@google.com>
parents:
6952
diff
changeset
|
1865 + frame->length; |
663e6a48bfcb
HTTP/2: fix $body_bytes_sent variable.
Piotr Sikora <piotrsikora@google.com>
parents:
6952
diff
changeset
|
1866 |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1867 ngx_http_v2_handle_frame(stream, frame); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1868 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1869 ngx_http_v2_handle_stream(h2c, stream); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1870 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1871 return NGX_OK; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1872 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1873 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1874 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1875 static ngx_int_t |
7201 | 1876 ngx_http_v2_push_frame_handler(ngx_http_v2_connection_t *h2c, |
1877 ngx_http_v2_out_frame_t *frame) | |
1878 { | |
1879 ngx_chain_t *cl, *ln; | |
1880 ngx_http_v2_stream_t *stream; | |
1881 | |
1882 stream = frame->stream; | |
1883 cl = frame->first; | |
1884 | |
1885 for ( ;; ) { | |
1886 if (cl->buf->pos != cl->buf->last) { | |
1887 frame->first = cl; | |
1888 | |
1889 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, | |
1890 "http2:%ui PUSH_PROMISE frame %p was sent partially", | |
1891 stream->node->id, frame); | |
1892 | |
1893 return NGX_AGAIN; | |
1894 } | |
1895 | |
1896 ln = cl->next; | |
1897 | |
1898 if (cl->buf->tag == (ngx_buf_tag_t) &ngx_http_v2_module) { | |
1899 cl->next = stream->free_frame_headers; | |
1900 stream->free_frame_headers = cl; | |
1901 | |
1902 } else { | |
1903 cl->next = stream->free_bufs; | |
1904 stream->free_bufs = cl; | |
1905 } | |
1906 | |
1907 if (cl == frame->last) { | |
1908 break; | |
1909 } | |
1910 | |
1911 cl = ln; | |
1912 } | |
1913 | |
1914 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, | |
1915 "http2:%ui PUSH_PROMISE frame %p was sent", | |
1916 stream->node->id, frame); | |
1917 | |
1918 stream->request->header_size += NGX_HTTP_V2_FRAME_HEADER_SIZE | |
1919 + frame->length; | |
1920 | |
1921 ngx_http_v2_handle_frame(stream, frame); | |
1922 | |
1923 ngx_http_v2_handle_stream(h2c, stream); | |
1924 | |
1925 return NGX_OK; | |
1926 } | |
1927 | |
1928 | |
1929 static ngx_int_t | |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1930 ngx_http_v2_data_frame_handler(ngx_http_v2_connection_t *h2c, |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1931 ngx_http_v2_out_frame_t *frame) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1932 { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1933 ngx_buf_t *buf; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1934 ngx_chain_t *cl, *ln; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1935 ngx_http_v2_stream_t *stream; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1936 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1937 stream = frame->stream; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1938 cl = frame->first; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1939 |
6293
ec6b07be88a5
HTTP/2: reused HEADERS and CONTINUATION frames buffers.
Valentin Bartenev <vbart@nginx.com>
parents:
6292
diff
changeset
|
1940 if (cl->buf->tag == (ngx_buf_tag_t) &ngx_http_v2_module) { |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1941 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1942 if (cl->buf->pos != cl->buf->last) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1943 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1944 "http2:%ui DATA frame %p was sent partially", |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1945 stream->node->id, frame); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1946 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1947 return NGX_AGAIN; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1948 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1949 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1950 ln = cl->next; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1951 |
6293
ec6b07be88a5
HTTP/2: reused HEADERS and CONTINUATION frames buffers.
Valentin Bartenev <vbart@nginx.com>
parents:
6292
diff
changeset
|
1952 cl->next = stream->free_frame_headers; |
ec6b07be88a5
HTTP/2: reused HEADERS and CONTINUATION frames buffers.
Valentin Bartenev <vbart@nginx.com>
parents:
6292
diff
changeset
|
1953 stream->free_frame_headers = cl; |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1954 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1955 if (cl == frame->last) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1956 goto done; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1957 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1958 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1959 cl = ln; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1960 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1961 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1962 for ( ;; ) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1963 if (cl->buf->tag == (ngx_buf_tag_t) &ngx_http_v2_filter_get_shadow) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1964 buf = cl->buf->shadow; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1965 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1966 if (ngx_buf_in_memory(buf)) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1967 buf->pos = cl->buf->pos; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1968 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1969 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1970 if (buf->in_file) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1971 buf->file_pos = cl->buf->file_pos; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1972 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1973 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1974 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1975 if (ngx_buf_size(cl->buf) != 0) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1976 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1977 if (cl != frame->first) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1978 frame->first = cl; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1979 ngx_http_v2_handle_stream(h2c, stream); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1980 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1981 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1982 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1983 "http2:%ui DATA frame %p was sent partially", |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1984 stream->node->id, frame); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1985 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1986 return NGX_AGAIN; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1987 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1988 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1989 ln = cl->next; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1990 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1991 if (cl->buf->tag == (ngx_buf_tag_t) &ngx_http_v2_filter_get_shadow) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1992 cl->next = stream->free_bufs; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1993 stream->free_bufs = cl; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1994 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1995 } else { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1996 ngx_free_chain(stream->request->pool, cl); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1997 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1998 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1999 if (cl == frame->last) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2000 goto done; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2001 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2002 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2003 cl = ln; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2004 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2005 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2006 done: |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2007 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2008 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2009 "http2:%ui DATA frame %p was sent", |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2010 stream->node->id, frame); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2011 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2012 stream->request->header_size += NGX_HTTP_V2_FRAME_HEADER_SIZE; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2013 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2014 ngx_http_v2_handle_frame(stream, frame); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2015 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2016 ngx_http_v2_handle_stream(h2c, stream); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2017 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2018 return NGX_OK; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2019 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2020 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2021 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2022 static ngx_inline void |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2023 ngx_http_v2_handle_frame(ngx_http_v2_stream_t *stream, |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2024 ngx_http_v2_out_frame_t *frame) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2025 { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2026 ngx_http_request_t *r; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2027 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2028 r = stream->request; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2029 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2030 r->connection->sent += NGX_HTTP_V2_FRAME_HEADER_SIZE + frame->length; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2031 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2032 if (frame->fin) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2033 stream->out_closed = 1; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2034 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2035 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2036 frame->next = stream->free_frames; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2037 stream->free_frames = frame; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2038 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2039 stream->queued--; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2040 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2041 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2042 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2043 static ngx_inline void |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2044 ngx_http_v2_handle_stream(ngx_http_v2_connection_t *h2c, |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2045 ngx_http_v2_stream_t *stream) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2046 { |
6833
3834951e32ab
HTTP/2: fixed posted streams handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6792
diff
changeset
|
2047 ngx_event_t *wev; |
6638
a2b310a8b2af
HTTP/2: always handle streams in error state.
Valentin Bartenev <vbart@nginx.com>
parents:
6637
diff
changeset
|
2048 ngx_connection_t *fc; |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2049 |
6833
3834951e32ab
HTTP/2: fixed posted streams handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6792
diff
changeset
|
2050 if (stream->waiting || stream->blocked) { |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2051 return; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2052 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2053 |
6638
a2b310a8b2af
HTTP/2: always handle streams in error state.
Valentin Bartenev <vbart@nginx.com>
parents:
6637
diff
changeset
|
2054 fc = stream->request->connection; |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2055 |
6833
3834951e32ab
HTTP/2: fixed posted streams handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6792
diff
changeset
|
2056 if (!fc->error && stream->exhausted) { |
6638
a2b310a8b2af
HTTP/2: always handle streams in error state.
Valentin Bartenev <vbart@nginx.com>
parents:
6637
diff
changeset
|
2057 return; |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2058 } |
6638
a2b310a8b2af
HTTP/2: always handle streams in error state.
Valentin Bartenev <vbart@nginx.com>
parents:
6637
diff
changeset
|
2059 |
6833
3834951e32ab
HTTP/2: fixed posted streams handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6792
diff
changeset
|
2060 wev = fc->write; |
3834951e32ab
HTTP/2: fixed posted streams handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6792
diff
changeset
|
2061 |
3834951e32ab
HTTP/2: fixed posted streams handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6792
diff
changeset
|
2062 wev->active = 0; |
3834951e32ab
HTTP/2: fixed posted streams handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6792
diff
changeset
|
2063 wev->ready = 1; |
3834951e32ab
HTTP/2: fixed posted streams handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6792
diff
changeset
|
2064 |
3834951e32ab
HTTP/2: fixed posted streams handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6792
diff
changeset
|
2065 if (!fc->error && wev->delayed) { |
3834951e32ab
HTTP/2: fixed posted streams handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6792
diff
changeset
|
2066 return; |
3834951e32ab
HTTP/2: fixed posted streams handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6792
diff
changeset
|
2067 } |
3834951e32ab
HTTP/2: fixed posted streams handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6792
diff
changeset
|
2068 |
3834951e32ab
HTTP/2: fixed posted streams handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6792
diff
changeset
|
2069 ngx_post_event(wev, &ngx_posted_events); |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2070 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2071 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2072 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2073 static void |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2074 ngx_http_v2_filter_cleanup(void *data) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2075 { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2076 ngx_http_v2_stream_t *stream = data; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2077 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2078 size_t window; |
6833
3834951e32ab
HTTP/2: fixed posted streams handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6792
diff
changeset
|
2079 ngx_event_t *wev; |
3834951e32ab
HTTP/2: fixed posted streams handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6792
diff
changeset
|
2080 ngx_queue_t *q; |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2081 ngx_http_v2_out_frame_t *frame, **fn; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2082 ngx_http_v2_connection_t *h2c; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2083 |
6833
3834951e32ab
HTTP/2: fixed posted streams handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6792
diff
changeset
|
2084 if (stream->waiting) { |
3834951e32ab
HTTP/2: fixed posted streams handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6792
diff
changeset
|
2085 stream->waiting = 0; |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2086 ngx_queue_remove(&stream->queue); |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2087 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2088 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2089 if (stream->queued == 0) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2090 return; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2091 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2092 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2093 window = 0; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2094 h2c = stream->connection; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2095 fn = &h2c->last_out; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2096 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2097 for ( ;; ) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2098 frame = *fn; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2099 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2100 if (frame == NULL) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2101 break; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2102 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2103 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2104 if (frame->stream == stream && !frame->blocked) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2105 *fn = frame->next; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2106 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2107 window += frame->length; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2108 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2109 if (--stream->queued == 0) { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2110 break; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2111 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2112 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2113 continue; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2114 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2115 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2116 fn = &frame->next; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2117 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2118 |
6833
3834951e32ab
HTTP/2: fixed posted streams handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6792
diff
changeset
|
2119 if (h2c->send_window == 0 && window) { |
3834951e32ab
HTTP/2: fixed posted streams handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6792
diff
changeset
|
2120 |
3834951e32ab
HTTP/2: fixed posted streams handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6792
diff
changeset
|
2121 while (!ngx_queue_empty(&h2c->waiting)) { |
3834951e32ab
HTTP/2: fixed posted streams handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6792
diff
changeset
|
2122 q = ngx_queue_head(&h2c->waiting); |
3834951e32ab
HTTP/2: fixed posted streams handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6792
diff
changeset
|
2123 |
3834951e32ab
HTTP/2: fixed posted streams handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6792
diff
changeset
|
2124 ngx_queue_remove(q); |
3834951e32ab
HTTP/2: fixed posted streams handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6792
diff
changeset
|
2125 |
3834951e32ab
HTTP/2: fixed posted streams handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6792
diff
changeset
|
2126 stream = ngx_queue_data(q, ngx_http_v2_stream_t, queue); |
3834951e32ab
HTTP/2: fixed posted streams handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6792
diff
changeset
|
2127 |
3834951e32ab
HTTP/2: fixed posted streams handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6792
diff
changeset
|
2128 stream->waiting = 0; |
3834951e32ab
HTTP/2: fixed posted streams handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6792
diff
changeset
|
2129 |
3834951e32ab
HTTP/2: fixed posted streams handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6792
diff
changeset
|
2130 wev = stream->request->connection->write; |
3834951e32ab
HTTP/2: fixed posted streams handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6792
diff
changeset
|
2131 |
3834951e32ab
HTTP/2: fixed posted streams handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6792
diff
changeset
|
2132 wev->active = 0; |
3834951e32ab
HTTP/2: fixed posted streams handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6792
diff
changeset
|
2133 wev->ready = 1; |
3834951e32ab
HTTP/2: fixed posted streams handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6792
diff
changeset
|
2134 |
3834951e32ab
HTTP/2: fixed posted streams handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6792
diff
changeset
|
2135 if (!wev->delayed) { |
3834951e32ab
HTTP/2: fixed posted streams handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6792
diff
changeset
|
2136 ngx_post_event(wev, &ngx_posted_events); |
3834951e32ab
HTTP/2: fixed posted streams handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6792
diff
changeset
|
2137 } |
3834951e32ab
HTTP/2: fixed posted streams handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6792
diff
changeset
|
2138 } |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2139 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2140 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2141 h2c->send_window += window; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2142 } |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2143 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2144 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2145 static ngx_int_t |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2146 ngx_http_v2_filter_init(ngx_conf_t *cf) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2147 { |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2148 ngx_http_next_header_filter = ngx_http_top_header_filter; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2149 ngx_http_top_header_filter = ngx_http_v2_header_filter; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2150 |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2151 return NGX_OK; |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2152 } |