Changeset afcdaf


Ignore:
Timestamp:
04/12/08 17:15:25 (4 years ago)
Author:
Tomash Brechko <tomash.brechko@…>
Branches:
master-v0.7, master-v0.6, upstream_count_limit
Children:
1233ec
Parents:
c02e6f (diff), a1f117 (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@…> (04/12/08 17:15:25)
git-committer:
Tomash Brechko <tomash.brechko@…> (04/12/08 17:15:25)
Message:

Merge branch 'memcached_hash'

Files:
12 edited

Legend:

Unmodified
Added
Removed
  • memcached_hash/ngx_http_upstream_memcached_hash_module.c

    r36e9ea ra1f117  
    170170          unsigned int scaled_total_weight = 
    171171            (memd->total_weight + memd->scale / 2) / memd->scale; 
    172           point = ((point >> 16) & 0x00007fff); 
     172          point = ((point >> 16) & 0x00007fffU); 
    173173          point = point % scaled_total_weight; 
    174174          point = ((uint64_t) point * CONTINUUM_MAX_POINT 
     
    314314          for (j = 0; j < i; ++j) 
    315315            { 
    316               memd->buckets[j].point = 
    317                 (memd->buckets[j].point 
    318                  - ((uint64_t) memd->buckets[j].point * server[i].weight 
    319                     + total_weight / 2) / total_weight); 
     316              memd->buckets[j].point -= 
     317                (uint64_t) memd->buckets[j].point * server[i].weight 
     318                / total_weight; 
    320319            } 
    321320 
  • server/src/core/ngx_regex.c

    r0019fc r5af58e  
    115115 
    116116 
     117ngx_int_t 
     118ngx_regex_exec_array(ngx_array_t *a, ngx_str_t *s, ngx_log_t *log) 
     119{ 
     120    ngx_int_t         n; 
     121    ngx_uint_t        i; 
     122    ngx_regex_elt_t  *re; 
     123 
     124    re = a->elts; 
     125 
     126    for (i = 0; i < a->nelts; i++) { 
     127 
     128        n = ngx_regex_exec(re[i].regex, s, NULL, 0); 
     129 
     130        if (n == NGX_REGEX_NO_MATCHED) { 
     131            continue; 
     132        } 
     133 
     134        if (n < 0) { 
     135            ngx_log_error(NGX_LOG_ALERT, log, 0, 
     136                          ngx_regex_exec_n " failed: %d on \"%V\" using \"%s\"", 
     137                          n, s, re[i].name); 
     138            return NGX_ERROR; 
     139        } 
     140 
     141        /* match */ 
     142 
     143        return NGX_OK; 
     144    } 
     145 
     146    return NGX_DECLINED; 
     147} 
     148 
     149 
    117150static void * ngx_libc_cdecl 
    118151ngx_regex_malloc(size_t size) 
  • server/src/core/ngx_regex.h

    r0019fc r5af58e  
    2121typedef pcre  ngx_regex_t; 
    2222 
     23typedef struct { 
     24    ngx_regex_t   *regex; 
     25    u_char        *name; 
     26} ngx_regex_elt_t; 
     27 
     28 
    2329void ngx_regex_init(void); 
    2430ngx_regex_t *ngx_regex_compile(ngx_str_t *pattern, ngx_int_t options, 
     
    2733ngx_int_t ngx_regex_exec(ngx_regex_t *re, ngx_str_t *s, int *captures, 
    2834    ngx_int_t size); 
     35ngx_int_t ngx_regex_exec_array(ngx_array_t *a, ngx_str_t *s, ngx_log_t *log); 
     36 
    2937 
    3038#define ngx_regex_exec_n           "pcre_exec()" 
  • server/src/http/modules/ngx_http_fastcgi_module.c

    r0019fc r66a597  
    180180    { ngx_string("invalid_header"), NGX_HTTP_UPSTREAM_FT_INVALID_HEADER }, 
    181181    { ngx_string("http_500"), NGX_HTTP_UPSTREAM_FT_HTTP_500 }, 
     182    { ngx_string("http_502"), NGX_HTTP_UPSTREAM_FT_HTTP_502 }, 
    182183    { ngx_string("http_503"), NGX_HTTP_UPSTREAM_FT_HTTP_503 }, 
     184    { ngx_string("http_504"), NGX_HTTP_UPSTREAM_FT_HTTP_504 }, 
     185    { ngx_string("http_507"), NGX_HTTP_UPSTREAM_FT_HTTP_507 }, 
    183186    { ngx_string("http_404"), NGX_HTTP_UPSTREAM_FT_HTTP_404 }, 
    184187    { ngx_string("off"), NGX_HTTP_UPSTREAM_FT_OFF }, 
  • server/src/http/modules/ngx_http_gzip_filter_module.c

    r0019fc r95d817  
    1515    ngx_flag_t           enable; 
    1616    ngx_flag_t           no_buffer; 
    17     ngx_flag_t           vary; 
    1817 
    1918    ngx_array_t         *types;     /* array of ngx_str_t */ 
    2019 
    2120    ngx_bufs_t           bufs; 
    22  
    23     ngx_uint_t           http_version; 
    24     ngx_uint_t           proxied; 
    2521 
    2622    ngx_int_t            level; 
     
    2925    ssize_t              min_length; 
    3026} ngx_http_gzip_conf_t; 
    31  
    32  
    33 #define NGX_HTTP_GZIP_PROXIED_OFF       0x0002 
    34 #define NGX_HTTP_GZIP_PROXIED_EXPIRED   0x0004 
    35 #define NGX_HTTP_GZIP_PROXIED_NO_CACHE  0x0008 
    36 #define NGX_HTTP_GZIP_PROXIED_NO_STORE  0x0010 
    37 #define NGX_HTTP_GZIP_PROXIED_PRIVATE   0x0020 
    38 #define NGX_HTTP_GZIP_PROXIED_NO_LM     0x0040 
    39 #define NGX_HTTP_GZIP_PROXIED_NO_ETAG   0x0080 
    40 #define NGX_HTTP_GZIP_PROXIED_AUTH      0x0100 
    41 #define NGX_HTTP_GZIP_PROXIED_ANY       0x0200 
    4227 
    4328 
     
    7156 
    7257 
    73 static ngx_int_t ngx_http_gzip_proxied(ngx_http_request_t *r, 
    74     ngx_http_gzip_conf_t *conf); 
    7558static void *ngx_http_gzip_filter_alloc(void *opaque, u_int items, 
    7659    u_int size); 
     
    10083 
    10184 
    102 static ngx_conf_enum_t  ngx_http_gzip_http_version[] = { 
    103     { ngx_string("1.0"), NGX_HTTP_VERSION_10 }, 
    104     { ngx_string("1.1"), NGX_HTTP_VERSION_11 }, 
    105     { ngx_null_string, 0 } 
    106 }; 
    107  
    108  
    109 static ngx_conf_bitmask_t  ngx_http_gzip_proxied_mask[] = { 
    110     { ngx_string("off"), NGX_HTTP_GZIP_PROXIED_OFF }, 
    111     { ngx_string("expired"), NGX_HTTP_GZIP_PROXIED_EXPIRED }, 
    112     { ngx_string("no-cache"), NGX_HTTP_GZIP_PROXIED_NO_CACHE }, 
    113     { ngx_string("no-store"), NGX_HTTP_GZIP_PROXIED_NO_STORE }, 
    114     { ngx_string("private"), NGX_HTTP_GZIP_PROXIED_PRIVATE }, 
    115     { ngx_string("no_last_modified"), NGX_HTTP_GZIP_PROXIED_NO_LM }, 
    116     { ngx_string("no_etag"), NGX_HTTP_GZIP_PROXIED_NO_ETAG }, 
    117     { ngx_string("auth"), NGX_HTTP_GZIP_PROXIED_AUTH }, 
    118     { ngx_string("any"), NGX_HTTP_GZIP_PROXIED_ANY }, 
    119     { ngx_null_string, 0 } 
    120 }; 
    121  
    122  
    12385static ngx_command_t  ngx_http_gzip_filter_commands[] = { 
    12486 
     
    173135      NULL }, 
    174136 
    175     { ngx_string("gzip_http_version"), 
    176       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, 
    177       ngx_conf_set_enum_slot, 
    178       NGX_HTTP_LOC_CONF_OFFSET, 
    179       offsetof(ngx_http_gzip_conf_t, http_version), 
    180       &ngx_http_gzip_http_version }, 
    181  
    182     { ngx_string("gzip_proxied"), 
    183       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, 
    184       ngx_conf_set_bitmask_slot, 
    185       NGX_HTTP_LOC_CONF_OFFSET, 
    186       offsetof(ngx_http_gzip_conf_t, proxied), 
    187       &ngx_http_gzip_proxied_mask }, 
    188  
    189137    { ngx_string("gzip_min_length"), 
    190138      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, 
     
    192140      NGX_HTTP_LOC_CONF_OFFSET, 
    193141      offsetof(ngx_http_gzip_conf_t, min_length), 
    194       NULL }, 
    195  
    196     { ngx_string("gzip_vary"), 
    197       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, 
    198       ngx_conf_set_flag_slot, 
    199       NGX_HTTP_LOC_CONF_OFFSET, 
    200       offsetof(ngx_http_gzip_conf_t, vary), 
    201142      NULL }, 
    202143 
     
    256197 
    257198static ngx_str_t  ngx_http_gzip_ratio = ngx_string("gzip_ratio"); 
    258 static ngx_str_t  ngx_http_gzip_no_cache = ngx_string("no-cache"); 
    259 static ngx_str_t  ngx_http_gzip_no_store = ngx_string("no-store"); 
    260 static ngx_str_t  ngx_http_gzip_private = ngx_string("private"); 
    261  
    262199 
    263200static ngx_http_output_header_filter_pt  ngx_http_next_header_filter; 
     
    268205ngx_http_gzip_header_filter(ngx_http_request_t *r) 
    269206{ 
    270     ngx_str_t             *type; 
    271     ngx_uint_t             i; 
    272     ngx_table_elt_t       *header; 
    273     ngx_http_gzip_ctx_t   *ctx; 
    274     ngx_http_gzip_conf_t  *conf; 
     207    ngx_str_t                 *type; 
     208    ngx_uint_t                 i; 
     209    ngx_table_elt_t           *h; 
     210    ngx_http_gzip_ctx_t       *ctx; 
     211    ngx_http_gzip_conf_t      *conf; 
     212    ngx_http_core_loc_conf_t  *clcf; 
    275213 
    276214    conf = ngx_http_get_module_loc_conf(r, ngx_http_gzip_filter_module); 
    277215 
    278     if (!conf->enable 
    279         || (r->headers_out.status != NGX_HTTP_OK 
    280             && r->headers_out.status != NGX_HTTP_FORBIDDEN 
    281             && r->headers_out.status != NGX_HTTP_NOT_FOUND) 
     216    if ((r->headers_out.status != NGX_HTTP_OK 
     217         && r->headers_out.status != NGX_HTTP_FORBIDDEN 
     218         && r->headers_out.status != NGX_HTTP_NOT_FOUND) 
    282219        || r->header_only 
    283         || r != r->main 
    284         || r->http_version < conf->http_version 
    285         || r->headers_out.content_type.len == 0 
    286         || (r->headers_out.content_encoding 
    287             && r->headers_out.content_encoding->value.len) 
    288         || r->headers_in.accept_encoding == NULL 
    289         || (r->headers_out.content_length_n != -1 
    290             && r->headers_out.content_length_n < conf->min_length) 
    291         || ngx_strcasestrn(r->headers_in.accept_encoding->value.data, 
    292                            "gzip", 4 - 1) 
    293            == NULL 
    294        ) 
     220        || r->headers_out.content_type.len == 0) 
    295221    { 
    296222        return ngx_http_next_header_filter(r); 
    297223    } 
    298224 
    299  
    300     type = conf->types->elts; 
    301     for (i = 0; i < conf->types->nelts; i++) { 
    302         if (r->headers_out.content_type.len >= type[i].len 
    303             && ngx_strncasecmp(r->headers_out.content_type.data, 
    304                                type[i].data, type[i].len) == 0) 
    305         { 
    306             goto found; 
    307         } 
    308     } 
    309  
    310     return ngx_http_next_header_filter(r); 
    311  
    312  
    313 found: 
    314  
    315     if (r->headers_in.via) { 
    316         if (conf->proxied & NGX_HTTP_GZIP_PROXIED_OFF) { 
    317             return ngx_http_next_header_filter(r); 
    318         } 
    319  
    320         if (!(conf->proxied & NGX_HTTP_GZIP_PROXIED_ANY) 
    321             && ngx_http_gzip_proxied(r, conf) == NGX_DECLINED) 
     225    if (!r->gunzip) { 
     226        if (!conf->enable 
     227            || (r->headers_out.content_encoding 
     228                && r->headers_out.content_encoding->value.len) 
     229            || (r->headers_out.content_length_n != -1 
     230                && r->headers_out.content_length_n < conf->min_length) 
     231            || ngx_http_gzip_ok(r) != NGX_OK) 
    322232        { 
    323233            return ngx_http_next_header_filter(r); 
    324234        } 
    325     } 
    326  
    327  
    328     /* 
    329      * if the URL (without the "http://" prefix) is longer than 253 bytes 
    330      * then MSIE 4.x can not handle the compressed stream - it waits too long, 
    331      * hangs up or crashes 
    332      */ 
    333  
    334     if (r->headers_in.msie4 && r->unparsed_uri.len > 200) { 
     235 
     236        type = conf->types->elts; 
     237        for (i = 0; i < conf->types->nelts; i++) { 
     238            if (r->headers_out.content_type.len >= type[i].len 
     239                && ngx_strncasecmp(r->headers_out.content_type.data, 
     240                                   type[i].data, type[i].len) == 0) 
     241            { 
     242                goto found; 
     243            } 
     244        } 
     245 
    335246        return ngx_http_next_header_filter(r); 
    336247    } 
     248 
     249found: 
    337250 
    338251    ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_gzip_ctx_t)); 
     
    343256    ngx_http_set_ctx(r, ctx, ngx_http_gzip_filter_module); 
    344257 
    345  
    346258    ctx->request = r; 
    347259 
    348     header = ngx_list_push(&r->headers_out.headers); 
    349     if (header == NULL) { 
    350         return NGX_ERROR; 
    351     } 
    352  
    353     header->hash = 1; 
    354     header->key.len = sizeof("Content-Encoding") - 1; 
    355     header->key.data = (u_char *) "Content-Encoding"; 
    356     header->value.len = sizeof("gzip") - 1; 
    357     header->value.data = (u_char *) "gzip"; 
    358  
    359     r->headers_out.content_encoding = header; 
    360  
    361     if (conf->vary) { 
    362         header = ngx_list_push(&r->headers_out.headers); 
    363         if (header == NULL) { 
     260    if (!r->gunzip) { 
     261        h = ngx_list_push(&r->headers_out.headers); 
     262        if (h == NULL) { 
    364263            return NGX_ERROR; 
    365264        } 
    366265 
    367         header->hash = 1; 
    368         header->key.len = sizeof("Vary") - 1; 
    369         header->key.data = (u_char *) "Vary"; 
    370         header->value.len = sizeof("Accept-Encoding") - 1; 
    371         header->value.data = (u_char *) "Accept-Encoding"; 
     266        h->hash = 1; 
     267        h->key.len = sizeof("Content-Encoding") - 1; 
     268        h->key.data = (u_char *) "Content-Encoding"; 
     269        h->value.len = sizeof("gzip") - 1; 
     270        h->value.data = (u_char *) "gzip"; 
     271 
     272        r->headers_out.content_encoding = h; 
     273 
     274        clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); 
     275 
     276        if (clcf->gzip_vary) { 
     277            h = ngx_list_push(&r->headers_out.headers); 
     278            if (h == NULL) { 
     279                return NGX_ERROR; 
     280            } 
     281 
     282            h->hash = 1; 
     283            h->key.len = sizeof("Vary") - 1; 
     284            h->key.data = (u_char *) "Vary"; 
     285            h->value.len = sizeof("Accept-Encoding") - 1; 
     286            h->value.data = (u_char *) "Accept-Encoding"; 
     287        } 
    372288    } 
    373289 
     
    380296 
    381297    return ngx_http_next_header_filter(r); 
    382 } 
    383  
    384  
    385 static ngx_int_t 
    386 ngx_http_gzip_proxied(ngx_http_request_t *r, ngx_http_gzip_conf_t *conf) 
    387 { 
    388     time_t  date, expires; 
    389  
    390     if (r->headers_in.authorization 
    391         && (conf->proxied & NGX_HTTP_GZIP_PROXIED_AUTH)) 
    392     { 
    393         return NGX_OK; 
    394     } 
    395  
    396     if (r->headers_out.expires) { 
    397  
    398         if (!(conf->proxied & NGX_HTTP_GZIP_PROXIED_EXPIRED)) { 
    399             return NGX_DECLINED; 
    400         } 
    401  
    402         expires = ngx_http_parse_time(r->headers_out.expires->value.data, 
    403                                       r->headers_out.expires->value.len); 
    404         if (expires == NGX_ERROR) { 
    405             return NGX_DECLINED; 
    406         } 
    407  
    408         if (r->headers_out.date) { 
    409             date = ngx_http_parse_time(r->headers_out.date->value.data, 
    410                                        r->headers_out.date->value.len); 
    411             if (date == NGX_ERROR) { 
    412                 return NGX_DECLINED; 
    413             } 
    414  
    415         } else { 
    416             date = ngx_time(); 
    417         } 
    418  
    419         if (expires < date) { 
    420             return NGX_OK; 
    421         } 
    422  
    423         return NGX_DECLINED; 
    424     } 
    425  
    426     if (r->headers_out.cache_control.elts) { 
    427  
    428         if ((conf->proxied & NGX_HTTP_GZIP_PROXIED_NO_CACHE) 
    429             && ngx_http_parse_multi_header_lines(&r->headers_out.cache_control, 
    430                    &ngx_http_gzip_no_cache, NULL) >= 0) 
    431         { 
    432             return NGX_OK; 
    433         } 
    434  
    435         if ((conf->proxied & NGX_HTTP_GZIP_PROXIED_NO_STORE) 
    436             && ngx_http_parse_multi_header_lines(&r->headers_out.cache_control, 
    437                    &ngx_http_gzip_no_store, NULL) >= 0) 
    438         { 
    439             return NGX_OK; 
    440         } 
    441  
    442         if ((conf->proxied & NGX_HTTP_GZIP_PROXIED_PRIVATE) 
    443             && ngx_http_parse_multi_header_lines(&r->headers_out.cache_control, 
    444                    &ngx_http_gzip_private, NULL) >= 0) 
    445         { 
    446             return NGX_OK; 
    447         } 
    448  
    449         return NGX_DECLINED; 
    450     } 
    451  
    452     if ((conf->proxied & NGX_HTTP_GZIP_PROXIED_NO_LM) 
    453         && r->headers_out.last_modified) 
    454     { 
    455         return NGX_DECLINED; 
    456     } 
    457  
    458     if ((conf->proxied & NGX_HTTP_GZIP_PROXIED_NO_ETAG) 
    459         && r->headers_out.etag) 
    460     { 
    461         return NGX_DECLINED; 
    462     } 
    463  
    464     return NGX_OK; 
    465298} 
    466299 
     
    476309    ngx_http_gzip_ctx_t   *ctx; 
    477310    ngx_http_gzip_conf_t  *conf; 
     311    const char            *method = (r->gunzip ? "inflate" : "deflate"); 
    478312 
    479313    ctx = ngx_http_get_module_ctx(r, ngx_http_gzip_filter_module); 
     
    486320 
    487321    if (ctx->preallocated == NULL) { 
    488         wbits = conf->wbits; 
     322        wbits = (!r->gunzip ? conf->wbits : 15); 
    489323        memlevel = conf->memlevel; 
    490324 
    491         if (ctx->length > 0) { 
     325        if (!r->gunzip && ctx->length > 0) { 
    492326 
    493327            /* the actual zlib window size is smaller by 262 bytes */ 
     
    524358        ctx->zstream.opaque = ctx; 
    525359 
    526         rc = deflateInit2(&ctx->zstream, (int) conf->level, Z_DEFLATED, 
    527                           -wbits, memlevel, Z_DEFAULT_STRATEGY); 
     360        if (!r->gunzip) { 
     361            rc = deflateInit2(&ctx->zstream, (int) conf->level, Z_DEFLATED, 
     362                              -wbits, memlevel, Z_DEFAULT_STRATEGY); 
     363        } else { 
     364            rc = inflateInit2(&ctx->zstream, 15 + 16); 
     365        } 
    528366 
    529367        if (rc != Z_OK) { 
    530368            ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, 
    531                           "deflateInit2() failed: %d", rc); 
     369                          "%sInit2() failed: %d", method, rc); 
    532370            ngx_http_gzip_error(ctx); 
    533371            return NGX_ERROR; 
    534372        } 
    535373 
    536         b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t)); 
    537         if (b == NULL) { 
    538             ngx_http_gzip_error(ctx); 
    539             return NGX_ERROR; 
    540         } 
    541  
    542         b->memory = 1; 
    543         b->pos = gzheader; 
    544         b->last = b->pos + 10; 
    545  
    546         out.buf = b; 
    547         out.next = NULL; 
    548  
    549         /* 
    550          * We pass the gzheader to the next filter now to avoid its linking 
    551          * to the ctx->busy chain.  zlib does not usually output the compressed 
    552          * data in the initial iterations, so the gzheader that was linked 
    553          * to the ctx->busy chain would be flushed by ngx_http_write_filter(). 
    554          */ 
    555  
    556         if (ngx_http_next_body_filter(r, &out) == NGX_ERROR) { 
    557             ngx_http_gzip_error(ctx); 
    558             return NGX_ERROR; 
     374        if (!r->gunzip) { 
     375            b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t)); 
     376            if (b == NULL) { 
     377                ngx_http_gzip_error(ctx); 
     378                return NGX_ERROR; 
     379            } 
     380 
     381            b->memory = 1; 
     382            b->pos = gzheader; 
     383            b->last = b->pos + 10; 
     384 
     385            out.buf = b; 
     386            out.next = NULL; 
     387 
     388            /* 
     389             * We pass the gzheader to the next filter now to avoid 
     390             * its linking to the ctx->busy chain.  zlib does not 
     391             * usually output the compressed data in the initial 
     392             * iterations, so the gzheader that was linked to the 
     393             * ctx->busy chain would be flushed by 
     394             * ngx_http_write_filter(). 
     395             */ 
     396 
     397            if (ngx_http_next_body_filter(r, &out) == NGX_ERROR) { 
     398                ngx_http_gzip_error(ctx); 
     399                return NGX_ERROR; 
     400            } 
     401 
     402            ctx->crc32 = crc32(0L, Z_NULL, 0); 
    559403        } 
    560404 
     
    563407        ctx->last_out = &ctx->out; 
    564408 
    565         ctx->crc32 = crc32(0L, Z_NULL, 0); 
    566409        ctx->flush = Z_NO_FLUSH; 
    567410    } 
     
    614457 
    615458                if (ctx->in_buf->last_buf) { 
    616                     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); 
    617482 
    618483                } else if (ctx->in_buf->flush) { 
     
    625490                    } 
    626491 
    627                 } else { 
     492                } else if (!r->gunzip) { 
    628493                    ctx->crc32 = crc32(ctx->crc32, ctx->zstream.next_in, 
    629494                                       ctx->zstream.avail_in); 
     
    632497 
    633498 
    634             /* is there a space for the gzipped data ? */ 
     499            /* is there a space for the output data ? */ 
    635500 
    636501            if (ctx->zstream.avail_out == 0) { 
     
    661526            } 
    662527 
    663             ngx_log_debug6(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 
    664                          "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, 
    665531                         ctx->zstream.next_in, ctx->zstream.next_out, 
    666532                         ctx->zstream.avail_in, ctx->zstream.avail_out, 
    667533                         ctx->flush, ctx->redo); 
    668534 
    669             rc = deflate(&ctx->zstream, ctx->flush); 
     535            if (!r->gunzip) { 
     536                rc = deflate(&ctx->zstream, ctx->flush); 
     537            } else { 
     538                rc = inflate(&ctx->zstream, ctx->flush); 
     539            } 
    670540 
    671541            if (rc != Z_OK && rc != Z_STREAM_END) { 
    672542                ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, 
    673                               "deflate() failed: %d, %d", ctx->flush, rc); 
     543                              "%s() failed: %d, %d", method, ctx->flush, rc); 
    674544                ngx_http_gzip_error(ctx); 
    675545                return NGX_ERROR; 
    676546            } 
    677547 
    678             ngx_log_debug5(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 
    679                            "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, 
    680551                           ctx->zstream.next_in, ctx->zstream.next_out, 
    681552                           ctx->zstream.avail_in, ctx->zstream.avail_out, 
    682553                           rc); 
    683554 
    684             ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 
    685                            "gzip in_buf:%p pos:%p", 
    686                            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); 
    687558 
    688559 
     
    697568            ctx->out_buf->last = ctx->zstream.next_out; 
    698569 
    699             if (ctx->zstream.avail_out == 0) { 
    700  
    701                 /* zlib wants to output some more gzipped data */ 
    702  
    703                 cl = ngx_alloc_chain_link(r->pool); 
    704                 if (cl == NULL) { 
    705                     ngx_http_gzip_error(ctx); 
    706                     return NGX_ERROR; 
    707                 } 
    708  
    709                 cl->buf = ctx->out_buf; 
    710                 cl->next = NULL; 
    711                 *ctx->last_out = cl; 
    712                 ctx->last_out = &cl->next; 
    713  
    714                 ctx->redo = 1; 
    715  
    716                 continue; 
    717             } 
    718  
    719570            ctx->redo = 0; 
    720571 
    721572            if (ctx->flush == Z_SYNC_FLUSH) { 
    722573 
    723                 ctx->zstream.avail_out = 0; 
    724574                ctx->out_buf->flush = 1; 
    725575                ctx->flush = Z_NO_FLUSH; 
    726576 
    727                 cl = ngx_alloc_chain_link(r->pool); 
    728                 if (cl == NULL) { 
    729                     ngx_http_gzip_error(ctx); 
    730                     return NGX_ERROR; 
    731                 } 
    732  
    733                 cl->buf = ctx->out_buf; 
    734                 cl->next = NULL; 
    735                 *ctx->last_out = cl; 
    736                 ctx->last_out = &cl->next; 
    737  
    738                 break; 
    739             } 
    740  
    741             if (rc == Z_STREAM_END) { 
    742  
    743                 ctx->zin = ctx->zstream.total_in; 
    744                 ctx->zout = 10 + ctx->zstream.total_out + 8; 
    745  
    746                 rc = deflateEnd(&ctx->zstream); 
    747  
    748                 if (rc != Z_OK) { 
    749                     ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, 
    750                                   "deflateEnd() failed: %d", rc); 
    751                     ngx_http_gzip_error(ctx); 
    752                     return NGX_ERROR; 
    753                 } 
    754  
    755                 ngx_pfree(r->pool, ctx->preallocated); 
    756  
    757                 cl = ngx_alloc_chain_link(r->pool); 
    758                 if (cl == NULL) { 
    759                     ngx_http_gzip_error(ctx); 
    760                     return NGX_ERROR; 
    761                 } 
    762  
    763                 cl->buf = ctx->out_buf; 
    764                 cl->next = NULL; 
    765                 *ctx->last_out = cl; 
    766                 ctx->last_out = &cl->next; 
    767  
    768                 if (ctx->zstream.avail_out >= 8) { 
    769                     trailer = (struct gztrailer *) ctx->out_buf->last; 
    770                     ctx->out_buf->last += 8; 
    771                     ctx->out_buf->last_buf = 1; 
    772  
    773                 } else { 
    774                     b = ngx_create_temp_buf(r->pool, 8); 
    775                     if (b == NULL) { 
    776                         ngx_http_gzip_error(ctx); 
    777                         return NGX_ERROR; 
    778                     } 
    779  
    780                     b->last_buf = 1; 
     577                /* 
     578                 * On decompression there might be not enough input 
     579                 * data to produce any output data. 
     580                 */ 
     581                if (ctx->out_buf->last > ctx->out_buf->pos) { 
     582 
     583                    ctx->zstream.avail_out = 0; 
    781584 
    782585                    cl = ngx_alloc_chain_link(r->pool); 
     
    786589                    } 
    787590 
    788                     cl->buf = b; 
     591                    cl->buf = ctx->out_buf; 
    789592                    cl->next = NULL; 
    790593                    *ctx->last_out = cl; 
    791594                    ctx->last_out = &cl->next; 
    792                     trailer = (struct gztrailer *) b->pos; 
    793                     b->last += 8; 
    794                 } 
    795  
    796 #if (NGX_HAVE_LITTLE_ENDIAN && NGX_HAVE_NONALIGNED) 
    797  
    798                 trailer->crc32 = ctx->crc32; 
    799                 trailer->zlen = ctx->zin; 
    800  
    801 #else 
    802                 trailer->crc32[0] = (u_char) (ctx->crc32 & 0xff); 
    803                 trailer->crc32[1] = (u_char) ((ctx->crc32 >> 8) & 0xff); 
    804                 trailer->crc32[2] = (u_char) ((ctx->crc32 >> 16) & 0xff); 
    805                 trailer->crc32[3] = (u_char) ((ctx->crc32 >> 24) & 0xff); 
    806  
    807                 trailer->zlen[0] = (u_char) (ctx->zin & 0xff); 
    808                 trailer->zlen[1] = (u_char) ((ctx->zin >> 8) & 0xff); 
    809                 trailer->zlen[2] = (u_char) ((ctx->zin >> 16) & 0xff); 
    810                 trailer->zlen[3] = (u_char) ((ctx->zin >> 24) & 0xff); 
    811 #endif 
    812  
    813                 ctx->zstream.avail_in = 0; 
    814                 ctx->zstream.avail_out = 0; 
    815  
    816                 ctx->done = 1; 
    817  
    818                 r->connection->buffered &= ~NGX_HTTP_GZIP_BUFFERED; 
    819  
    820                 break; 
    821             } 
    822  
    823             if (conf->no_buffer && ctx->in == NULL) { 
     595 
     596                    break; 
     597                } 
     598            } 
     599 
     600            if (rc == Z_STREAM_END) { 
     601 
     602                ctx->zin = ctx->zstream.total_in; 
     603                if (!r->gunzip) { 
     604                    ctx->zout = 10 + ctx->zstream.total_out + 8; 
     605 
     606                    rc = deflateEnd(&ctx->zstream); 
     607                } else { 
     608                    ctx->zout = ctx->zstream.total_out; 
     609 
     610                    rc = inflateEnd(&ctx->zstream); 
     611                } 
     612 
     613                if (rc != Z_OK) { 
     614                    ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, 
     615                                  "%sEnd() failed: %d", method, rc); 
     616                    ngx_http_gzip_error(ctx); 
     617                    return NGX_ERROR; 
     618                } 
     619 
     620                ngx_pfree(r->pool, ctx->preallocated); 
    824621 
    825622                cl = ngx_alloc_chain_link(r->pool); 
     
    829626                } 
    830627 
     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                } 
     639 
     640                if (!r->gunzip) { 
     641                    if (ctx->zstream.avail_out >= 8) { 
     642                        trailer = (struct gztrailer *) ctx->out_buf->last; 
     643                        ctx->out_buf->last += 8; 
     644                        ctx->out_buf->last_buf = 1; 
     645 
     646                    } else { 
     647                        b = ngx_create_temp_buf(r->pool, 8); 
     648                        if (b == NULL) { 
     649                            ngx_http_gzip_error(ctx); 
     650                            return NGX_ERROR; 
     651                        } 
     652 
     653                        b->last_buf = 1; 
     654 
     655                        cl = ngx_alloc_chain_link(r->pool); 
     656                        if (cl == NULL) { 
     657                            ngx_http_gzip_error(ctx); 
     658                            return NGX_ERROR; 
     659                        } 
     660 
     661                        cl->buf = b; 
     662                        cl->next = NULL; 
     663                        *ctx->last_out = cl; 
     664                        ctx->last_out = &cl->next; 
     665                        trailer = (struct gztrailer *) b->pos; 
     666                        b->last += 8; 
     667                    } 
     668 
     669#if (NGX_HAVE_LITTLE_ENDIAN && NGX_HAVE_NONALIGNED) 
     670 
     671                    trailer->crc32 = ctx->crc32; 
     672                    trailer->zlen = ctx->zin; 
     673 
     674#else 
     675                    trailer->crc32[0] = (u_char) (ctx->crc32 & 0xff); 
     676                    trailer->crc32[1] = (u_char) ((ctx->crc32 >> 8) & 0xff); 
     677                    trailer->crc32[2] = (u_char) ((ctx->crc32 >> 16) & 0xff); 
     678                    trailer->crc32[3] = (u_char) ((ctx->crc32 >> 24) & 0xff); 
     679 
     680                    trailer->zlen[0] = (u_char) (ctx->zin & 0xff); 
     681                    trailer->zlen[1] = (u_char) ((ctx->zin >> 8) & 0xff); 
     682                    trailer->zlen[2] = (u_char) ((ctx->zin >> 16) & 0xff); 
     683                    trailer->zlen[3] = (u_char) ((ctx->zin >> 24) & 0xff); 
     684#endif 
     685                } else { 
     686                    ctx->out_buf->last_buf = 1; 
     687                    r->gunzip = 0; 
     688                } 
     689 
     690                ctx->zstream.avail_in = 0; 
     691                ctx->zstream.avail_out = 0; 
     692 
     693                ctx->done = 1; 
     694 
     695                r->connection->buffered &= ~NGX_HTTP_GZIP_BUFFERED; 
     696 
     697                break; 
     698            } 
     699 
     700            if (ctx->zstream.avail_out == 0) { 
     701 
     702                /* zlib wants to output some more gzipped data */ 
     703 
     704                cl = ngx_alloc_chain_link(r->pool); 
     705                if (cl == NULL) { 
     706                    ngx_http_gzip_error(ctx); 
     707                    return NGX_ERROR; 
     708                } 
     709 
    831710                cl->buf = ctx->out_buf; 
    832711                cl->next = NULL; 
     
    834713                ctx->last_out = &cl->next; 
    835714 
     715                ctx->redo = 1; 
     716 
     717                continue; 
     718            } 
     719 
     720            if (conf->no_buffer && ctx->in == NULL) { 
     721 
     722                cl = ngx_alloc_chain_link(r->pool); 
     723                if (cl == NULL) { 
     724                    ngx_http_gzip_error(ctx); 
     725                    return NGX_ERROR; 
     726                } 
     727 
     728                cl->buf = ctx->out_buf; 
     729                cl->next = NULL; 
     730                *ctx->last_out = cl; 
     731                ctx->last_out = &cl->next; 
     732 
    836733                break; 
    837734            } 
     
    929826ngx_http_gzip_error(ngx_http_gzip_ctx_t *ctx) 
    930827{ 
    931     deflateEnd(&ctx->zstream); 
     828    if (! ctx->request->gunzip) { 
     829        deflateEnd(&ctx->zstream); 
     830    } else { 
     831        ctx->request->gunzip = 0; 
     832        inflateEnd(&ctx->zstream); 
     833    } 
    932834 
    933835    if (ctx->preallocated) { 
     
    1018920     * 
    1019921     *     conf->bufs.num = 0; 
    1020      *     conf->proxied = 0; 
    1021922     *     conf->types = NULL; 
    1022923     */ 
     
    1024925    conf->enable = NGX_CONF_UNSET; 
    1025926    conf->no_buffer = NGX_CONF_UNSET; 
    1026     conf->vary = NGX_CONF_UNSET; 
    1027  
    1028     conf->http_version = NGX_CONF_UNSET_UINT; 
    1029927 
    1030928    conf->level = NGX_CONF_UNSET; 
     
    1048946 
    1049947    ngx_conf_merge_bufs_value(conf->bufs, prev->bufs, 4, ngx_pagesize); 
    1050  
    1051     ngx_conf_merge_uint_value(conf->http_version, prev->http_version, 
    1052                               NGX_HTTP_VERSION_11); 
    1053     ngx_conf_merge_bitmask_value(conf->proxied, prev->proxied, 
    1054                               (NGX_CONF_BITMASK_SET|NGX_HTTP_GZIP_PROXIED_OFF)); 
    1055948 
    1056949    ngx_conf_merge_value(conf->level, prev->level, 1); 
     
    1060953    ngx_conf_merge_value(conf->min_length, prev->min_length, 20); 
    1061954    ngx_conf_merge_value(conf->no_buffer, prev->no_buffer, 0); 
    1062     ngx_conf_merge_value(conf->vary, prev->vary, 0); 
    1063955 
    1064956    if (conf->types == NULL) { 
  • server/src/http/modules/ngx_http_memcached_module.c

    r7bf8e1 r034113  
    1414    ngx_http_upstream_conf_t   upstream; 
    1515    ngx_int_t                  index; 
     16    ngx_uint_t                 gzip_flag; 
    1617    ngx_int_t                  ns_index; 
    1718} ngx_http_memcached_loc_conf_t; 
     
    100101      offsetof(ngx_http_memcached_loc_conf_t, upstream.next_upstream), 
    101102      &ngx_http_memcached_next_upstream_masks }, 
     103 
     104    { ngx_string("memcached_gzip_flag"), 
     105      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF 
     106                        |NGX_CONF_TAKE1, 
     107      ngx_conf_set_num_slot, 
     108      NGX_HTTP_LOC_CONF_OFFSET, 
     109      offsetof(ngx_http_memcached_loc_conf_t, gzip_flag), 
     110      NULL }, 
    102111 
    103112    { ngx_string("memcached_upstream_max_fails"), 
     
    318327ngx_http_memcached_process_header(ngx_http_request_t *r) 
    319328{ 
    320     u_char                    *p, *len; 
     329    u_char                    *p, *beg; 
    321330    ngx_str_t                  line; 
    322331    ngx_http_upstream_t       *u; 
    323332    ngx_http_memcached_ctx_t  *ctx; 
     333    ngx_http_memcached_loc_conf_t  *mlcf; 
     334    uint32_t                   flags; 
     335    ngx_table_elt_t           *h; 
     336    ngx_http_core_loc_conf_t  *clcf; 
    324337 
    325338    u = r->upstream; 
     
    366379        } 
    367380 
    368         /* skip flags */ 
    369  
    370         while (*p) { 
    371             if (*p++ == ' ') { 
    372                 goto length; 
    373             } 
     381        beg = p; 
     382 
     383        while (*p && *p++ != ' ') { /* void */ } 
     384 
     385        if (! *p) { 
     386            goto no_valid; 
    374387        } 
    375388 
    376         goto no_valid; 
    377  
    378     length: 
    379  
    380         len = p; 
     389        flags = ngx_atoof(beg, p - beg - 1); 
     390 
     391        beg = p; 
    381392 
    382393        while (*p && *p++ != CR) { /* void */ } 
    383394 
    384         r->headers_out.content_length_n = ngx_atoof(len, p - len - 1); 
     395        r->headers_out.content_length_n = ngx_atoof(beg, p - beg - 1); 
    385396        if (r->headers_out.content_length_n == -1) { 
    386397            ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, 
     
    389400                          &line, &ctx->key); 
    390401            return NGX_HTTP_UPSTREAM_INVALID_HEADER; 
     402        } 
     403 
     404        mlcf = ngx_http_get_module_loc_conf(r, ngx_http_memcached_module); 
     405 
     406        if (flags & mlcf->gzip_flag) { 
     407#if (NGX_HTTP_GZIP) 
     408            clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); 
     409 
     410            if (ngx_http_gzip_ok(r) == NGX_OK) { 
     411                h = ngx_list_push(&r->headers_out.headers); 
     412                if (h == NULL) { 
     413                    return NGX_ERROR; 
     414                } 
     415 
     416                h->hash = 1; 
     417                h->key.len = sizeof("Content-Encoding") - 1; 
     418                h->key.data = (u_char *) "Content-Encoding"; 
     419                h->value.len = sizeof("gzip") - 1; 
     420                h->value.data = (u_char *) "gzip"; 
     421 
     422                r->headers_out.content_encoding = h; 
     423 
     424                if (clcf->gzip_vary) { 
     425                    h = ngx_list_push(&r->headers_out.headers); 
     426                    if (h == NULL) { 
     427                        return NGX_ERROR; 
     428                    } 
     429 
     430                    h->hash = 1; 
     431                    h->key.len = sizeof("Vary") - 1; 
     432                    h->key.data = (u_char *) "Vary"; 
     433                    h->value.len = sizeof("Accept-Encoding") - 1; 
     434                    h->value.data = (u_char *) "Accept-Encoding"; 
     435                } 
     436            } else { 
     437                if (clcf->gunzip) { 
     438                    r->gunzip = 1; 
     439                } else { 
     440#endif 
     441                    /* 
     442                     * If the client can't accept compressed data, and 
     443                     * automatic decompression is not enabled, we 
     444                     * return 404 in the hope that the next upstream 
     445                     * will return uncompressed data. 
     446                     */ 
     447                    u->headers_in.status_n = 404; 
     448                    u->state->status = 404; 
     449 
     450                    return NGX_OK; 
     451#if (NGX_HTTP_GZIP) 
     452                } 
     453            } 
     454#endif 
    391455        } 
    392456 
     
    554618    conf->upstream.buffer_size = NGX_CONF_UNSET_SIZE; 
    555619 
     620    conf->gzip_flag = NGX_CONF_UNSET_UINT; 
     621 
    556622    /* the hardcoded values */ 
    557623    conf->upstream.cyclic_temp_file = 0; 
     
    597663                               |NGX_HTTP_UPSTREAM_FT_TIMEOUT)); 
    598664 
     665    ngx_conf_merge_uint_value(conf->gzip_flag, 
     666                              prev->gzip_flag, 0); 
     667 
    599668    if (conf->upstream.next_upstream & NGX_HTTP_UPSTREAM_FT_OFF) { 
    600669        conf->upstream.next_upstream = NGX_CONF_BITMASK_SET 
  • server/src/http/modules/ngx_http_proxy_module.c

    ra64318 r66a597  
    134134    { ngx_string("invalid_header"), NGX_HTTP_UPSTREAM_FT_INVALID_HEADER }, 
    135135    { ngx_string("http_500"), NGX_HTTP_UPSTREAM_FT_HTTP_500 }, 
     136    { ngx_string("http_502"), NGX_HTTP_UPSTREAM_FT_HTTP_502 }, 
    136137    { ngx_string("http_503"), NGX_HTTP_UPSTREAM_FT_HTTP_503 }, 
     138    { ngx_string("http_504"), NGX_HTTP_UPSTREAM_FT_HTTP_504 }, 
     139    { ngx_string("http_507"), NGX_HTTP_UPSTREAM_FT_HTTP_507 }, 
    137140    { ngx_string("http_404"), NGX_HTTP_UPSTREAM_FT_HTTP_404 }, 
    138141    { ngx_string("off"), NGX_HTTP_UPSTREAM_FT_OFF }, 
  • server/src/http/ngx_http_core_module.c

    r0019fc r88f48a  
    6868static char *ngx_http_core_internal(ngx_conf_t *cf, ngx_command_t *cmd, 
    6969    void *conf); 
     70#if (NGX_HTTP_GZIP) 
     71static char *ngx_http_gzip_disable(ngx_conf_t *cf, ngx_command_t *cmd, 
     72    void *conf); 
     73#endif 
    7074 
    7175static char *ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data); 
     
    9195 
    9296 
     97#if (NGX_HTTP_GZIP) 
     98 
     99static ngx_conf_enum_t  ngx_http_gzip_http_version[] = { 
     100    { ngx_string("1.0"), NGX_HTTP_VERSION_10 }, 
     101    { ngx_string("1.1"), NGX_HTTP_VERSION_11 }, 
     102    { ngx_null_string, 0 } 
     103}; 
     104 
     105 
     106static ngx_conf_bitmask_t  ngx_http_gzip_proxied_mask[] = { 
     107    { ngx_string("off"), NGX_HTTP_GZIP_PROXIED_OFF }, 
     108    { ngx_string("expired"), NGX_HTTP_GZIP_PROXIED_EXPIRED }, 
     109    { ngx_string("no-cache"), NGX_HTTP_GZIP_PROXIED_NO_CACHE }, 
     110    { ngx_string("no-store"), NGX_HTTP_GZIP_PROXIED_NO_STORE }, 
     111    { ngx_string("private"), NGX_HTTP_GZIP_PROXIED_PRIVATE }, 
     112    { ngx_string("no_last_modified"), NGX_HTTP_GZIP_PROXIED_NO_LM }, 
     113    { ngx_string("no_etag"), NGX_HTTP_GZIP_PROXIED_NO_ETAG }, 
     114    { ngx_string("auth"), NGX_HTTP_GZIP_PROXIED_AUTH }, 
     115    { ngx_string("any"), NGX_HTTP_GZIP_PROXIED_ANY }, 
     116    { ngx_null_string, 0 } 
     117}; 
     118 
     119 
     120static ngx_str_t  ngx_http_gzip_no_cache = ngx_string("no-cache"); 
     121static ngx_str_t  ngx_http_gzip_no_store = ngx_string("no-store"); 
     122static ngx_str_t  ngx_http_gzip_private = ngx_string("private"); 
     123 
     124#endif 
     125 
     126 
    93127static ngx_command_t  ngx_http_core_commands[] = { 
    94128 
     
    470504      NGX_HTTP_LOC_CONF_OFFSET, 
    471505      offsetof(ngx_http_core_loc_conf_t, open_files), 
     506      NULL }, 
     507 
     508#endif 
     509 
     510#if (NGX_HTTP_GZIP) 
     511 
     512    { ngx_string("gzip_vary"), 
     513      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, 
     514      ngx_conf_set_flag_slot, 
     515      NGX_HTTP_LOC_CONF_OFFSET, 
     516      offsetof(ngx_http_core_loc_conf_t, gzip_vary), 
     517      NULL }, 
     518 
     519    { ngx_string("gzip_http_version"), 
     520      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, 
     521      ngx_conf_set_enum_slot, 
     522      NGX_HTTP_LOC_CONF_OFFSET, 
     523      offsetof(ngx_http_core_loc_conf_t, gzip_http_version), 
     524      &ngx_http_gzip_http_version }, 
     525 
     526    { ngx_string("gzip_proxied"), 
     527      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, 
     528      ngx_conf_set_bitmask_slot, 
     529      NGX_HTTP_LOC_CONF_OFFSET, 
     530      offsetof(ngx_http_core_loc_conf_t, gzip_proxied), 
     531      &ngx_http_gzip_proxied_mask }, 
     532 
     533    { ngx_string("gzip_disable"), 
     534      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, 
     535      ngx_http_gzip_disable, 
     536      NGX_HTTP_LOC_CONF_OFFSET, 
     537      0, 
     538      NULL }, 
     539 
     540    { ngx_string("gunzip"), 
     541      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF 
     542                        |NGX_CONF_FLAG, 
     543      ngx_conf_set_flag_slot, 
     544      NGX_HTTP_LOC_CONF_OFFSET, 
     545      offsetof(ngx_http_core_loc_conf_t, gunzip), 
    472546      NULL }, 
    473547 
     
    566640 
    567641    r->valid_location = 1; 
     642    r->gzip = 0; 
     643    r->gunzip = 0; 
    568644 
    569645    r->write_event_handler = ngx_http_core_run_phases; 
     
    13491425    return NGX_OK; 
    13501426} 
     1427 
     1428 
     1429#if (NGX_HTTP_GZIP) 
     1430 
     1431ngx_int_t 
     1432ngx_http_gzip_ok(ngx_http_request_t *r) 
     1433{ 
     1434    time_t                     date, expires; 
     1435    ngx_uint_t                 p; 
     1436    ngx_array_t               *cc; 
     1437    ngx_table_elt_t           *e, *d; 
     1438    ngx_http_core_loc_conf_t  *clcf; 
     1439 
     1440    if (r->gzip == 1) { 
     1441        return NGX_OK; 
     1442    } 
     1443 
     1444    if (r->gzip == 2) { 
     1445        return NGX_DECLINED; 
     1446    } 
     1447 
     1448    r->gzip = 2; 
     1449 
     1450    if (r != r->main 
     1451        || r->headers_in.accept_encoding == NULL 
     1452        || ngx_strcasestrn(r->headers_in.accept_encoding->value.data, 
     1453                           "gzip", 4 - 1) 
     1454           == NULL 
     1455 
     1456        /* 
     1457         * if the URL (without the "http://" prefix) is longer than 253 bytes, 
     1458         * then MSIE 4.x can not handle the compressed stream - it waits 
     1459         * too long, hangs up or crashes 
     1460         */ 
     1461 
     1462        || (r->headers_in.msie4 && r->unparsed_uri.len > 200)) 
     1463    { 
     1464        return NGX_DECLINED; 
     1465    } 
     1466 
     1467    clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); 
     1468 
     1469    if (r->http_version < clcf->gzip_http_version) { 
     1470        return NGX_DECLINED; 
     1471    } 
     1472 
     1473    if (r->headers_in.via == NULL) { 
     1474        goto ok; 
     1475    } 
     1476 
     1477    p = clcf->gzip_proxied; 
     1478 
     1479    if (p & NGX_HTTP_GZIP_PROXIED_OFF) { 
     1480        return NGX_DECLINED; 
     1481    } 
     1482 
     1483    if (p & NGX_HTTP_GZIP_PROXIED_ANY) { 
     1484        goto ok; 
     1485    } 
     1486 
     1487    if (r->headers_in.authorization && (p & NGX_HTTP_GZIP_PROXIED_AUTH)) { 
     1488        goto ok; 
     1489    } 
     1490 
     1491    e = r->headers_out.expires; 
     1492 
     1493    if (e) { 
     1494 
     1495        if (!(p & NGX_HTTP_GZIP_PROXIED_EXPIRED)) { 
     1496            return NGX_DECLINED; 
     1497        } 
     1498 
     1499        expires = ngx_http_parse_time(e->value.data, e->value.len); 
     1500        if (expires == NGX_ERROR) { 
     1501            return NGX_DECLINED; 
     1502        } 
     1503 
     1504        d = r->headers_out.date; 
     1505 
     1506        if (d) { 
     1507            date = ngx_http_parse_time(d->value.data, d->value.len); 
     1508            if (date == NGX_ERROR) { 
     1509                return NGX_DECLINED; 
     1510            } 
     1511 
     1512        } else { 
     1513            date = ngx_time(); 
     1514        } 
     1515 
     1516        if (expires < date) { 
     1517            goto ok; 
     1518        } 
     1519 
     1520        return NGX_DECLINED; 
     1521    } 
     1522 
     1523    cc = &r->headers_out.cache_control; 
     1524 
     1525    if (cc->elts) { 
     1526 
     1527        if ((p & NGX_HTTP_GZIP_PROXIED_NO_CACHE) 
     1528            && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_no_cache, 
     1529                                                 NULL) 
     1530               >= 0) 
     1531        { 
     1532            goto ok; 
     1533        } 
     1534 
     1535        if ((p & NGX_HTTP_GZIP_PROXIED_NO_STORE) 
     1536            && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_no_store, 
     1537                                                 NULL) 
     1538               >= 0) 
     1539        { 
     1540            goto ok; 
     1541        } 
     1542 
     1543        if ((p & NGX_HTTP_GZIP_PROXIED_PRIVATE) 
     1544            && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_private, 
     1545                                                 NULL) 
     1546               >= 0) 
     1547        { 
     1548            goto ok; 
     1549        } 
     1550 
     1551        return NGX_DECLINED; 
     1552    } 
     1553 
     1554    if ((p & NGX_HTTP_GZIP_PROXIED_NO_LM) && r->headers_out.last_modified) { 
     1555        return NGX_DECLINED; 
     1556    } 
     1557 
     1558    if ((p & NGX_HTTP_GZIP_PROXIED_NO_ETAG) && r->headers_out.etag) { 
     1559        return NGX_DECLINED; 
     1560    } 
     1561 
     1562ok: 
     1563 
     1564#if (NGX_PCRE) 
     1565 
     1566    if (clcf->gzip_disable && r->headers_in.user_agent) { 
     1567 
     1568        if (ngx_regex_exec_array(clcf->gzip_disable,  
     1569                                 &r->headers_in.user_agent->value, 
     1570                                 r->connection->log) 
     1571            != NGX_DECLINED) 
     1572        { 
     1573            return NGX_DECLINED; 
     1574        } 
     1575    } 
     1576 
     1577#endif 
     1578 
     1579    r->gzip = 1; 
     1580 
     1581    return NGX_OK; 
     1582} 
     1583 
     1584#endif 
    13511585 
    13521586 
     
    23522586     *     lcf->auto_redirect = 0; 
    23532587     *     lcf->alias = 0; 
     2588     *     lcf->gzip_proxied = 0; 
    23542589     */ 
    23552590 
     
    23822617    lcf->types_hash_bucket_size = NGX_CONF_UNSET_UINT; 
    23832618 
     2619#if (NGX_HTTP_GZIP) 
     2620    lcf->gzip_vary = NGX_CONF_UNSET; 
     2621    lcf->gzip_http_version = NGX_CONF_UNSET_UINT; 
     2622    lcf->gzip_disable = NGX_CONF_UNSET_PTR; 
     2623    lcf->gunzip = NGX_CONF_UNSET; 
     2624#endif 
     2625 
    23842626    return lcf; 
    23852627} 
     
    25682810        conf->open_files = prev->open_files; 
    25692811    } 
     2812 
     2813#if (NGX_HTTP_GZIP) 
     2814 
     2815    ngx_conf_merge_value(conf->gzip_vary, prev->gzip_vary, 0); 
     2816    ngx_conf_merge_value(conf->gunzip, prev->gunzip, 0); 
     2817    ngx_conf_merge_uint_value(conf->gzip_http_version, prev->gzip_http_version, 
     2818                              NGX_HTTP_VERSION_11); 
     2819    ngx_conf_merge_bitmask_value(conf->gzip_proxied, prev->gzip_proxied, 
     2820                              (NGX_CONF_BITMASK_SET|NGX_HTTP_GZIP_PROXIED_OFF)); 
     2821 
     2822    ngx_conf_merge_ptr_value(conf->gzip_disable, prev->gzip_disable, NULL); 
     2823 
     2824#endif 
    25702825 
    25712826    return NGX_CONF_OK; 
     
    32533508 
    32543509 
     3510#if (NGX_HTTP_GZIP) 
     3511 
     3512static char * 
     3513ngx_http_gzip_disable(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 
     3514{ 
     3515#if (NGX_PCRE) 
     3516    ngx_http_core_loc_conf_t  *clcf = conf; 
     3517 
     3518    ngx_str_t         err, *value; 
     3519    ngx_uint_t        i; 
     3520    ngx_regex_elt_t  *re; 
     3521    u_char            errstr[NGX_MAX_CONF_ERRSTR]; 
     3522 
     3523    if (clcf->gzip_disable == NGX_CONF_UNSET_PTR) { 
     3524        clcf->gzip_disable = ngx_array_create(cf->pool, 2, 
     3525                                              sizeof(ngx_regex_elt_t)); 
     3526        if (clcf->gzip_disable == NULL) { 
     3527            return NGX_CONF_ERROR; 
     3528        } 
     3529    } 
     3530 
     3531    value = cf->args->elts; 
     3532 
     3533    err.len = NGX_MAX_CONF_ERRSTR; 
     3534    err.data = errstr; 
     3535 
     3536    for (i = 1; i < cf->args->nelts; i++) { 
     3537 
     3538        re = ngx_array_push(clcf->gzip_disable); 
     3539        if (re == NULL) { 
     3540            return NGX_CONF_ERROR; 
     3541        } 
     3542 
     3543        re->regex = ngx_regex_compile(&value[i], NGX_REGEX_CASELESS, cf->pool, 
     3544                                      &err); 
     3545 
     3546        if (re->regex == NULL) { 
     3547            ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data); 
     3548            return NGX_CONF_ERROR; 
     3549        } 
     3550 
     3551        re->name = value[i].data; 
     3552    } 
     3553 
     3554    return NGX_CONF_OK; 
     3555 
     3556#else 
     3557    ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 
     3558                       "\"gzip_disable\" requires PCRE library"); 
     3559 
     3560    return NGX_CONF_ERROR; 
     3561#endif 
     3562} 
     3563 
     3564#endif 
     3565 
     3566 
    32553567static char * 
    32563568ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data) 
  • server/src/http/ngx_http_core_module.h

    r0019fc r233310  
    1212#include <ngx_array.h> 
    1313#include <ngx_http.h> 
     14 
     15 
     16#define NGX_HTTP_GZIP_PROXIED_OFF       0x0002 
     17#define NGX_HTTP_GZIP_PROXIED_EXPIRED   0x0004 
     18#define NGX_HTTP_GZIP_PROXIED_NO_CACHE  0x0008 
     19#define NGX_HTTP_GZIP_PROXIED_NO_STORE  0x0010 
     20#define NGX_HTTP_GZIP_PROXIED_PRIVATE   0x0020 
     21#define NGX_HTTP_GZIP_PROXIED_NO_LM     0x0040 
     22#define NGX_HTTP_GZIP_PROXIED_NO_ETAG   0x0080 
     23#define NGX_HTTP_GZIP_PROXIED_AUTH      0x0100 
     24#define NGX_HTTP_GZIP_PROXIED_ANY       0x0200 
    1425 
    1526 
     
    288299    ngx_flag_t    server_tokens;           /* server_tokens */ 
    289300 
     301#if (NGX_HTTP_GZIP) 
     302    ngx_flag_t    gzip_vary;               /* gzip_vary */ 
     303 
     304    ngx_uint_t    gzip_http_version;       /* gzip_http_version */ 
     305    ngx_uint_t    gzip_proxied;            /* gzip_proxied */ 
     306    ngx_flag_t    gunzip; 
     307 
     308#if (NGX_PCRE) 
     309    ngx_array_t  *gzip_disable;            /* gzip_disable */ 
     310#endif 
     311#endif 
     312 
    290313    ngx_array_t  *error_pages;             /* error_page */ 
    291314 
     
    324347    size_t *root_length, size_t reserved); 
    325348ngx_int_t ngx_http_auth_basic_user(ngx_http_request_t *r); 
     349#if (NGX_HTTP_GZIP) 
     350ngx_int_t ngx_http_gzip_ok(ngx_http_request_t *r); 
     351#endif 
     352 
    326353 
    327354ngx_int_t ngx_http_subrequest(ngx_http_request_t *r, 
  • server/src/http/ngx_http_request.h

    ra64318 r233310  
    429429 
    430430    unsigned                          header_timeout_set:1; 
     431 
     432    unsigned                          gzip:2; 
     433    unsigned                          gunzip:1; 
    431434 
    432435    unsigned                          proxy:1; 
  • server/src/http/ngx_http_upstream.c

    rde9561 r445d49  
    10941094    } 
    10951095 
     1096    if (u->headers_in.status_n == NGX_HTTP_BAD_GATEWAY) { 
     1097 
     1098        if (u->peer.tries > 1 
     1099            && u->conf->next_upstream & NGX_HTTP_UPSTREAM_FT_HTTP_502) 
     1100        { 
     1101            ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_HTTP_502); 
     1102            return; 
     1103        } 
     1104    } 
     1105 
     1106    if (u->headers_in.status_n == NGX_HTTP_SERVICE_UNAVAILABLE) { 
     1107 
     1108        if (u->peer.tries > 1 
     1109            && u->conf->next_upstream & NGX_HTTP_UPSTREAM_FT_HTTP_503) 
     1110        { 
     1111            ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_HTTP_503); 
     1112            return; 
     1113        } 
     1114    } 
     1115 
     1116    if (u->headers_in.status_n == NGX_HTTP_GATEWAY_TIME_OUT) { 
     1117 
     1118        if (u->peer.tries > 1 
     1119            && u->conf->next_upstream & NGX_HTTP_UPSTREAM_FT_HTTP_504) 
     1120        { 
     1121            ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_HTTP_504); 
     1122            return; 
     1123        } 
     1124    } 
     1125 
     1126    if (u->headers_in.status_n == NGX_HTTP_INSUFFICIENT_STORAGE) { 
     1127 
     1128        if (u->peer.tries > 1 
     1129            && u->conf->next_upstream & NGX_HTTP_UPSTREAM_FT_HTTP_507) 
     1130        { 
     1131            ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_HTTP_507); 
     1132            return; 
     1133        } 
     1134    } 
    10961135 
    10971136    if (u->headers_in.status_n >= NGX_HTTP_BAD_REQUEST 
     
    21732212        switch(ft_type) { 
    21742213 
     2214        case NGX_HTTP_UPSTREAM_FT_HTTP_504: 
    21752215        case NGX_HTTP_UPSTREAM_FT_TIMEOUT: 
    21762216            status = NGX_HTTP_GATEWAY_TIME_OUT; 
     
    21832223        case NGX_HTTP_UPSTREAM_FT_HTTP_404: 
    21842224            status = NGX_HTTP_NOT_FOUND; 
     2225            break; 
     2226 
     2227        case NGX_HTTP_UPSTREAM_FT_HTTP_502: 
     2228            status = NGX_HTTP_BAD_GATEWAY; 
     2229            break; 
     2230 
     2231        case NGX_HTTP_UPSTREAM_FT_HTTP_503: 
     2232            status = NGX_HTTP_SERVICE_UNAVAILABLE; 
     2233            break; 
     2234 
     2235        case NGX_HTTP_UPSTREAM_FT_HTTP_507: 
     2236            status = NGX_HTTP_INSUFFICIENT_STORAGE; 
    21852237            break; 
    21862238 
  • server/src/http/ngx_http_upstream.h

    rde9561 r445d49  
    2525#define NGX_HTTP_UPSTREAM_FT_BUSY_LOCK       0x00000080 
    2626#define NGX_HTTP_UPSTREAM_FT_MAX_WAITING     0x00000100 
     27#define NGX_HTTP_UPSTREAM_FT_HTTP_502        0x00000200 
     28#define NGX_HTTP_UPSTREAM_FT_HTTP_504        0x00000400 
     29#define NGX_HTTP_UPSTREAM_FT_HTTP_507        0x00000800 
    2730#define NGX_HTTP_UPSTREAM_FT_OFF             0x80000000 
    2831 
Note: See TracChangeset for help on using the changeset viewer.