50
|
1
|
|
2 /*
|
|
3 * Copyright (C) Igor Sysoev
|
|
4 */
|
|
5
|
|
6
|
|
7 #include <ngx_config.h>
|
|
8 #include <ngx_core.h>
|
|
9 #include <ngx_http.h>
|
|
10 #include <nginx.h>
|
|
11
|
|
12
|
230
|
13 static ngx_int_t ngx_http_header_filter_init(ngx_conf_t *cf);
|
50
|
14 static ngx_int_t ngx_http_header_filter(ngx_http_request_t *r);
|
|
15
|
|
16
|
|
17 static ngx_http_module_t ngx_http_header_filter_module_ctx = {
|
58
|
18 NULL, /* preconfiguration */
|
230
|
19 ngx_http_header_filter_init, /* postconfiguration */
|
50
|
20
|
|
21 NULL, /* create main configuration */
|
|
22 NULL, /* init main configuration */
|
|
23
|
|
24 NULL, /* create server configuration */
|
|
25 NULL, /* merge server configuration */
|
|
26
|
|
27 NULL, /* create location configuration */
|
|
28 NULL, /* merge location configuration */
|
|
29 };
|
|
30
|
|
31
|
|
32 ngx_module_t ngx_http_header_filter_module = {
|
58
|
33 NGX_MODULE_V1,
|
50
|
34 &ngx_http_header_filter_module_ctx, /* module context */
|
|
35 NULL, /* module directives */
|
|
36 NGX_HTTP_MODULE, /* module type */
|
90
|
37 NULL, /* init master */
|
230
|
38 NULL, /* init module */
|
90
|
39 NULL, /* init process */
|
|
40 NULL, /* init thread */
|
|
41 NULL, /* exit thread */
|
|
42 NULL, /* exit process */
|
|
43 NULL, /* exit master */
|
|
44 NGX_MODULE_V1_PADDING
|
50
|
45 };
|
|
46
|
|
47
|
342
|
48 static char ngx_http_server_string[] = "Server: nginx" CRLF;
|
|
49 static char ngx_http_server_full_string[] = "Server: " NGINX_VER CRLF;
|
50
|
50
|
|
51
|
58
|
52 static ngx_str_t ngx_http_status_lines[] = {
|
50
|
53
|
|
54 ngx_string("200 OK"),
|
182
|
55 ngx_string("201 Created"),
|
50
|
56 ngx_null_string, /* "202 Accepted" */
|
|
57 ngx_null_string, /* "203 Non-Authoritative Information" */
|
60
|
58 ngx_string("204 No Content"),
|
50
|
59 ngx_null_string, /* "205 Reset Content" */
|
|
60 ngx_string("206 Partial Content"),
|
|
61
|
|
62 /* ngx_null_string, */ /* "207 Multi-Status" */
|
|
63
|
|
64 #define NGX_HTTP_LEVEL_200 7
|
|
65
|
|
66 /* ngx_null_string, */ /* "300 Multiple Choices" */
|
|
67
|
|
68 ngx_string("301 Moved Permanently"),
|
|
69 ngx_string("302 Moved Temporarily"),
|
|
70 ngx_null_string, /* "303 See Other" */
|
|
71 ngx_string("304 Not Modified"),
|
|
72
|
|
73 /* ngx_null_string, */ /* "305 Use Proxy" */
|
|
74 /* ngx_null_string, */ /* "306 unused" */
|
|
75 /* ngx_null_string, */ /* "307 Temporary Redirect" */
|
|
76
|
|
77 #define NGX_HTTP_LEVEL_300 4
|
|
78
|
|
79 ngx_string("400 Bad Request"),
|
|
80 ngx_string("401 Unauthorized"),
|
|
81 ngx_string("402 Payment Required"),
|
|
82 ngx_string("403 Forbidden"),
|
|
83 ngx_string("404 Not Found"),
|
|
84 ngx_string("405 Not Allowed"),
|
|
85 ngx_string("406 Not Acceptable"),
|
|
86 ngx_null_string, /* "407 Proxy Authentication Required" */
|
|
87 ngx_string("408 Request Time-out"),
|
212
|
88 ngx_string("409 Conflict"),
|
50
|
89 ngx_string("410 Gone"),
|
|
90 ngx_string("411 Length Required"),
|
276
|
91 ngx_string("412 Precondition Failed"),
|
50
|
92 ngx_string("413 Request Entity Too Large"),
|
|
93 ngx_null_string, /* "414 Request-URI Too Large", but we never send it
|
|
94 * because we treat such requests as the HTTP/0.9
|
|
95 * requests and send only a body without a header
|
|
96 */
|
186
|
97 ngx_string("415 Unsupported Media Type"),
|
50
|
98 ngx_string("416 Requested Range Not Satisfiable"),
|
|
99
|
|
100 /* ngx_null_string, */ /* "417 Expectation Failed" */
|
|
101 /* ngx_null_string, */ /* "418 unused" */
|
|
102 /* ngx_null_string, */ /* "419 unused" */
|
|
103 /* ngx_null_string, */ /* "420 unused" */
|
|
104 /* ngx_null_string, */ /* "421 unused" */
|
|
105 /* ngx_null_string, */ /* "422 Unprocessable Entity" */
|
|
106 /* ngx_null_string, */ /* "423 Locked" */
|
|
107 /* ngx_null_string, */ /* "424 Failed Dependency" */
|
|
108
|
|
109 #define NGX_HTTP_LEVEL_400 17
|
|
110
|
|
111 ngx_string("500 Internal Server Error"),
|
|
112 ngx_string("501 Method Not Implemented"),
|
|
113 ngx_string("502 Bad Gateway"),
|
|
114 ngx_string("503 Service Temporarily Unavailable"),
|
186
|
115 ngx_string("504 Gateway Time-out"),
|
50
|
116
|
186
|
117 ngx_null_string, /* "505 HTTP Version Not Supported" */
|
|
118 ngx_null_string, /* "506 Variant Also Negotiates" */
|
|
119 ngx_string("507 Insufficient Storage"),
|
50
|
120 /* ngx_null_string, */ /* "508 unused" */
|
|
121 /* ngx_null_string, */ /* "509 unused" */
|
|
122 /* ngx_null_string, */ /* "510 Not Extended" */
|
|
123 };
|
|
124
|
|
125
|
118
|
126 ngx_http_header_out_t ngx_http_headers_out[] = {
|
50
|
127 { ngx_string("Server"), offsetof(ngx_http_headers_out_t, server) },
|
|
128 { ngx_string("Date"), offsetof(ngx_http_headers_out_t, date) },
|
58
|
129 #if 0
|
50
|
130 { ngx_string("Content-Type"),
|
|
131 offsetof(ngx_http_headers_out_t, content_type) },
|
58
|
132 #endif
|
50
|
133 { ngx_string("Content-Length"),
|
|
134 offsetof(ngx_http_headers_out_t, content_length) },
|
|
135 { ngx_string("Content-Encoding"),
|
|
136 offsetof(ngx_http_headers_out_t, content_encoding) },
|
|
137 { ngx_string("Location"), offsetof(ngx_http_headers_out_t, location) },
|
|
138 { ngx_string("Last-Modified"),
|
|
139 offsetof(ngx_http_headers_out_t, last_modified) },
|
|
140 { ngx_string("Accept-Ranges"),
|
|
141 offsetof(ngx_http_headers_out_t, accept_ranges) },
|
|
142 { ngx_string("Expires"), offsetof(ngx_http_headers_out_t, expires) },
|
|
143 { ngx_string("Cache-Control"),
|
|
144 offsetof(ngx_http_headers_out_t, cache_control) },
|
|
145 { ngx_string("ETag"), offsetof(ngx_http_headers_out_t, etag) },
|
|
146
|
|
147 { ngx_null_string, 0 }
|
|
148 };
|
|
149
|
|
150
|
|
151 static ngx_int_t
|
|
152 ngx_http_header_filter(ngx_http_request_t *r)
|
|
153 {
|
|
154 u_char *p;
|
|
155 size_t len;
|
362
|
156 ngx_str_t host;
|
230
|
157 ngx_buf_t *b;
|
50
|
158 ngx_uint_t status, i;
|
|
159 ngx_chain_t out;
|
|
160 ngx_list_part_t *part;
|
|
161 ngx_table_elt_t *header;
|
|
162 ngx_http_core_loc_conf_t *clcf;
|
362
|
163 ngx_http_core_srv_conf_t *cscf;
|
|
164 /* AF_INET only */
|
|
165 u_char addr[INET_ADDRSTRLEN];
|
50
|
166
|
216
|
167 r->header_sent = 1;
|
|
168
|
146
|
169 if (r != r->main) {
|
58
|
170 return NGX_OK;
|
|
171 }
|
|
172
|
50
|
173 if (r->http_version < NGX_HTTP_VERSION_10) {
|
|
174 return NGX_OK;
|
|
175 }
|
|
176
|
|
177 if (r->method == NGX_HTTP_HEAD) {
|
|
178 r->header_only = 1;
|
|
179 }
|
|
180
|
|
181 if (r->headers_out.last_modified_time != -1) {
|
|
182 if (r->headers_out.status != NGX_HTTP_OK
|
60
|
183 && r->headers_out.status != NGX_HTTP_PARTIAL_CONTENT
|
|
184 && r->headers_out.status != NGX_HTTP_NOT_MODIFIED)
|
50
|
185 {
|
|
186 r->headers_out.last_modified_time = -1;
|
|
187 r->headers_out.last_modified = NULL;
|
|
188 }
|
|
189 }
|
|
190
|
|
191 len = sizeof("HTTP/1.x ") - 1 + sizeof(CRLF) - 1
|
|
192 /* the end of the header */
|
|
193 + sizeof(CRLF) - 1;
|
|
194
|
|
195 /* status line */
|
|
196
|
|
197 if (r->headers_out.status_line.len) {
|
|
198 len += r->headers_out.status_line.len;
|
|
199 #if (NGX_SUPPRESS_WARN)
|
|
200 status = NGX_INVALID_ARRAY_INDEX;
|
|
201 #endif
|
|
202
|
|
203 } else {
|
|
204
|
|
205 if (r->headers_out.status < NGX_HTTP_MOVED_PERMANENTLY) {
|
|
206 /* 2XX */
|
|
207 status = r->headers_out.status - NGX_HTTP_OK;
|
|
208
|
60
|
209 if (r->headers_out.status == NGX_HTTP_NO_CONTENT) {
|
|
210 r->header_only = 1;
|
|
211 r->headers_out.content_type.len = 0;
|
|
212 r->headers_out.content_type.data = NULL;
|
|
213 r->headers_out.last_modified_time = -1;
|
|
214 r->headers_out.last_modified = NULL;
|
|
215 r->headers_out.content_length = NULL;
|
|
216 r->headers_out.content_length_n = -1;
|
|
217 }
|
|
218
|
50
|
219 } else if (r->headers_out.status < NGX_HTTP_BAD_REQUEST) {
|
|
220 /* 3XX */
|
|
221 status = r->headers_out.status - NGX_HTTP_MOVED_PERMANENTLY
|
|
222 + NGX_HTTP_LEVEL_200;
|
|
223
|
|
224 if (r->headers_out.status == NGX_HTTP_NOT_MODIFIED) {
|
|
225 r->header_only = 1;
|
|
226 }
|
|
227
|
|
228 } else if (r->headers_out.status < NGX_HTTP_INTERNAL_SERVER_ERROR) {
|
|
229 /* 4XX */
|
|
230 status = r->headers_out.status - NGX_HTTP_BAD_REQUEST
|
|
231 + NGX_HTTP_LEVEL_200
|
|
232 + NGX_HTTP_LEVEL_300;
|
|
233
|
|
234 } else {
|
|
235 /* 5XX */
|
|
236 status = r->headers_out.status - NGX_HTTP_INTERNAL_SERVER_ERROR
|
|
237 + NGX_HTTP_LEVEL_200
|
|
238 + NGX_HTTP_LEVEL_300
|
|
239 + NGX_HTTP_LEVEL_400;
|
|
240 }
|
|
241
|
58
|
242 len += ngx_http_status_lines[status].len;
|
50
|
243 }
|
|
244
|
342
|
245 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
246
|
58
|
247 if (r->headers_out.server == NULL) {
|
342
|
248 len += clcf->server_tokens ? sizeof(ngx_http_server_full_string) - 1:
|
|
249 sizeof(ngx_http_server_string) - 1;
|
50
|
250 }
|
|
251
|
58
|
252 if (r->headers_out.date == NULL) {
|
50
|
253 len += sizeof("Date: Mon, 28 Sep 1970 06:00:00 GMT" CRLF) - 1;
|
|
254 }
|
|
255
|
58
|
256 if (r->headers_out.content_type.len) {
|
50
|
257 len += sizeof("Content-Type: ") - 1
|
58
|
258 + r->headers_out.content_type.len + 2;
|
50
|
259
|
206
|
260 if (r->headers_out.content_type_len == r->headers_out.content_type.len
|
|
261 && r->headers_out.charset.len)
|
|
262 {
|
50
|
263 len += sizeof("; charset=") - 1 + r->headers_out.charset.len;
|
|
264 }
|
|
265 }
|
|
266
|
58
|
267 if (r->headers_out.content_length == NULL
|
|
268 && r->headers_out.content_length_n >= 0)
|
|
269 {
|
|
270 len += sizeof("Content-Length: ") - 1 + NGX_OFF_T_LEN + 2;
|
|
271 }
|
|
272
|
|
273 if (r->headers_out.last_modified == NULL
|
|
274 && r->headers_out.last_modified_time != -1)
|
|
275 {
|
|
276 len += sizeof("Last-Modified: Mon, 28 Sep 1970 06:00:00 GMT" CRLF) - 1;
|
|
277 }
|
|
278
|
50
|
279 if (r->headers_out.location
|
|
280 && r->headers_out.location->value.len
|
|
281 && r->headers_out.location->value.data[0] == '/')
|
|
282 {
|
58
|
283 r->headers_out.location->hash = 0;
|
|
284
|
362
|
285 if (clcf->server_name_in_redirect) {
|
|
286 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
|
|
287 host = cscf->server_name;
|
|
288
|
376
|
289 } else if (r->headers_in.server.len) {
|
|
290 host = r->headers_in.server;
|
362
|
291
|
|
292 } else {
|
|
293 host.data = addr;
|
|
294
|
|
295 if (ngx_http_server_addr(r, &host) != NGX_OK) {
|
|
296 return NGX_ERROR;
|
|
297 }
|
|
298 }
|
|
299
|
66
|
300 #if (NGX_HTTP_SSL)
|
|
301 if (r->connection->ssl) {
|
|
302 len += sizeof("Location: https://") - 1
|
362
|
303 + host.len
|
66
|
304 + r->headers_out.location->value.len + 2;
|
|
305
|
70
|
306 if (clcf->port_in_redirect && r->port != 443) {
|
66
|
307 len += r->port_text->len;
|
|
308 }
|
50
|
309
|
66
|
310 } else
|
|
311 #endif
|
|
312 {
|
|
313 len += sizeof("Location: http://") - 1
|
362
|
314 + host.len
|
66
|
315 + r->headers_out.location->value.len + 2;
|
|
316
|
70
|
317 if (clcf->port_in_redirect && r->port != 80) {
|
66
|
318 len += r->port_text->len;
|
|
319 }
|
50
|
320 }
|
362
|
321
|
|
322 } else {
|
|
323 host.len = 0;
|
|
324 host.data = NULL;
|
50
|
325 }
|
|
326
|
|
327 if (r->chunked) {
|
|
328 len += sizeof("Transfer-Encoding: chunked" CRLF) - 1;
|
|
329 }
|
|
330
|
|
331 if (r->keepalive) {
|
|
332 len += sizeof("Connection: keep-alive" CRLF) - 1;
|
|
333
|
|
334 /*
|
|
335 * MSIE and Opera ignore the "Keep-Alive: timeout=<N>" header.
|
|
336 * MSIE keeps the connection alive for about 60-65 seconds.
|
|
337 * Opera keeps the connection alive very long.
|
|
338 * Mozilla keeps the connection alive for N plus about 1-10 seconds.
|
|
339 * Konqueror keeps the connection alive for about N seconds.
|
|
340 */
|
|
341
|
|
342 if (clcf->keepalive_header) {
|
|
343 len += sizeof("Keep-Alive: timeout=") - 1 + NGX_TIME_T_LEN + 2;
|
|
344 }
|
|
345
|
|
346 } else {
|
|
347 len += sizeof("Connection: closed" CRLF) - 1;
|
|
348 }
|
|
349
|
382
|
350 if (r->gzip && clcf->gzip_vary) {
|
|
351 len += sizeof("Vary: Accept-Encoding" CRLF) - 1;
|
|
352 }
|
|
353
|
50
|
354 part = &r->headers_out.headers.part;
|
|
355 header = part->elts;
|
|
356
|
|
357 for (i = 0; /* void */; i++) {
|
|
358
|
|
359 if (i >= part->nelts) {
|
|
360 if (part->next == NULL) {
|
|
361 break;
|
|
362 }
|
|
363
|
|
364 part = part->next;
|
|
365 header = part->elts;
|
|
366 i = 0;
|
|
367 }
|
|
368
|
58
|
369 if (header[i].hash == 0) {
|
50
|
370 continue;
|
|
371 }
|
|
372
|
|
373 len += header[i].key.len + sizeof(": ") - 1 + header[i].value.len
|
|
374 + sizeof(CRLF) - 1;
|
|
375 }
|
|
376
|
|
377 b = ngx_create_temp_buf(r->pool, len);
|
|
378 if (b == NULL) {
|
|
379 return NGX_ERROR;
|
|
380 }
|
|
381
|
|
382 /* "HTTP/1.x " */
|
|
383 b->last = ngx_cpymem(b->last, "HTTP/1.1 ", sizeof("HTTP/1.x ") - 1);
|
|
384
|
|
385 /* status line */
|
|
386 if (r->headers_out.status_line.len) {
|
122
|
387 b->last = ngx_copy(b->last, r->headers_out.status_line.data,
|
|
388 r->headers_out.status_line.len);
|
50
|
389
|
|
390 } else {
|
122
|
391 b->last = ngx_copy(b->last, ngx_http_status_lines[status].data,
|
|
392 ngx_http_status_lines[status].len);
|
50
|
393 }
|
|
394 *b->last++ = CR; *b->last++ = LF;
|
|
395
|
58
|
396 if (r->headers_out.server == NULL) {
|
342
|
397 if (clcf->server_tokens) {
|
|
398 p = (u_char *) ngx_http_server_full_string;
|
|
399 len = sizeof(ngx_http_server_full_string) - 1;
|
|
400
|
|
401 } else {
|
|
402 p = (u_char *) ngx_http_server_string;
|
|
403 len = sizeof(ngx_http_server_string) - 1;
|
|
404 }
|
|
405
|
|
406 b->last = ngx_cpymem(b->last, p, len);
|
50
|
407 }
|
|
408
|
58
|
409 if (r->headers_out.date == NULL) {
|
50
|
410 b->last = ngx_cpymem(b->last, "Date: ", sizeof("Date: ") - 1);
|
|
411 b->last = ngx_cpymem(b->last, ngx_cached_http_time.data,
|
|
412 ngx_cached_http_time.len);
|
|
413
|
|
414 *b->last++ = CR; *b->last++ = LF;
|
|
415 }
|
|
416
|
58
|
417 if (r->headers_out.content_type.len) {
|
50
|
418 b->last = ngx_cpymem(b->last, "Content-Type: ",
|
|
419 sizeof("Content-Type: ") - 1);
|
|
420 p = b->last;
|
122
|
421 b->last = ngx_copy(b->last, r->headers_out.content_type.data,
|
|
422 r->headers_out.content_type.len);
|
50
|
423
|
206
|
424 if (r->headers_out.content_type_len == r->headers_out.content_type.len
|
|
425 && r->headers_out.charset.len)
|
|
426 {
|
50
|
427 b->last = ngx_cpymem(b->last, "; charset=",
|
|
428 sizeof("; charset=") - 1);
|
122
|
429 b->last = ngx_copy(b->last, r->headers_out.charset.data,
|
|
430 r->headers_out.charset.len);
|
50
|
431
|
58
|
432 /* update r->headers_out.content_type for possible logging */
|
|
433
|
|
434 r->headers_out.content_type.len = b->last - p;
|
|
435 r->headers_out.content_type.data = p;
|
50
|
436 }
|
|
437
|
|
438 *b->last++ = CR; *b->last++ = LF;
|
|
439 }
|
|
440
|
58
|
441 if (r->headers_out.content_length == NULL
|
|
442 && r->headers_out.content_length_n >= 0)
|
|
443 {
|
|
444 b->last = ngx_sprintf(b->last, "Content-Length: %O" CRLF,
|
|
445 r->headers_out.content_length_n);
|
|
446 }
|
|
447
|
|
448 if (r->headers_out.last_modified == NULL
|
|
449 && r->headers_out.last_modified_time != -1)
|
|
450 {
|
|
451 b->last = ngx_cpymem(b->last, "Last-Modified: ",
|
|
452 sizeof("Last-Modified: ") - 1);
|
|
453 b->last = ngx_http_time(b->last, r->headers_out.last_modified_time);
|
|
454
|
|
455 *b->last++ = CR; *b->last++ = LF;
|
|
456 }
|
|
457
|
362
|
458 if (host.data) {
|
|
459
|
50
|
460 p = b->last + sizeof("Location: ") - 1;
|
66
|
461
|
|
462 b->last = ngx_cpymem(b->last, "Location: http",
|
|
463 sizeof("Location: http") - 1);
|
|
464
|
|
465 #if (NGX_HTTP_SSL)
|
|
466 if (r->connection->ssl) {
|
|
467 *b->last++ ='s';
|
|
468 }
|
|
469 #endif
|
|
470
|
|
471 *b->last++ = ':'; *b->last++ = '/'; *b->last++ = '/';
|
362
|
472 b->last = ngx_copy(b->last, host.data, host.len);
|
66
|
473
|
70
|
474 if (clcf->port_in_redirect) {
|
66
|
475 #if (NGX_HTTP_SSL)
|
70
|
476 if (r->connection->ssl) {
|
|
477 if (r->port != 443) {
|
122
|
478 b->last = ngx_copy(b->last, r->port_text->data,
|
|
479 r->port_text->len);
|
70
|
480 }
|
|
481 } else
|
66
|
482 #endif
|
70
|
483 {
|
|
484 if (r->port != 80) {
|
122
|
485 b->last = ngx_copy(b->last, r->port_text->data,
|
|
486 r->port_text->len);
|
70
|
487 }
|
66
|
488 }
|
50
|
489 }
|
|
490
|
122
|
491 b->last = ngx_copy(b->last, r->headers_out.location->value.data,
|
|
492 r->headers_out.location->value.len);
|
50
|
493
|
58
|
494 /* update r->headers_out.location->value for possible logging */
|
|
495
|
50
|
496 r->headers_out.location->value.len = b->last - p;
|
|
497 r->headers_out.location->value.data = p;
|
218
|
498 r->headers_out.location->key.len = sizeof("Location: ") - 1;
|
|
499 r->headers_out.location->key.data = (u_char *) "Location: ";
|
50
|
500
|
|
501 *b->last++ = CR; *b->last++ = LF;
|
|
502 }
|
|
503
|
|
504 if (r->chunked) {
|
|
505 b->last = ngx_cpymem(b->last, "Transfer-Encoding: chunked" CRLF,
|
|
506 sizeof("Transfer-Encoding: chunked" CRLF) - 1);
|
|
507 }
|
|
508
|
|
509 if (r->keepalive) {
|
|
510 b->last = ngx_cpymem(b->last, "Connection: keep-alive" CRLF,
|
|
511 sizeof("Connection: keep-alive" CRLF) - 1);
|
|
512
|
|
513 if (clcf->keepalive_header) {
|
|
514 b->last = ngx_sprintf(b->last, "Keep-Alive: timeout=%T" CRLF,
|
|
515 clcf->keepalive_header);
|
|
516 }
|
|
517
|
|
518 } else {
|
|
519 b->last = ngx_cpymem(b->last, "Connection: close" CRLF,
|
|
520 sizeof("Connection: close" CRLF) - 1);
|
|
521 }
|
|
522
|
382
|
523 if (r->gzip && clcf->gzip_vary) {
|
|
524 b->last = ngx_cpymem(b->last, "Vary: Accept-Encoding" CRLF,
|
|
525 sizeof("Vary: Accept-Encoding" CRLF) - 1);
|
|
526 }
|
|
527
|
50
|
528 part = &r->headers_out.headers.part;
|
|
529 header = part->elts;
|
|
530
|
|
531 for (i = 0; /* void */; i++) {
|
|
532
|
|
533 if (i >= part->nelts) {
|
|
534 if (part->next == NULL) {
|
|
535 break;
|
|
536 }
|
|
537
|
|
538 part = part->next;
|
|
539 header = part->elts;
|
|
540 i = 0;
|
|
541 }
|
|
542
|
58
|
543 if (header[i].hash == 0) {
|
50
|
544 continue;
|
|
545 }
|
|
546
|
122
|
547 b->last = ngx_copy(b->last, header[i].key.data, header[i].key.len);
|
378
|
548 *b->last++ = ':'; *b->last++ = ' ';
|
50
|
549
|
122
|
550 b->last = ngx_copy(b->last, header[i].value.data, header[i].value.len);
|
50
|
551 *b->last++ = CR; *b->last++ = LF;
|
|
552 }
|
|
553
|
358
|
554 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
555 "%*s\n", (size_t) (b->last - b->pos), b->pos);
|
50
|
556
|
|
557 /* the end of HTTP header */
|
|
558 *b->last++ = CR; *b->last++ = LF;
|
|
559
|
|
560 r->header_size = b->last - b->pos;
|
|
561
|
|
562 if (r->header_only) {
|
|
563 b->last_buf = 1;
|
|
564 }
|
|
565
|
|
566 out.buf = b;
|
|
567 out.next = NULL;
|
|
568
|
|
569 return ngx_http_write_filter(r, &out);
|
|
570 }
|
|
571
|
|
572
|
|
573 static ngx_int_t
|
230
|
574 ngx_http_header_filter_init(ngx_conf_t *cf)
|
50
|
575 {
|
|
576 ngx_http_top_header_filter = ngx_http_header_filter;
|
|
577
|
|
578 return NGX_OK;
|
|
579 }
|