Mercurial > hg > ngx_http_gunzip_filter_module
annotate ngx_http_gunzip_filter_module.c @ 7:9158103f8571 0.1
Gunzip: fix tests for repcached and memcached 1.2.7+.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 28 Dec 2009 14:45:12 +0000 |
parents | 0dd7d109e56b |
children | 5c999acd9436 |
rev | line source |
---|---|
0 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4 * Copyright (C) Maxim Dounin | |
5 */ | |
6 | |
7 | |
8 #include <ngx_config.h> | |
9 #include <ngx_core.h> | |
10 #include <ngx_http.h> | |
11 #include <nginx.h> | |
12 | |
13 #include <zlib.h> | |
14 | |
15 | |
16 typedef struct { | |
17 ngx_flag_t enable; | |
18 ngx_bufs_t bufs; | |
19 } ngx_http_gunzip_conf_t; | |
20 | |
21 | |
22 typedef struct { | |
23 ngx_chain_t *in; | |
24 ngx_chain_t *free; | |
25 ngx_chain_t *busy; | |
26 ngx_chain_t *out; | |
27 ngx_chain_t **last_out; | |
28 | |
29 ngx_buf_t *in_buf; | |
30 ngx_buf_t *out_buf; | |
31 ngx_int_t bufs; | |
32 | |
33 unsigned started:1; | |
34 unsigned flush:4; | |
35 unsigned redo:1; | |
36 unsigned done:1; | |
37 unsigned nomem:1; | |
38 | |
39 z_stream zstream; | |
40 ngx_http_request_t *request; | |
41 } ngx_http_gunzip_ctx_t; | |
42 | |
43 | |
44 static ngx_int_t ngx_http_gunzip_filter_inflate_start(ngx_http_request_t *r, | |
45 ngx_http_gunzip_ctx_t *ctx); | |
46 static ngx_int_t ngx_http_gunzip_filter_add_data(ngx_http_request_t *r, | |
47 ngx_http_gunzip_ctx_t *ctx); | |
48 static ngx_int_t ngx_http_gunzip_filter_get_buf(ngx_http_request_t *r, | |
49 ngx_http_gunzip_ctx_t *ctx); | |
50 static ngx_int_t ngx_http_gunzip_filter_inflate(ngx_http_request_t *r, | |
51 ngx_http_gunzip_ctx_t *ctx); | |
52 static ngx_int_t ngx_http_gunzip_filter_inflate_end(ngx_http_request_t *r, | |
53 ngx_http_gunzip_ctx_t *ctx); | |
54 | |
55 static void *ngx_http_gunzip_filter_alloc(void *opaque, u_int items, | |
56 u_int size); | |
57 static void ngx_http_gunzip_filter_free(void *opaque, void *address); | |
58 | |
59 static ngx_int_t ngx_http_gunzip_filter_init(ngx_conf_t *cf); | |
60 static void *ngx_http_gunzip_create_conf(ngx_conf_t *cf); | |
61 static char *ngx_http_gunzip_merge_conf(ngx_conf_t *cf, | |
62 void *parent, void *child); | |
63 | |
64 | |
65 static ngx_command_t ngx_http_gunzip_filter_commands[] = { | |
66 | |
67 { ngx_string("gunzip"), | |
68 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | |
69 ngx_conf_set_flag_slot, | |
70 NGX_HTTP_LOC_CONF_OFFSET, | |
71 offsetof(ngx_http_gunzip_conf_t, enable), | |
72 NULL }, | |
73 | |
74 { ngx_string("gunzip_buffers"), | |
75 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2, | |
76 ngx_conf_set_bufs_slot, | |
77 NGX_HTTP_LOC_CONF_OFFSET, | |
78 offsetof(ngx_http_gunzip_conf_t, bufs), | |
79 NULL }, | |
80 | |
81 ngx_null_command | |
82 }; | |
83 | |
84 | |
85 static ngx_http_module_t ngx_http_gunzip_filter_module_ctx = { | |
86 NULL, /* preconfiguration */ | |
87 ngx_http_gunzip_filter_init, /* postconfiguration */ | |
88 | |
89 NULL, /* create main configuration */ | |
90 NULL, /* init main configuration */ | |
91 | |
92 NULL, /* create server configuration */ | |
93 NULL, /* merge server configuration */ | |
94 | |
95 ngx_http_gunzip_create_conf, /* create location configuration */ | |
96 ngx_http_gunzip_merge_conf /* merge location configuration */ | |
97 }; | |
98 | |
99 | |
100 ngx_module_t ngx_http_gunzip_filter_module = { | |
101 NGX_MODULE_V1, | |
102 &ngx_http_gunzip_filter_module_ctx, /* module context */ | |
103 ngx_http_gunzip_filter_commands, /* module directives */ | |
104 NGX_HTTP_MODULE, /* module type */ | |
105 NULL, /* init master */ | |
106 NULL, /* init module */ | |
107 NULL, /* init process */ | |
108 NULL, /* init thread */ | |
109 NULL, /* exit thread */ | |
110 NULL, /* exit process */ | |
111 NULL, /* exit master */ | |
112 NGX_MODULE_V1_PADDING | |
113 }; | |
114 | |
115 | |
116 static ngx_http_output_header_filter_pt ngx_http_next_header_filter; | |
117 static ngx_http_output_body_filter_pt ngx_http_next_body_filter; | |
118 | |
119 | |
120 static ngx_int_t | |
121 ngx_http_gunzip_header_filter(ngx_http_request_t *r) | |
122 { | |
123 ngx_http_gunzip_ctx_t *ctx; | |
124 ngx_http_gunzip_conf_t *conf; | |
125 | |
126 conf = ngx_http_get_module_loc_conf(r, ngx_http_gunzip_filter_module); | |
127 | |
128 /* TODO support multiple content-codings */ | |
1
0dd7d109e56b
Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
0
diff
changeset
|
129 /* TODO always gunzip - due to configuration or module request */ |
0dd7d109e56b
Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
0
diff
changeset
|
130 /* TODO ignore content encoding? */ |
0 | 131 |
132 if (!conf->enable | |
133 || r->headers_out.content_encoding == NULL | |
134 || r->headers_out.content_encoding->value.len != 4 | |
135 || ngx_strncasecmp(r->headers_out.content_encoding->value.data, | |
136 (u_char *) "gzip", 4) != 0) | |
137 { | |
138 return ngx_http_next_header_filter(r); | |
139 } | |
140 | |
141 #if (nginx_version >= 8025) | |
142 | |
143 r->gzip_vary = 1; | |
144 | |
145 if (!r->gzip_tested) { | |
146 if (ngx_http_gzip_ok(r) == NGX_OK) { | |
147 return ngx_http_next_header_filter(r); | |
148 } | |
149 | |
150 } else if (!r->gzip_ok) { | |
151 return ngx_http_next_header_filter(r); | |
152 } | |
153 | |
154 #else | |
155 | |
156 if (ngx_http_gzip_ok(r) == NGX_OK) { | |
157 return ngx_http_next_header_filter(r); | |
158 } | |
159 | |
160 #endif | |
161 | |
162 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_gunzip_ctx_t)); | |
163 if (ctx == NULL) { | |
164 return NGX_ERROR; | |
165 } | |
166 | |
167 ngx_http_set_ctx(r, ctx, ngx_http_gunzip_filter_module); | |
168 | |
169 ctx->request = r; | |
170 | |
171 r->filter_need_in_memory = 1; | |
172 | |
173 r->headers_out.content_encoding->hash = 0; | |
174 r->headers_out.content_encoding = NULL; | |
175 | |
176 ngx_http_clear_content_length(r); | |
177 ngx_http_clear_accept_ranges(r); | |
178 | |
179 return ngx_http_next_header_filter(r); | |
180 } | |
181 | |
182 | |
183 static ngx_int_t | |
184 ngx_http_gunzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in) | |
185 { | |
186 int rc; | |
187 ngx_chain_t *cl; | |
188 ngx_http_gunzip_ctx_t *ctx; | |
189 | |
190 ctx = ngx_http_get_module_ctx(r, ngx_http_gunzip_filter_module); | |
191 | |
192 if (ctx == NULL || ctx->done) { | |
193 return ngx_http_next_body_filter(r, in); | |
194 } | |
195 | |
196 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
197 "http gunzip filter"); | |
198 | |
199 if (!ctx->started) { | |
200 if (ngx_http_gunzip_filter_inflate_start(r, ctx) != NGX_OK) { | |
201 goto failed; | |
202 } | |
203 } | |
204 | |
205 if (in) { | |
206 if (ngx_chain_add_copy(r->pool, &ctx->in, in) != NGX_OK) { | |
207 goto failed; | |
208 } | |
209 } | |
210 | |
211 if (ctx->nomem) { | |
212 | |
213 /* flush busy buffers */ | |
214 | |
215 if (ngx_http_next_body_filter(r, NULL) == NGX_ERROR) { | |
216 goto failed; | |
217 } | |
218 | |
219 cl = NULL; | |
220 | |
221 ngx_chain_update_chains(&ctx->free, &ctx->busy, &cl, | |
222 (ngx_buf_tag_t) &ngx_http_gunzip_filter_module); | |
223 ctx->nomem = 0; | |
224 } | |
225 | |
226 for ( ;; ) { | |
227 | |
228 /* cycle while we can write to a client */ | |
229 | |
230 for ( ;; ) { | |
231 | |
232 /* cycle while there is data to feed zlib and ... */ | |
233 | |
234 rc = ngx_http_gunzip_filter_add_data(r, ctx); | |
235 | |
236 if (rc == NGX_DECLINED) { | |
237 break; | |
238 } | |
239 | |
240 if (rc == NGX_AGAIN) { | |
241 continue; | |
242 } | |
243 | |
244 | |
245 /* ... there are buffers to write zlib output */ | |
246 | |
247 rc = ngx_http_gunzip_filter_get_buf(r, ctx); | |
248 | |
249 if (rc == NGX_DECLINED) { | |
250 break; | |
251 } | |
252 | |
253 if (rc == NGX_ERROR) { | |
254 goto failed; | |
255 } | |
256 | |
257 rc = ngx_http_gunzip_filter_inflate(r, ctx); | |
258 | |
259 if (rc == NGX_OK) { | |
260 break; | |
261 } | |
262 | |
263 if (rc == NGX_ERROR) { | |
264 goto failed; | |
265 } | |
266 | |
267 /* rc == NGX_AGAIN */ | |
268 } | |
269 | |
270 if (ctx->out == NULL) { | |
271 return ctx->busy ? NGX_AGAIN : NGX_OK; | |
272 } | |
273 | |
274 rc = ngx_http_next_body_filter(r, ctx->out); | |
275 | |
276 if (rc == NGX_ERROR) { | |
277 goto failed; | |
278 } | |
279 | |
280 ngx_chain_update_chains(&ctx->free, &ctx->busy, &ctx->out, | |
281 (ngx_buf_tag_t) &ngx_http_gunzip_filter_module); | |
282 ctx->last_out = &ctx->out; | |
283 | |
284 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
285 "gunzip out: %p", ctx->out); | |
286 | |
287 ctx->nomem = 0; | |
288 | |
289 if (ctx->done) { | |
290 return rc; | |
291 } | |
292 } | |
293 | |
294 /* unreachable */ | |
295 | |
296 failed: | |
297 | |
298 ctx->done = 1; | |
299 | |
300 return NGX_ERROR; | |
301 } | |
302 | |
303 | |
304 static ngx_int_t | |
305 ngx_http_gunzip_filter_inflate_start(ngx_http_request_t *r, | |
306 ngx_http_gunzip_ctx_t *ctx) | |
307 { | |
308 int rc; | |
309 | |
310 ctx->zstream.next_in = Z_NULL; | |
311 ctx->zstream.avail_in = 0; | |
312 | |
313 ctx->zstream.zalloc = ngx_http_gunzip_filter_alloc; | |
314 ctx->zstream.zfree = ngx_http_gunzip_filter_free; | |
315 ctx->zstream.opaque = ctx; | |
316 | |
317 /* windowBits +16 to decode gzip, zlib 1.2.0.4+ */ | |
318 rc = inflateInit2(&ctx->zstream, MAX_WBITS + 16); | |
319 | |
320 if (rc != Z_OK) { | |
321 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, | |
322 "inflateInit2() failed: %d", rc); | |
323 return NGX_ERROR; | |
324 } | |
325 | |
326 ctx->started = 1; | |
327 | |
328 ctx->last_out = &ctx->out; | |
329 ctx->flush = Z_NO_FLUSH; | |
330 | |
331 return NGX_OK; | |
332 } | |
333 | |
334 | |
335 static ngx_int_t | |
336 ngx_http_gunzip_filter_add_data(ngx_http_request_t *r, | |
337 ngx_http_gunzip_ctx_t *ctx) | |
338 { | |
339 if (ctx->zstream.avail_in || ctx->flush != Z_NO_FLUSH || ctx->redo) { | |
340 return NGX_OK; | |
341 } | |
342 | |
343 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
344 "gunzip in: %p", ctx->in); | |
345 | |
346 if (ctx->in == NULL) { | |
347 return NGX_DECLINED; | |
348 } | |
349 | |
350 ctx->in_buf = ctx->in->buf; | |
351 ctx->in = ctx->in->next; | |
352 | |
353 ctx->zstream.next_in = ctx->in_buf->pos; | |
354 ctx->zstream.avail_in = ctx->in_buf->last - ctx->in_buf->pos; | |
355 | |
356 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
357 "gunzip in_buf:%p ni:%p ai:%ud", | |
358 ctx->in_buf, | |
359 ctx->zstream.next_in, ctx->zstream.avail_in); | |
360 | |
361 if (ctx->in_buf->last_buf || ctx->in_buf->last_in_chain) { | |
362 ctx->flush = Z_FINISH; | |
363 | |
364 } else if (ctx->in_buf->flush) { | |
365 ctx->flush = Z_SYNC_FLUSH; | |
366 | |
367 } else if (ctx->zstream.avail_in == 0) { | |
368 /* ctx->flush == Z_NO_FLUSH */ | |
369 return NGX_AGAIN; | |
370 } | |
371 | |
372 return NGX_OK; | |
373 } | |
374 | |
375 | |
376 static ngx_int_t | |
377 ngx_http_gunzip_filter_get_buf(ngx_http_request_t *r, | |
378 ngx_http_gunzip_ctx_t *ctx) | |
379 { | |
380 ngx_http_gunzip_conf_t *conf; | |
381 | |
382 if (ctx->zstream.avail_out) { | |
383 return NGX_OK; | |
384 } | |
385 | |
386 conf = ngx_http_get_module_loc_conf(r, ngx_http_gunzip_filter_module); | |
387 | |
388 if (ctx->free) { | |
389 ctx->out_buf = ctx->free->buf; | |
390 ctx->free = ctx->free->next; | |
391 | |
392 ctx->out_buf->flush = 0; | |
393 | |
394 } else if (ctx->bufs < conf->bufs.num) { | |
395 | |
396 ctx->out_buf = ngx_create_temp_buf(r->pool, conf->bufs.size); | |
397 if (ctx->out_buf == NULL) { | |
398 return NGX_ERROR; | |
399 } | |
400 | |
401 ctx->out_buf->tag = (ngx_buf_tag_t) &ngx_http_gunzip_filter_module; | |
402 ctx->out_buf->recycled = 1; | |
403 ctx->bufs++; | |
404 | |
405 } else { | |
406 ctx->nomem = 1; | |
407 return NGX_DECLINED; | |
408 } | |
409 | |
410 ctx->zstream.next_out = ctx->out_buf->pos; | |
411 ctx->zstream.avail_out = conf->bufs.size; | |
412 | |
413 return NGX_OK; | |
414 } | |
415 | |
416 | |
417 static ngx_int_t | |
418 ngx_http_gunzip_filter_inflate(ngx_http_request_t *r, | |
419 ngx_http_gunzip_ctx_t *ctx) | |
420 { | |
421 int rc; | |
422 ngx_buf_t *b; | |
423 ngx_chain_t *cl; | |
424 | |
425 ngx_log_debug6(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
426 "inflate in: ni:%p no:%p ai:%ud ao:%ud fl:%d redo:%d", | |
427 ctx->zstream.next_in, ctx->zstream.next_out, | |
428 ctx->zstream.avail_in, ctx->zstream.avail_out, | |
429 ctx->flush, ctx->redo); | |
430 | |
431 rc = inflate(&ctx->zstream, ctx->flush); | |
432 | |
433 if (rc != Z_OK && rc != Z_STREAM_END && rc != Z_BUF_ERROR) { | |
434 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, | |
435 "inflate() failed: %d, %d", ctx->flush, rc); | |
436 return NGX_ERROR; | |
437 } | |
438 | |
439 ngx_log_debug5(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
440 "inflate out: ni:%p no:%p ai:%ud ao:%ud rc:%d", | |
441 ctx->zstream.next_in, ctx->zstream.next_out, | |
442 ctx->zstream.avail_in, ctx->zstream.avail_out, | |
443 rc); | |
444 | |
445 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
446 "gunzip in_buf:%p pos:%p", | |
447 ctx->in_buf, ctx->in_buf->pos); | |
448 | |
449 if (ctx->zstream.next_in) { | |
450 ctx->in_buf->pos = ctx->zstream.next_in; | |
451 | |
452 if (ctx->zstream.avail_in == 0) { | |
453 ctx->zstream.next_in = NULL; | |
454 } | |
455 } | |
456 | |
457 ctx->out_buf->last = ctx->zstream.next_out; | |
458 | |
459 if (ctx->zstream.avail_out == 0) { | |
460 | |
461 /* zlib wants to output some more data */ | |
462 | |
463 cl = ngx_alloc_chain_link(r->pool); | |
464 if (cl == NULL) { | |
465 return NGX_ERROR; | |
466 } | |
467 | |
468 cl->buf = ctx->out_buf; | |
469 cl->next = NULL; | |
470 *ctx->last_out = cl; | |
471 ctx->last_out = &cl->next; | |
472 | |
473 ctx->redo = 1; | |
474 | |
475 return NGX_AGAIN; | |
476 } | |
477 | |
478 ctx->redo = 0; | |
479 | |
480 if (ctx->flush == Z_SYNC_FLUSH) { | |
481 | |
482 ctx->flush = Z_NO_FLUSH; | |
483 | |
484 cl = ngx_alloc_chain_link(r->pool); | |
485 if (cl == NULL) { | |
486 return NGX_ERROR; | |
487 } | |
488 | |
489 b = ctx->out_buf; | |
490 | |
491 if (ngx_buf_size(b) == 0) { | |
492 | |
493 b = ngx_calloc_buf(ctx->request->pool); | |
494 if (b == NULL) { | |
495 return NGX_ERROR; | |
496 } | |
497 | |
498 } else { | |
499 ctx->zstream.avail_out = 0; | |
500 } | |
501 | |
502 b->flush = 1; | |
503 | |
504 cl->buf = b; | |
505 cl->next = NULL; | |
506 *ctx->last_out = cl; | |
507 ctx->last_out = &cl->next; | |
508 | |
509 return NGX_OK; | |
510 } | |
511 | |
512 if (rc == Z_STREAM_END && ctx->flush == Z_FINISH | |
513 && ctx->zstream.avail_in == 0) | |
514 { | |
515 | |
516 if (ngx_http_gunzip_filter_inflate_end(r, ctx) != NGX_OK) { | |
517 return NGX_ERROR; | |
518 } | |
519 | |
520 return NGX_OK; | |
521 } | |
522 | |
523 if (rc == Z_STREAM_END && ctx->zstream.avail_in > 0) { | |
524 | |
525 rc = inflateReset(&ctx->zstream); | |
526 | |
527 if (rc != Z_OK) { | |
528 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, | |
529 "inflateReset() failed: %d", rc); | |
530 return NGX_ERROR; | |
531 } | |
532 | |
533 ctx->redo = 1; | |
534 | |
535 return NGX_AGAIN; | |
536 } | |
537 | |
538 if (ctx->in == NULL) { | |
539 | |
540 cl = ngx_alloc_chain_link(r->pool); | |
541 if (cl == NULL) { | |
542 return NGX_ERROR; | |
543 } | |
544 | |
545 b = ctx->out_buf; | |
546 | |
547 if (ngx_buf_size(b) == 0) { | |
548 | |
549 b = ngx_calloc_buf(ctx->request->pool); | |
550 if (b == NULL) { | |
551 return NGX_ERROR; | |
552 } | |
553 | |
554 } else { | |
555 ctx->zstream.avail_out = 0; | |
556 } | |
557 | |
558 cl->buf = b; | |
559 cl->next = NULL; | |
560 *ctx->last_out = cl; | |
561 ctx->last_out = &cl->next; | |
562 | |
563 return NGX_OK; | |
564 } | |
565 | |
566 return NGX_AGAIN; | |
567 } | |
568 | |
569 | |
570 static ngx_int_t | |
571 ngx_http_gunzip_filter_inflate_end(ngx_http_request_t *r, | |
572 ngx_http_gunzip_ctx_t *ctx) | |
573 { | |
574 int rc; | |
575 ngx_buf_t *b; | |
576 ngx_chain_t *cl; | |
577 | |
578 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
579 "gunzip inflate end"); | |
580 | |
581 rc = inflateEnd(&ctx->zstream); | |
582 | |
583 if (rc != Z_OK) { | |
584 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, | |
585 "inflateEnd() failed: %d", rc); | |
586 return NGX_ERROR; | |
587 } | |
588 | |
589 b = ctx->out_buf; | |
590 | |
591 if (ngx_buf_size(b) == 0) { | |
592 | |
593 b = ngx_calloc_buf(ctx->request->pool); | |
594 if (b == NULL) { | |
595 return NGX_ERROR; | |
596 } | |
597 } | |
598 | |
599 cl = ngx_alloc_chain_link(r->pool); | |
600 if (cl == NULL) { | |
601 return NGX_ERROR; | |
602 } | |
603 | |
604 cl->buf = b; | |
605 cl->next = NULL; | |
606 *ctx->last_out = cl; | |
607 ctx->last_out = &cl->next; | |
608 | |
609 b->last_buf = (r == r->main) ? 1 : 0; | |
610 b->last_in_chain = 1; | |
611 b->sync = 1; | |
612 | |
613 ctx->done = 1; | |
614 | |
615 return NGX_OK; | |
616 } | |
617 | |
618 | |
619 static void * | |
620 ngx_http_gunzip_filter_alloc(void *opaque, u_int items, u_int size) | |
621 { | |
622 ngx_http_gunzip_ctx_t *ctx = opaque; | |
623 | |
624 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, ctx->request->connection->log, 0, | |
625 "gunzip alloc: n:%ud s:%ud", | |
626 items, size); | |
627 | |
628 return ngx_palloc(ctx->request->pool, items * size); | |
629 } | |
630 | |
631 | |
632 static void | |
633 ngx_http_gunzip_filter_free(void *opaque, void *address) | |
634 { | |
635 #if 0 | |
636 ngx_http_gunzip_ctx_t *ctx = opaque; | |
637 | |
638 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ctx->request->connection->log, 0, | |
639 "gunzip free: %p", address); | |
640 #endif | |
641 } | |
642 | |
643 | |
644 static void * | |
645 ngx_http_gunzip_create_conf(ngx_conf_t *cf) | |
646 { | |
647 ngx_http_gunzip_conf_t *conf; | |
648 | |
649 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_gunzip_conf_t)); | |
650 if (conf == NULL) { | |
651 return NULL; | |
652 } | |
653 | |
654 /* | |
655 * set by ngx_pcalloc(): | |
656 * | |
657 * conf->bufs.num = 0; | |
658 */ | |
659 | |
660 conf->enable = NGX_CONF_UNSET; | |
661 | |
662 return conf; | |
663 } | |
664 | |
665 | |
666 static char * | |
667 ngx_http_gunzip_merge_conf(ngx_conf_t *cf, void *parent, void *child) | |
668 { | |
669 ngx_http_gunzip_conf_t *prev = parent; | |
670 ngx_http_gunzip_conf_t *conf = child; | |
671 | |
672 ngx_conf_merge_value(conf->enable, prev->enable, 0); | |
673 | |
674 ngx_conf_merge_bufs_value(conf->bufs, prev->bufs, | |
675 (128 * 1024) / ngx_pagesize, ngx_pagesize); | |
676 | |
677 return NGX_CONF_OK; | |
678 } | |
679 | |
680 | |
681 static ngx_int_t | |
682 ngx_http_gunzip_filter_init(ngx_conf_t *cf) | |
683 { | |
684 ngx_http_next_header_filter = ngx_http_top_header_filter; | |
685 ngx_http_top_header_filter = ngx_http_gunzip_header_filter; | |
686 | |
687 ngx_http_next_body_filter = ngx_http_top_body_filter; | |
688 ngx_http_top_body_filter = ngx_http_gunzip_body_filter; | |
689 | |
690 return NGX_OK; | |
691 } |