Changeset dbd2c3
- Timestamp:
- 02/04/08 16:11:49 (4 years ago)
- Branches:
- master-v0.7, master-v0.6, memcached_gzip, upstream_count_limit
- Children:
- b649a6, f54237
- Parents:
- 2a28c1 (diff), 95d817 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - git-author:
- Tomash Brechko <tomash.brechko@…> (02/04/08 16:11:49)
- git-committer:
- Tomash Brechko <tomash.brechko@…> (02/04/08 16:11:49)
- Location:
- server/src/http/modules
- Files:
-
- 2 edited
-
ngx_http_gzip_filter_module.c (modified) (8 diffs)
-
ngx_http_memcached_module.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
server/src/http/modules/ngx_http_gzip_filter_module.c
r2bbdb3 r95d817 309 309 ngx_http_gzip_ctx_t *ctx; 310 310 ngx_http_gzip_conf_t *conf; 311 const char *method = (r->gunzip ? "inflate" : "deflate"); 311 312 312 313 ctx = ngx_http_get_module_ctx(r, ngx_http_gzip_filter_module); … … 366 367 if (rc != Z_OK) { 367 368 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, 368 " deflateInit2() failed: %d", rc);369 "%sInit2() failed: %d", method, rc); 369 370 ngx_http_gzip_error(ctx); 370 371 return NGX_ERROR; … … 456 457 457 458 if (ctx->in_buf->last_buf) { 458 ctx->flush = Z_FINISH; 459 /* 460 * We use Z_BLOCK below for the following reason: 461 * if we would use Z_FINISH, then decompression 462 * may return Z_BUF_ERROR, meaning there wasn't 463 * enough room for decompressed data. This error 464 * is not fatal according to zlib.h, however 465 * ignoring it is dangerous and may mask real 466 * bugs. For instance, sometimes completely empty 467 * last buffer is passed to this filter, and 468 * decompression would enter the infinite loop: no 469 * progress is possible because input is void and 470 * Z_BUF_ERROR is ignored. We can't use 471 * Z_NO_FLUSH, because it will never return 472 * Z_STREAM_END. We can't use Z_SYNC_FLUSH, 473 * because it has a special meaning. So we use 474 * Z_BLOCK, which eventually would return 475 * Z_STREAM_END. 476 * 477 * Perhaps the above is also true for compression, 478 * but right now we won't try to change the old 479 * behaviour. 480 */ 481 ctx->flush = (!r->gunzip ? Z_FINISH : Z_BLOCK); 459 482 460 483 } else if (ctx->in_buf->flush) { … … 474 497 475 498 476 /* is there a space for the gzippeddata ? */499 /* is there a space for the output data ? */ 477 500 478 501 if (ctx->zstream.avail_out == 0) { … … 503 526 } 504 527 505 ngx_log_debug6(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 506 "deflate in: ni:%p no:%p ai:%ud ao:%ud fl:%d redo:%d", 528 ngx_log_debug7(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 529 "%s in: ni:%p no:%p ai:%ud ao:%ud fl:%d redo:%d", 530 method, 507 531 ctx->zstream.next_in, ctx->zstream.next_out, 508 532 ctx->zstream.avail_in, ctx->zstream.avail_out, … … 515 539 } 516 540 517 if (rc != Z_OK && rc != Z_STREAM_END && rc != Z_BUF_ERROR) {541 if (rc != Z_OK && rc != Z_STREAM_END) { 518 542 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, 519 " deflate() failed: %d, %d", ctx->flush, rc);543 "%s() failed: %d, %d", method, ctx->flush, rc); 520 544 ngx_http_gzip_error(ctx); 521 545 return NGX_ERROR; 522 546 } 523 547 524 ngx_log_debug5(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 525 "deflate out: ni:%p no:%p ai:%ud ao:%ud rc:%d", 548 ngx_log_debug6(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 549 "%s out: ni:%p no:%p ai:%ud ao:%ud rc:%d", 550 method, 526 551 ctx->zstream.next_in, ctx->zstream.next_out, 527 552 ctx->zstream.avail_in, ctx->zstream.avail_out, 528 553 rc); 529 554 530 ngx_log_debug 2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,531 " gzipin_buf:%p pos:%p",532 ctx->in_buf, ctx->in_buf->pos);555 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 556 "%s in_buf:%p pos:%p", 557 method, ctx->in_buf, ctx->in_buf->pos); 533 558 534 559 … … 588 613 if (rc != Z_OK) { 589 614 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, 590 " deflateEnd() failed: %d", rc);615 "%sEnd() failed: %d", method, rc); 591 616 ngx_http_gzip_error(ctx); 592 617 return NGX_ERROR; … … 601 626 } 602 627 603 cl->buf = ctx->out_buf; 604 cl->next = NULL; 605 *ctx->last_out = cl; 606 ctx->last_out = &cl->next; 628 /* 629 * On decompression we could already output everything 630 * under (ctx->flush == Z_SYNC_FLUSH), so we test here 631 * that the buffer is not empty. 632 */ 633 if (!r->gunzip || ctx->out_buf->last > ctx->out_buf->pos) { 634 cl->buf = ctx->out_buf; 635 cl->next = NULL; 636 *ctx->last_out = cl; 637 ctx->last_out = &cl->next; 638 } 607 639 608 640 if (!r->gunzip) { -
server/src/http/modules/ngx_http_memcached_module.c
r0019fc re1c857 14 14 ngx_http_upstream_conf_t upstream; 15 15 ngx_int_t index; 16 ngx_uint_t gzip_flag; 16 17 } ngx_http_memcached_loc_conf_t; 17 18 … … 99 100 offsetof(ngx_http_memcached_loc_conf_t, upstream.next_upstream), 100 101 &ngx_http_memcached_next_upstream_masks }, 102 103 { ngx_string("memcached_gzip_flag"), 104 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, 105 ngx_conf_set_num_slot, 106 NGX_HTTP_LOC_CONF_OFFSET, 107 offsetof(ngx_http_memcached_loc_conf_t, gzip_flag), 108 NULL }, 101 109 102 110 { ngx_string("memcached_upstream_max_fails"), … … 298 306 ngx_http_memcached_process_header(ngx_http_request_t *r) 299 307 { 300 u_char *p, * len;308 u_char *p, *beg; 301 309 ngx_str_t line; 302 310 ngx_http_upstream_t *u; 303 311 ngx_http_memcached_ctx_t *ctx; 312 ngx_http_memcached_loc_conf_t *mlcf; 313 uint32_t flags; 314 ngx_table_elt_t *h; 315 ngx_http_core_loc_conf_t *clcf; 304 316 305 317 u = r->upstream; … … 346 358 } 347 359 348 /* skip flags */349 350 while (*p ) {351 if (*p++ == ' ') { 352 goto length;353 }360 beg = p; 361 362 while (*p && *p++ != ' ') { /* void */ } 363 364 if (! *p) { 365 goto no_valid; 354 366 } 355 367 356 goto no_valid; 357 358 length: 359 360 len = p; 368 flags = ngx_atoof(beg, p - beg - 1); 369 370 beg = p; 361 371 362 372 while (*p && *p++ != CR) { /* void */ } 363 373 364 r->headers_out.content_length_n = ngx_atoof( len, p - len- 1);374 r->headers_out.content_length_n = ngx_atoof(beg, p - beg - 1); 365 375 if (r->headers_out.content_length_n == -1) { 366 376 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, … … 369 379 &line, &ctx->key); 370 380 return NGX_HTTP_UPSTREAM_INVALID_HEADER; 381 } 382 383 mlcf = ngx_http_get_module_loc_conf(r, ngx_http_memcached_module); 384 385 if (flags & mlcf->gzip_flag) { 386 #if (NGX_HTTP_GZIP) 387 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); 388 389 if (ngx_http_gzip_ok(r) == NGX_OK) { 390 h = ngx_list_push(&r->headers_out.headers); 391 if (h == NULL) { 392 return NGX_ERROR; 393 } 394 395 h->hash = 1; 396 h->key.len = sizeof("Content-Encoding") - 1; 397 h->key.data = (u_char *) "Content-Encoding"; 398 h->value.len = sizeof("gzip") - 1; 399 h->value.data = (u_char *) "gzip"; 400 401 r->headers_out.content_encoding = h; 402 403 if (clcf->gzip_vary) { 404 h = ngx_list_push(&r->headers_out.headers); 405 if (h == NULL) { 406 return NGX_ERROR; 407 } 408 409 h->hash = 1; 410 h->key.len = sizeof("Vary") - 1; 411 h->key.data = (u_char *) "Vary"; 412 h->value.len = sizeof("Accept-Encoding") - 1; 413 h->value.data = (u_char *) "Accept-Encoding"; 414 } 415 } else { 416 if (clcf->gunzip) { 417 r->gunzip = 1; 418 } else { 419 #endif 420 /* 421 * If the client can't accept compressed data, and 422 * automatic decompression is not enabled, we 423 * return 404 in the hope that the next upstream 424 * will return uncompressed data. 425 */ 426 u->headers_in.status_n = 404; 427 u->state->status = 404; 428 429 return NGX_OK; 430 #if (NGX_HTTP_GZIP) 431 } 432 } 433 #endif 371 434 } 372 435 … … 532 595 533 596 conf->upstream.buffer_size = NGX_CONF_UNSET_SIZE; 597 598 conf->gzip_flag = NGX_CONF_UNSET_UINT; 534 599 535 600 /* the hardcoded values */ … … 576 641 |NGX_HTTP_UPSTREAM_FT_TIMEOUT)); 577 642 643 ngx_conf_merge_uint_value(conf->gzip_flag, 644 prev->gzip_flag, 0); 645 578 646 if (conf->upstream.next_upstream & NGX_HTTP_UPSTREAM_FT_OFF) { 579 647 conf->upstream.next_upstream = NGX_CONF_BITMASK_SET
Note: See TracChangeset
for help on using the changeset viewer.
