Mercurial > hg > nginx-vendor-0-7
comparison src/http/modules/ngx_http_gzip_filter.c @ 10:46833bd150cb NGINX_0_1_5
nginx 0.1.5
*) Bugfix: on Solaris and Linux there may be too many "recvmsg()
returned not enough data" alerts.
*) Bugfix: there were the "writev() failed (22: Invalid argument)"
errors on Solaris in proxy mode without sendfile. On other platforms
that do not support sendfile at all the process got caught in an
endless loop.
*) Bugfix: segmentation fault on Solaris in proxy mode and using
sendfile.
*) Bugfix: segmentation fault on Solaris.
*) Bugfix: on-line upgrade did not work on Linux.
*) Bugfix: the ngx_http_autoindex_module module did not escape the
spaces, the quotes, and the percent signs in the directory listing.
*) Change: the decrease of the copy operations.
*) Feature: the userid_p3p directive.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Thu, 11 Nov 2004 00:00:00 +0300 |
parents | 4b2dafa26fe2 |
children | 6f8b0dc0f8dd |
comparison
equal
deleted
inserted
replaced
9:77eee314ddbd | 10:46833bd150cb |
---|---|
78 static ngx_int_t ngx_http_gzip_proxied(ngx_http_request_t *r, | 78 static ngx_int_t ngx_http_gzip_proxied(ngx_http_request_t *r, |
79 ngx_http_gzip_conf_t *conf); | 79 ngx_http_gzip_conf_t *conf); |
80 static void *ngx_http_gzip_filter_alloc(void *opaque, u_int items, | 80 static void *ngx_http_gzip_filter_alloc(void *opaque, u_int items, |
81 u_int size); | 81 u_int size); |
82 static void ngx_http_gzip_filter_free(void *opaque, void *address); | 82 static void ngx_http_gzip_filter_free(void *opaque, void *address); |
83 ngx_inline static int ngx_http_gzip_error(ngx_http_gzip_ctx_t *ctx); | 83 static int ngx_http_gzip_error(ngx_http_gzip_ctx_t *ctx); |
84 | 84 |
85 static u_char *ngx_http_gzip_log_ratio(ngx_http_request_t *r, u_char *buf, | 85 static u_char *ngx_http_gzip_log_ratio(ngx_http_request_t *r, u_char *buf, |
86 uintptr_t data); | 86 uintptr_t data); |
87 | 87 |
88 static ngx_int_t ngx_http_gzip_pre_conf(ngx_conf_t *cf); | 88 static ngx_int_t ngx_http_gzip_pre_conf(ngx_conf_t *cf); |
505 | 505 |
506 b->memory = 1; | 506 b->memory = 1; |
507 b->pos = gzheader; | 507 b->pos = gzheader; |
508 b->last = b->pos + 10; | 508 b->last = b->pos + 10; |
509 | 509 |
510 ngx_alloc_link_and_set_buf(cl, b, r->pool, ngx_http_gzip_error(ctx)); | 510 if (!(cl = ngx_alloc_chain_link(r->pool))) { |
511 return ngx_http_gzip_error(ctx); | |
512 } | |
513 cl->buf = b; | |
514 cl->next = NULL; | |
511 ctx->out = cl; | 515 ctx->out = cl; |
512 ctx->last_out = &cl->next; | 516 ctx->last_out = &cl->next; |
513 | 517 |
514 ctx->crc32 = crc32(0L, Z_NULL, 0); | 518 ctx->crc32 = crc32(0L, Z_NULL, 0); |
515 ctx->flush = Z_NO_FLUSH; | 519 ctx->flush = Z_NO_FLUSH; |
532 if (ctx->zstream.avail_in == 0 | 536 if (ctx->zstream.avail_in == 0 |
533 && ctx->flush == Z_NO_FLUSH | 537 && ctx->flush == Z_NO_FLUSH |
534 && !ctx->redo) | 538 && !ctx->redo) |
535 { | 539 { |
536 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 540 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
537 "gzip in: " PTR_FMT, ctx->in); | 541 "gzip in: %p", ctx->in); |
538 | 542 |
539 if (ctx->in == NULL) { | 543 if (ctx->in == NULL) { |
540 break; | 544 break; |
541 } | 545 } |
542 | 546 |
545 | 549 |
546 ctx->zstream.next_in = ctx->in_buf->pos; | 550 ctx->zstream.next_in = ctx->in_buf->pos; |
547 ctx->zstream.avail_in = ctx->in_buf->last - ctx->in_buf->pos; | 551 ctx->zstream.avail_in = ctx->in_buf->last - ctx->in_buf->pos; |
548 | 552 |
549 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 553 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
550 "gzip in_buf:" PTR_FMT " ni:" PTR_FMT " ai:%d", | 554 "gzip in_buf:%p ni:%p ai:%ud", |
551 ctx->in_buf, | 555 ctx->in_buf, |
552 ctx->zstream.next_in, ctx->zstream.avail_in); | 556 ctx->zstream.next_in, ctx->zstream.avail_in); |
553 | 557 |
554 /* STUB */ | 558 /* STUB */ |
555 if (ctx->in_buf->last < ctx->in_buf->pos) { | 559 if (ctx->in_buf->last < ctx->in_buf->pos) { |
606 ctx->zstream.next_out = ctx->out_buf->pos; | 610 ctx->zstream.next_out = ctx->out_buf->pos; |
607 ctx->zstream.avail_out = conf->bufs.size; | 611 ctx->zstream.avail_out = conf->bufs.size; |
608 } | 612 } |
609 | 613 |
610 ngx_log_debug6(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 614 ngx_log_debug6(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
611 "deflate in: ni:%X no:%X ai:%d ao:%d fl:%d redo:%d", | 615 "deflate in: ni:%p no:%p ai:%ud ao:%ud fl:%d redo:%d", |
612 ctx->zstream.next_in, ctx->zstream.next_out, | 616 ctx->zstream.next_in, ctx->zstream.next_out, |
613 ctx->zstream.avail_in, ctx->zstream.avail_out, | 617 ctx->zstream.avail_in, ctx->zstream.avail_out, |
614 ctx->flush, ctx->redo); | 618 ctx->flush, ctx->redo); |
615 | 619 |
616 rc = deflate(&ctx->zstream, ctx->flush); | 620 rc = deflate(&ctx->zstream, ctx->flush); |
617 | 621 |
618 if (rc != Z_OK && rc != Z_STREAM_END) { | 622 if (rc != Z_OK && rc != Z_STREAM_END) { |
619 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, | 623 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, |
620 "deflate() failed: %d, %d", ctx->flush, rc); | 624 "deflate() failed: %d, %d", ctx->flush, rc); |
621 return ngx_http_gzip_error(ctx); | 625 return ngx_http_gzip_error(ctx); |
622 } | 626 } |
623 | 627 |
624 ngx_log_debug5(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 628 ngx_log_debug5(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
625 "deflate out: ni:%X no:%X ai:%d ao:%d rc:%d", | 629 "deflate out: ni:%p no:%p ai:%ud ao:%ud rc:%d", |
626 ctx->zstream.next_in, ctx->zstream.next_out, | 630 ctx->zstream.next_in, ctx->zstream.next_out, |
627 ctx->zstream.avail_in, ctx->zstream.avail_out, | 631 ctx->zstream.avail_in, ctx->zstream.avail_out, |
628 rc); | 632 rc); |
629 | 633 |
630 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 634 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
631 "gzip in_buf:" PTR_FMT " pos:" PTR_FMT, | 635 "gzip in_buf:%p pos:%p", |
632 ctx->in_buf, ctx->in_buf->pos); | 636 ctx->in_buf, ctx->in_buf->pos); |
633 | 637 |
634 | 638 |
635 if (ctx->zstream.next_in) { | 639 if (ctx->zstream.next_in) { |
636 ctx->in_buf->pos = ctx->zstream.next_in; | 640 ctx->in_buf->pos = ctx->zstream.next_in; |
644 | 648 |
645 if (ctx->zstream.avail_out == 0) { | 649 if (ctx->zstream.avail_out == 0) { |
646 | 650 |
647 /* zlib wants to output some more gzipped data */ | 651 /* zlib wants to output some more gzipped data */ |
648 | 652 |
649 ngx_alloc_link_and_set_buf(cl, ctx->out_buf, r->pool, | 653 if (!(cl = ngx_alloc_chain_link(r->pool))) { |
650 ngx_http_gzip_error(ctx)); | 654 return ngx_http_gzip_error(ctx); |
655 } | |
656 cl->buf = ctx->out_buf; | |
657 cl->next = NULL; | |
651 *ctx->last_out = cl; | 658 *ctx->last_out = cl; |
652 ctx->last_out = &cl->next; | 659 ctx->last_out = &cl->next; |
653 | 660 |
654 ctx->redo = 1; | 661 ctx->redo = 1; |
655 | 662 |
661 if (ctx->flush == Z_SYNC_FLUSH) { | 668 if (ctx->flush == Z_SYNC_FLUSH) { |
662 | 669 |
663 ctx->out_buf->flush = 0; | 670 ctx->out_buf->flush = 0; |
664 ctx->flush = Z_NO_FLUSH; | 671 ctx->flush = Z_NO_FLUSH; |
665 | 672 |
666 ngx_alloc_link_and_set_buf(cl, ctx->out_buf, r->pool, | 673 if (!(cl = ngx_alloc_chain_link(r->pool))) { |
667 ngx_http_gzip_error(ctx)); | 674 return ngx_http_gzip_error(ctx); |
675 } | |
676 cl->buf = ctx->out_buf; | |
677 cl->next = NULL; | |
668 *ctx->last_out = cl; | 678 *ctx->last_out = cl; |
669 ctx->last_out = &cl->next; | 679 ctx->last_out = &cl->next; |
670 | 680 |
671 break; | 681 break; |
672 } | 682 } |
684 return ngx_http_gzip_error(ctx); | 694 return ngx_http_gzip_error(ctx); |
685 } | 695 } |
686 | 696 |
687 ngx_pfree(r->pool, ctx->preallocated); | 697 ngx_pfree(r->pool, ctx->preallocated); |
688 | 698 |
689 ngx_alloc_link_and_set_buf(cl, ctx->out_buf, r->pool, | 699 if (!(cl = ngx_alloc_chain_link(r->pool))) { |
690 ngx_http_gzip_error(ctx)); | 700 return ngx_http_gzip_error(ctx); |
701 } | |
702 cl->buf = ctx->out_buf; | |
703 cl->next = NULL; | |
691 *ctx->last_out = cl; | 704 *ctx->last_out = cl; |
692 ctx->last_out = &cl->next; | 705 ctx->last_out = &cl->next; |
693 | 706 |
694 if (ctx->zstream.avail_out >= 8) { | 707 if (ctx->zstream.avail_out >= 8) { |
695 trailer = (struct gztrailer *) ctx->out_buf->last; | 708 trailer = (struct gztrailer *) ctx->out_buf->last; |
701 return ngx_http_gzip_error(ctx); | 714 return ngx_http_gzip_error(ctx); |
702 } | 715 } |
703 | 716 |
704 b->last_buf = 1; | 717 b->last_buf = 1; |
705 | 718 |
706 ngx_alloc_link_and_set_buf(cl, b, r->pool, | 719 if (!(cl = ngx_alloc_chain_link(r->pool))) { |
707 ngx_http_gzip_error(ctx)); | 720 return ngx_http_gzip_error(ctx); |
721 } | |
722 cl->buf = b; | |
723 cl->next = NULL; | |
708 *ctx->last_out = cl; | 724 *ctx->last_out = cl; |
709 ctx->last_out = &cl->next; | 725 ctx->last_out = &cl->next; |
710 trailer = (struct gztrailer *) b->pos; | 726 trailer = (struct gztrailer *) b->pos; |
711 b->last += 8; | 727 b->last += 8; |
712 } | 728 } |
733 | 749 |
734 break; | 750 break; |
735 } | 751 } |
736 | 752 |
737 if (conf->no_buffer && ctx->in == NULL) { | 753 if (conf->no_buffer && ctx->in == NULL) { |
738 ngx_alloc_link_and_set_buf(cl, ctx->out_buf, r->pool, | 754 if (!(cl = ngx_alloc_chain_link(r->pool))) { |
739 ngx_http_gzip_error(ctx)); | 755 return ngx_http_gzip_error(ctx); |
756 } | |
757 cl->buf = ctx->out_buf; | |
758 cl->next = NULL; | |
740 *ctx->last_out = cl; | 759 *ctx->last_out = cl; |
741 ctx->last_out = &cl->next; | 760 ctx->last_out = &cl->next; |
742 | 761 |
743 break; | 762 break; |
744 } | 763 } |
780 | 799 |
781 void *p; | 800 void *p; |
782 ngx_uint_t alloc; | 801 ngx_uint_t alloc; |
783 | 802 |
784 alloc = items * size; | 803 alloc = items * size; |
804 | |
785 if (alloc % 512 != 0) { | 805 if (alloc % 512 != 0) { |
786 | 806 |
787 /* | 807 /* |
788 * the zlib deflate_state allocation, it takes about 6K, we allocate 8K | 808 * The zlib deflate_state allocation, it takes about 6K, |
809 * we allocate 8K. Other allocations are divisible by 512. | |
789 */ | 810 */ |
790 | 811 |
791 alloc = (alloc + ngx_pagesize - 1) & ~(ngx_pagesize - 1); | 812 alloc = (alloc + ngx_pagesize - 1) & ~(ngx_pagesize - 1); |
792 } | 813 } |
793 | 814 |
795 p = ctx->free_mem; | 816 p = ctx->free_mem; |
796 ctx->free_mem += alloc; | 817 ctx->free_mem += alloc; |
797 ctx->allocated -= alloc; | 818 ctx->allocated -= alloc; |
798 | 819 |
799 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, ctx->request->connection->log, 0, | 820 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, ctx->request->connection->log, 0, |
800 "gzip alloc: n:%d s:%d a:%d p:" PTR_FMT, | 821 "gzip alloc: n:%ud s:%ud a:%ud p:%p", |
801 items, size, alloc, p); | 822 items, size, alloc, p); |
802 | 823 |
803 return p; | 824 return p; |
804 } | 825 } |
805 | 826 |
806 ngx_log_error(NGX_LOG_ALERT, ctx->request->connection->log, 0, | 827 ngx_log_error(NGX_LOG_ALERT, ctx->request->connection->log, 0, |
807 "gzip filter failed to use preallocated memory: %d of %d", | 828 "gzip filter failed to use preallocated memory: %ud of %ud", |
808 items * size, ctx->allocated); | 829 items * size, ctx->allocated); |
809 | 830 |
810 p = ngx_palloc(ctx->request->pool, items * size); | 831 p = ngx_palloc(ctx->request->pool, items * size); |
811 | 832 |
812 return p; | 833 return p; |
817 { | 838 { |
818 #if 0 | 839 #if 0 |
819 ngx_http_gzip_ctx_t *ctx = opaque; | 840 ngx_http_gzip_ctx_t *ctx = opaque; |
820 | 841 |
821 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ctx->request->connection->log, 0, | 842 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ctx->request->connection->log, 0, |
822 "gzip free: %X", address); | 843 "gzip free: %p", address); |
823 #endif | 844 #endif |
824 } | 845 } |
825 | 846 |
826 | 847 |
827 static u_char *ngx_http_gzip_log_ratio(ngx_http_request_t *r, u_char *buf, | 848 static u_char *ngx_http_gzip_log_ratio(ngx_http_request_t *r, u_char *buf, |
835 if (ctx == NULL || ctx->zout == 0) { | 856 if (ctx == NULL || ctx->zout == 0) { |
836 *buf = '-'; | 857 *buf = '-'; |
837 return buf + 1; | 858 return buf + 1; |
838 } | 859 } |
839 | 860 |
840 /* we prefer do not use the FPU */ | |
841 | |
842 zint = (ngx_uint_t) (ctx->zin / ctx->zout); | 861 zint = (ngx_uint_t) (ctx->zin / ctx->zout); |
843 zfrac = (ngx_uint_t) ((ctx->zin * 100 / ctx->zout) % 100); | 862 zfrac = (ngx_uint_t) ((ctx->zin * 100 / ctx->zout) % 100); |
844 | 863 |
845 if ((ctx->zin * 1000 / ctx->zout) % 10 > 4) { | 864 if ((ctx->zin * 1000 / ctx->zout) % 10 > 4) { |
846 | 865 |
853 zfrac = 0; | 872 zfrac = 0; |
854 } | 873 } |
855 } | 874 } |
856 | 875 |
857 return ngx_sprintf(buf, "%ui.%02ui", zint, zfrac); | 876 return ngx_sprintf(buf, "%ui.%02ui", zint, zfrac); |
858 | 877 } |
859 #if 0 | 878 |
860 return buf + ngx_snprintf((char *) buf, NGX_INT32_LEN + 4, | 879 |
861 "%" NGX_UINT_T_FMT ".%02" NGX_UINT_T_FMT, | 880 static int ngx_http_gzip_error(ngx_http_gzip_ctx_t *ctx) |
862 zint, zfrac); | |
863 #endif | |
864 } | |
865 | |
866 | |
867 ngx_inline static int ngx_http_gzip_error(ngx_http_gzip_ctx_t *ctx) | |
868 { | 881 { |
869 deflateEnd(&ctx->zstream); | 882 deflateEnd(&ctx->zstream); |
870 | 883 |
871 ngx_pfree(ctx->request->pool, ctx->preallocated); | 884 ngx_pfree(ctx->request->pool, ctx->preallocated); |
872 | 885 |