Mercurial > hg > nginx
comparison src/http/modules/ngx_http_gzip_filter.c @ 136:da00cde00e8a
nginx-0.0.1-2003-10-02-09:39:37 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 02 Oct 2003 05:39:37 +0000 |
parents | e29909bd9b8a |
children | 656d468f4ead |
comparison
equal
deleted
inserted
replaced
135:e29909bd9b8a | 136:da00cde00e8a |
---|---|
171 } | 171 } |
172 | 172 |
173 | 173 |
174 static int ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in) | 174 static int ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in) |
175 { | 175 { |
176 int rc, zin, zout; | 176 int rc, wbits, mem_level, zin, zout; |
177 struct gztrailer *trailer; | 177 struct gztrailer *trailer; |
178 ngx_hunk_t *h; | 178 ngx_hunk_t *h; |
179 ngx_chain_t *ce; | 179 ngx_chain_t *ce; |
180 ngx_http_gzip_ctx_t *ctx; | 180 ngx_http_gzip_ctx_t *ctx; |
181 ngx_http_gzip_conf_t *conf; | 181 ngx_http_gzip_conf_t *conf; |
187 } | 187 } |
188 | 188 |
189 conf = ngx_http_get_module_loc_conf(r, ngx_http_gzip_filter_module); | 189 conf = ngx_http_get_module_loc_conf(r, ngx_http_gzip_filter_module); |
190 | 190 |
191 if (ctx->alloc == NULL) { | 191 if (ctx->alloc == NULL) { |
192 wbits = MAX_WBITS; | |
193 mem_level = MAX_MEM_LEVEL - 1; | |
194 | |
195 if (ctx->length > 0) { | |
196 | |
197 /* the actual zlib window size is smaller by 262 bytes */ | |
198 | |
199 while (ctx->length < ((1 << (wbits - 1)) - 262)) { | |
200 wbits--; | |
201 mem_level--; | |
202 } | |
203 } | |
204 | |
192 #if 0 | 205 #if 0 |
193 ngx_test_null(ctx->alloc, ngx_alloc(200K, r->log), NGX_ERROR); | 206 ngx_test_null(ctx->alloc, ngx_alloc(200K, r->log), NGX_ERROR); |
194 #else | 207 #else |
195 ctx->alloc = (void *) ~NULL; | 208 ctx->alloc = (void *) ~NULL; |
196 #endif | 209 #endif |
210 | |
197 rc = deflateInit2(&ctx->zstream, /**/ 1, Z_DEFLATED, | 211 rc = deflateInit2(&ctx->zstream, /**/ 1, Z_DEFLATED, |
198 /**/ -MAX_WBITS, /**/ MAX_MEM_LEVEL - 1, | 212 -wbits, mem_level, Z_DEFAULT_STRATEGY); |
199 Z_DEFAULT_STRATEGY); | |
200 | 213 |
201 if (rc != Z_OK) { | 214 if (rc != Z_OK) { |
202 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, | 215 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, |
203 "deflateInit2() failed: %d", rc); | 216 "deflateInit2() failed: %d", rc); |
204 return ngx_http_gzip_error(ctx); | 217 return ngx_http_gzip_error(ctx); |
242 } | 255 } |
243 | 256 |
244 ctx->in_hunk = ctx->in->hunk; | 257 ctx->in_hunk = ctx->in->hunk; |
245 ctx->in = ctx->in->next; | 258 ctx->in = ctx->in->next; |
246 | 259 |
247 ctx->zstream.next_in = ctx->in_hunk->pos; | 260 ctx->zstream.next_in = (unsigned char *) ctx->in_hunk->pos; |
248 ctx->zstream.avail_in = ctx->in_hunk->last - ctx->in_hunk->pos; | 261 ctx->zstream.avail_in = ctx->in_hunk->last - ctx->in_hunk->pos; |
249 | 262 |
250 if (ctx->in_hunk->type & NGX_HUNK_LAST) { | 263 if (ctx->in_hunk->type & NGX_HUNK_LAST) { |
251 ctx->flush = Z_FINISH; | 264 ctx->flush = Z_FINISH; |
252 | 265 |
281 | 294 |
282 } else { | 295 } else { |
283 break; | 296 break; |
284 } | 297 } |
285 | 298 |
286 ctx->zstream.next_out = ctx->out_hunk->pos; | 299 ctx->zstream.next_out = (unsigned char *) ctx->out_hunk->pos; |
287 ctx->zstream.avail_out = conf->hunk_size; | 300 ctx->zstream.avail_out = conf->hunk_size; |
288 } | 301 } |
289 | 302 |
290 ngx_log_debug(r->connection->log, "deflate(): %08x %08x %d %d %d" _ | 303 ngx_log_debug(r->connection->log, "deflate(): %08x %08x %d %d %d" _ |
291 ctx->zstream.next_in _ ctx->zstream.next_out _ | 304 ctx->zstream.next_in _ ctx->zstream.next_out _ |
300 | 313 |
301 ngx_log_debug(r->connection->log, "DEFLATE(): %08x %08x %d %d %d" _ | 314 ngx_log_debug(r->connection->log, "DEFLATE(): %08x %08x %d %d %d" _ |
302 ctx->zstream.next_in _ ctx->zstream.next_out _ | 315 ctx->zstream.next_in _ ctx->zstream.next_out _ |
303 ctx->zstream.avail_in _ ctx->zstream.avail_out _ rc); | 316 ctx->zstream.avail_in _ ctx->zstream.avail_out _ rc); |
304 | 317 |
305 ctx->in_hunk->pos = ctx->zstream.next_in; | 318 ctx->in_hunk->pos = (char *) ctx->zstream.next_in; |
306 | 319 |
307 if (ctx->zstream.avail_out == 0) { | 320 if (ctx->zstream.avail_out == 0) { |
308 ctx->out_hunk->last += conf->hunk_size; | 321 ctx->out_hunk->last += conf->hunk_size; |
309 ngx_add_hunk_to_chain(ce, ctx->out_hunk, r->pool, | 322 ngx_add_hunk_to_chain(ce, ctx->out_hunk, r->pool, |
310 ngx_http_gzip_error(ctx)); | 323 ngx_http_gzip_error(ctx)); |
311 *ctx->last_out = ce; | 324 *ctx->last_out = ce; |
312 ctx->last_out = &ce->next; | 325 ctx->last_out = &ce->next; |
313 ctx->redo = 1; | 326 ctx->redo = 1; |
314 | 327 |
315 } else { | 328 } else { |
316 ctx->out_hunk->last = ctx->zstream.next_out; | 329 ctx->out_hunk->last = (char *) ctx->zstream.next_out; |
317 ctx->redo = 0; | 330 ctx->redo = 0; |
318 | 331 |
319 if (ctx->flush == Z_SYNC_FLUSH) { | 332 if (ctx->flush == Z_SYNC_FLUSH) { |
320 ctx->out_hunk->type |= NGX_HUNK_FLUSH; | 333 ctx->out_hunk->type |= NGX_HUNK_FLUSH; |
321 ctx->flush = Z_NO_FLUSH; | 334 ctx->flush = Z_NO_FLUSH; |
376 /* STUB */ | 389 /* STUB */ |
377 #endif | 390 #endif |
378 | 391 |
379 ctx->zstream.avail_in = 0; | 392 ctx->zstream.avail_in = 0; |
380 ctx->zstream.avail_out = 0; | 393 ctx->zstream.avail_out = 0; |
394 #if 0 | |
395 ngx_free(ctx->alloc); | |
396 #endif | |
381 ngx_http_delete_ctx(r, ngx_http_gzip_filter_module); | 397 ngx_http_delete_ctx(r, ngx_http_gzip_filter_module); |
382 #if 0 | 398 |
383 ngx_free(); | |
384 #endif | |
385 break; | 399 break; |
386 | 400 |
387 } else if (conf->no_buffer && ctx->in == NULL) { | 401 } else if (conf->no_buffer && ctx->in == NULL) { |
388 ngx_add_hunk_to_chain(ce, ctx->out_hunk, r->pool, | 402 ngx_add_hunk_to_chain(ce, ctx->out_hunk, r->pool, |
389 ngx_http_gzip_error(ctx)); | 403 ngx_http_gzip_error(ctx)); |