Klaus Demo nginx / a2c8119
nginx-0.0.11-2004-09-19-22:27:00 import Igor Sysoev 17 years ago
3 changed file(s) with 86 addition(s) and 29 deletion(s). Raw diff Collapse all Expand all
6666 "zero size buf");
6767
6868 ctx->in = ctx->in->next;
69
6970 continue;
7071 }
7172
145146 if (out) {
146147 break;
147148 }
149
148150 return rc;
149151 }
150152
5050
5151 unsigned flush:4;
5252 unsigned redo:1;
53 unsigned done:1;
54 #if 0
5355 unsigned pass:1;
54 unsigned done:1;
5556 unsigned blocked:1;
57 #endif
5658
5759 size_t zin;
5860 size_t zout;
444446
445447 ctx->allocated = 8192 + (1 << (wbits + 2)) + (1 << (memlevel + 9));
446448
447 ngx_test_null(ctx->preallocated, ngx_palloc(r->pool, ctx->allocated),
448 NGX_ERROR);
449 if (!(ctx->preallocated = ngx_palloc(r->pool, ctx->allocated))) {
450 return NGX_ERROR;
451 }
452
449453 ctx->free_mem = ctx->preallocated;
450454
451455 ctx->zstream.zalloc = ngx_http_gzip_filter_alloc;
461465 return ngx_http_gzip_error(ctx);
462466 }
463467
464 ngx_test_null(b, ngx_calloc_buf(r->pool), ngx_http_gzip_error(ctx));
468 if (!(b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t)))) {
469 return ngx_http_gzip_error(ctx);
470 }
465471
466472 b->memory = 1;
467473 b->pos = gzheader;
487493
488494 for ( ;; ) {
489495
490 /* is there a data to gzip ? */
496 /* does zlib need a new data ? */
491497
492498 if (ctx->zstream.avail_in == 0
493499 && ctx->flush == Z_NO_FLUSH
518524 ctx->done = 1;
519525 return NGX_ERROR;
520526 }
527 /**/
521528
522529 if (ctx->in_buf->last_buf) {
523530 ctx->flush = Z_FINISH;
537544 }
538545 }
539546
547
540548 /* is there a space for the gzipped data ? */
541549
542550 if (ctx->zstream.avail_out == 0) {
551
543552 if (ctx->free) {
544553 ctx->out_buf = ctx->free->buf;
545554 ctx->free = ctx->free->next;
546555
547556 } else if (ctx->bufs < conf->bufs.num) {
548 ngx_test_null(ctx->out_buf,
549 ngx_create_temp_buf(r->pool, conf->bufs.size),
550 ngx_http_gzip_error(ctx));
557 ctx->out_buf = ngx_create_temp_buf(r->pool,
558 conf->bufs.size);
559 if (ctx->out_buf == NULL) {
560 return ngx_http_gzip_error(ctx);
561 }
562
551563 ctx->out_buf->tag = (ngx_buf_tag_t)
552564 &ngx_http_gzip_filter_module;
553565 ctx->out_buf->recycled = 1;
554566 ctx->bufs++;
555567
556568 } else {
569 #if 0
557570 ctx->blocked = 1;
571 #endif
558572 break;
559573 }
560574
575 #if 0
561576 ctx->blocked = 0;
577 #endif
562578 ctx->zstream.next_out = ctx->out_buf->pos;
563579 ctx->zstream.avail_out = conf->bufs.size;
564580 }
570586 ctx->flush, ctx->redo);
571587
572588 rc = deflate(&ctx->zstream, ctx->flush);
589
573590 if (rc != Z_OK && rc != Z_STREAM_END) {
574591 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
575592 "deflate() failed: %d, %d", ctx->flush, rc);
598615 ctx->out_buf->last = ctx->zstream.next_out;
599616
600617 if (ctx->zstream.avail_out == 0) {
618
619 /* zlib wants to output some more gzipped data */
620
601621 ngx_alloc_link_and_set_buf(cl, ctx->out_buf, r->pool,
602622 ngx_http_gzip_error(ctx));
603623 *ctx->last_out = cl;
604624 ctx->last_out = &cl->next;
625
605626 ctx->redo = 1;
606627
607628 continue;
610631 ctx->redo = 0;
611632
612633 if (ctx->flush == Z_SYNC_FLUSH) {
634
613635 ctx->out_buf->flush = 0;
614636 ctx->flush = Z_NO_FLUSH;
615637
617639 ngx_http_gzip_error(ctx));
618640 *ctx->last_out = cl;
619641 ctx->last_out = &cl->next;
642
643 #if 0
620644 ctx->pass = 1;
645 #endif
621646
622647 break;
623648 }
628653 ctx->zout = 10 + ctx->zstream.total_out + 8;
629654
630655 rc = deflateEnd(&ctx->zstream);
656
631657 if (rc != Z_OK) {
632658 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
633659 "deflateEnd() failed: %d", rc);
647673 ctx->out_buf->last_buf = 1;
648674
649675 } else {
650 ngx_test_null(b, ngx_create_temp_buf(r->pool, 8),
651 ngx_http_gzip_error(ctx));
676 if (!(b = ngx_create_temp_buf(r->pool, 8))) {
677 return ngx_http_gzip_error(ctx);
678 }
652679
653680 b->last_buf = 1;
654681
679706 ctx->zstream.avail_out = 0;
680707
681708 ctx->done = 1;
709 #if 0
682710 ctx->pass = 1;
711 #endif
683712
684713 break;
685714 }
689718 ngx_http_gzip_error(ctx));
690719 *ctx->last_out = cl;
691720 ctx->last_out = &cl->next;
721
722 #if 0
692723 ctx->pass = 1;
724 #endif
693725
694726 break;
695727 }
696728 }
729
730 #if 0
731
732 /* OLD CODE */
697733
698734 if (ctx->out) {
699735 if (ctx->pass) {
703739 return last;
704740 }
705741
742 } else if (ctx->busy->buf && ngx_buf_size(ctx->busy->buf)) {
743 if (last != NGX_NONE) {
744 return last;
745 }
746
706747 } else if (ctx->blocked) {
707748 if (last != NGX_NONE) {
708749 return last;
715756
716757 return last;
717758 }
759 #endif
760
761 /* NEW CODE */
762
763 if (last == NGX_AGAIN) {
764 return NGX_AGAIN;
765 }
766
767 if (ctx->out == NULL && ctx->busy == NULL) {
768 return NGX_OK;
769 }
770
771 /**/
718772
719773 last = ngx_http_next_body_filter(r, ctx->out);
774
775 /*
776 * we do not check NGX_AGAIN here because the downstream filters
777 * may free some buffers and zlib may compress some data into them
778 */
720779
721780 if (last == NGX_ERROR) {
722781 return ngx_http_gzip_error(ctx);
872931 {
873932 ngx_http_gzip_conf_t *conf;
874933
875 ngx_test_null(conf,
876 ngx_pcalloc(cf->pool, sizeof(ngx_http_gzip_conf_t)),
877 NGX_CONF_ERROR);
878
879 /* set by ngx_pcalloc():
934 if (!(conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_gzip_conf_t)))) {
935 return NGX_CONF_ERROR;
936 }
937
938 /*
939
940 set by ngx_pcalloc():
880941
881942 conf->bufs.num = 0;
882943 conf->proxied = 0;
883944
884 */
885
945 */
886946
887947 conf->enable = NGX_CONF_UNSET;
888948 conf->no_buffer = NGX_CONF_UNSET;
889
890949
891950 conf->http_version = NGX_CONF_UNSET_UINT;
892951
932991
933992 int wbits, wsize;
934993
935
936 ngx_conf_log_error(NGX_LOG_INFO, cf, 0, "WBITS: %d", *np);
937
938994 wbits = 15;
995
939996 for (wsize = 32 * 1024; wsize > 256; wsize >>= 1) {
940997
941998 if (wsize == *np) {
942999 *np = wbits;
943 ngx_conf_log_error(NGX_LOG_INFO, cf, 0, "WBITS: %d", *np);
944 return NULL;
1000
1001 return NGX_CONF_OK;
9451002 }
9461003
9471004 wbits--;
9571014
9581015 int memlevel, hsize;
9591016
960
961 ngx_conf_log_error(NGX_LOG_INFO, cf, 0, "MEMLEVEL: %d", *np);
962
9631017 memlevel = 9;
1018
9641019 for (hsize = 128 * 1024; hsize > 256; hsize >>= 1) {
9651020
9661021 if (hsize == *np) {
9671022 *np = memlevel;
968 ngx_conf_log_error(NGX_LOG_INFO, cf, 0, "MEMLEVEL: %d", *np);
969 return NULL;
1023
1024 return NGX_CONF_OK;
9701025 }
9711026
9721027 memlevel--;
11521152
11531153 if (!r->headers_in.msie && !r->headers_in.opera) {
11541154
1155 if (ngx_strstr(user_agent, "Gecko")) {
1155 if (ngx_strstr(user_agent, "Gecko/")) {
11561156 r->headers_in.gecko = 1;
11571157
11581158 } else if (ngx_strstr(user_agent, "Konqueror")) {