Changeset c79fa6


Ignore:
Timestamp:
02/19/08 16:28:06 (4 years ago)
Author:
Tomash Brechko <tomash.brechko@…>
Branches:
master-v0.7, master-v0.6, upstream_count_limit
Children:
034113
Parents:
2a12f7 (diff), 2340f0 (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/19/08 16:28:06)
git-committer:
Tomash Brechko <tomash.brechko@…> (02/19/08 16:28:06)
Message:

Merge branch 'memcached_hash'

Files:
16 edited

Legend:

Unmodified
Added
Removed
  • memcached_hash/Changes

    r432a6a r2340f0  
    11Revision history of ngx_http_upstream_memcached_hash_module. 
     2 
     3 
     40.02  2008-02-19 
     5        - add support for $memcached_namespace variable. 
     6 
     7        If Cache::Memcached::Fast uses 
     8 
     9           namespace => 'prefix', 
     10 
     11        then nginx configuration file should have 
     12 
     13          set $memcached_namespace "prefix"; 
     14 
     15        This is not the same as prepending "prefix" to $memcached_key: 
     16        namespace prefix should not be hashed. 
    217 
    318 
  • memcached_hash/README

    r1e6e0c r2340f0  
    1 ngx_http_upstream_memcached_hash_module 0.01 
     1ngx_http_upstream_memcached_hash_module 0.02 
    22============================================ 
    33 
     
    8585      location / { 
    8686          set             $memcached_key   "$uri$is_args$args"; 
     87          set             $memcached_namespace   "prefix"; 
    8788          memcached_pass  memcached_cluster; 
    8889          error_page      404 502 504 = @fallback; 
     
    169170supports only integer weights and does not support consistent hashing. 
    170171 
     172If the client uses a namespace, i.e. constructor has 
     173 
     174  namespace => 'prefix', 
     175 
     176then you have to set $memcached_namespace variable in nginx 
     177configuration file: 
     178 
     179  set  $memcached_namespace  "prefix"; 
     180 
     181Note that this is not the same as prepending prefix to $memcached_key: 
     182namespace prefix is not hashed when the key is hashed to decide which 
     183memcached server to talk to. 
     184 
    171185Also note that nginx escapes an URI key before sending the request to 
    172186memcached.  As of this writing the transformation is equivalent to the 
  • memcached_hash/TODO

    r7fe430 r2340f0  
    1 - Comment the code, especially integer computations. 
    2  
    3 - Add gzip support. 
    4  
    51- Add populate.pl to the distribution. 
    62 
  • memcached_hash/ngx_http_upstream_memcached_hash_module.c

    r7fe430 r030d22  
    77  source code. 
    88 
    9   Version 0.01. 
     9  Version 0.02. 
    1010*/ 
    1111 
     
    1616 
    1717#define CONTINUUM_MAX_POINT  0xffffffffU 
     18 
     19 
     20static ngx_str_t memcached_ns = ngx_string("memcached_namespace"); 
    1821 
    1922 
     
    4346  unsigned int ketama_points; 
    4447  unsigned int scale; 
     48  ngx_int_t ns_index; 
    4549}; 
    4650 
     
    5054  struct memcached_hash *memd; 
    5155  ngx_http_upstream_server_t *server; 
    52   ngx_chain_t **request_bufs; 
     56  ngx_http_request_t *request; 
    5357}; 
    5458 
     
    133137  else 
    134138    { 
     139      ngx_chain_t *request_bufs = find_ctx->request->upstream->request_bufs; 
     140      ngx_http_variable_value_t *ns_vv = 
     141        ngx_http_get_indexed_variable(find_ctx->request, memd->ns_index); 
     142 
    135143      /* 
    136144        We take the key directly from request_buf, because there it is 
    137145        in the escaped form that will be seen by memcached server. 
    138146      */ 
    139       key = (*find_ctx->request_bufs)->buf->start + (sizeof("get ") - 1); 
    140       len = (((*find_ctx->request_bufs)->buf->last - key) 
    141              - (sizeof("\r\n") - 1)); 
     147      key = request_bufs->buf->start + (sizeof("get ") - 1); 
     148      if (ns_vv && ! ns_vv->not_found && ns_vv->len != 0) 
     149        { 
     150          key += ns_vv->len + 2 * ngx_escape_uri(NULL, ns_vv->data, ns_vv->len, 
     151                                                 NGX_ESCAPE_MEMCACHED); 
     152        } 
     153         
     154      len = request_bufs->buf->last - key - (sizeof("\r\n") - 1); 
    142155 
    143156      point = ngx_crc32_long(key, len); 
     
    218231    return NGX_ERROR; 
    219232  find_ctx->memd = memd; 
    220   find_ctx->request_bufs = &r->upstream->request_bufs; 
     233  find_ctx->request = r; 
    221234  find_ctx->server = us->servers->elts; 
    222235 
     
    454467  memd->ketama_points = ketama_points; 
    455468  memd->scale = scale; 
     469  memd->ns_index = ngx_http_get_variable_index(cf, &memcached_ns); 
     470 
     471  if (memd->ns_index == NGX_ERROR) { 
     472      return NGX_CONF_ERROR; 
     473  } 
    456474 
    457475  uscf->peer.data = memd; 
  • 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

    re1c857 rc79fa6  
    1515    ngx_int_t                  index; 
    1616    ngx_uint_t                 gzip_flag; 
     17    ngx_int_t                  ns_index; 
    1718} ngx_http_memcached_loc_conf_t; 
    1819 
     
    158159 
    159160static ngx_str_t  ngx_http_memcached_key = ngx_string("memcached_key"); 
     161static ngx_str_t  ngx_http_memcached_ns = ngx_string("memcached_namespace"); 
    160162 
    161163 
     
    235237{ 
    236238    size_t                          len; 
    237     uintptr_t                       escape; 
     239    uintptr_t                       escape, ns_escape = 0; 
    238240    ngx_buf_t                      *b; 
    239241    ngx_chain_t                    *cl; 
    240242    ngx_http_memcached_ctx_t       *ctx; 
    241     ngx_http_variable_value_t      *vv; 
     243    ngx_http_variable_value_t      *vv, *ns_vv; 
    242244    ngx_http_memcached_loc_conf_t  *mlcf; 
    243245 
     
    254256    escape = 2 * ngx_escape_uri(NULL, vv->data, vv->len, NGX_ESCAPE_MEMCACHED); 
    255257 
    256     len = sizeof("get ") - 1 + vv->len + escape + sizeof(CRLF) - 1; 
     258    ns_vv = ngx_http_get_indexed_variable(r, mlcf->ns_index); 
     259 
     260    if (ns_vv != NULL && !ns_vv->not_found && ns_vv->len != 0) { 
     261        ns_escape = 2 * ngx_escape_uri(NULL, ns_vv->data, 
     262                                       ns_vv->len, NGX_ESCAPE_MEMCACHED); 
     263    } 
     264 
     265    len = sizeof("get ") - 1 + ns_vv->len + ns_escape 
     266                             + vv->len + escape + sizeof(CRLF) - 1; 
    257267 
    258268    b = ngx_create_temp_buf(r->pool, len); 
     
    276286 
    277287    ctx->key.data = b->last; 
     288 
     289    if (ns_vv != NULL && !ns_vv->not_found && ns_vv->len != 0) { 
     290        if (ns_escape == 0) { 
     291            b->last = ngx_copy(b->last, ns_vv->data, ns_vv->len); 
     292        } else { 
     293            b->last = (u_char *) ngx_escape_uri(b->last, ns_vv->data, 
     294                                                ns_vv->len, 
     295                                                NGX_ESCAPE_MEMCACHED); 
     296        } 
     297    } 
    278298 
    279299    if (escape == 0) { 
     
    588608     * 
    589609     *     conf->index = 0; 
     610     *     conf->ns_index = 0; 
    590611     */ 
    591612 
     
    697718    } 
    698719 
     720    lcf->ns_index = ngx_http_get_variable_index(cf, &ngx_http_memcached_ns); 
     721 
     722    if (lcf->ns_index == NGX_ERROR) { 
     723        return NGX_CONF_ERROR; 
     724    } 
     725 
    699726    return NGX_CONF_OK; 
    700727} 
  • 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 r233310  
    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_CONF_FLAG, 
     542      ngx_conf_set_flag_slot, 
     543      NGX_HTTP_LOC_CONF_OFFSET, 
     544      offsetof(ngx_http_core_loc_conf_t, gunzip), 
    472545      NULL }, 
    473546 
     
    566639 
    567640    r->valid_location = 1; 
     641    r->gzip = 0; 
     642    r->gunzip = 0; 
    568643 
    569644    r->write_event_handler = ngx_http_core_run_phases; 
     
    13491424    return NGX_OK; 
    13501425} 
     1426 
     1427 
     1428#if (NGX_HTTP_GZIP) 
     1429 
     1430ngx_int_t 
     1431ngx_http_gzip_ok(ngx_http_request_t *r) 
     1432{ 
     1433    time_t                     date, expires; 
     1434    ngx_uint_t                 p; 
     1435    ngx_array_t               *cc; 
     1436    ngx_table_elt_t           *e, *d; 
     1437    ngx_http_core_loc_conf_t  *clcf; 
     1438 
     1439    if (r->gzip == 1) { 
     1440        return NGX_OK; 
     1441    } 
     1442 
     1443    if (r->gzip == 2) { 
     1444        return NGX_DECLINED; 
     1445    } 
     1446 
     1447    r->gzip = 2; 
     1448 
     1449    if (r != r->main 
     1450        || r->headers_in.accept_encoding == NULL 
     1451        || ngx_strcasestrn(r->headers_in.accept_encoding->value.data, 
     1452                           "gzip", 4 - 1) 
     1453           == NULL 
     1454 
     1455        /* 
     1456         * if the URL (without the "http://" prefix) is longer than 253 bytes, 
     1457         * then MSIE 4.x can not handle the compressed stream - it waits 
     1458         * too long, hangs up or crashes 
     1459         */ 
     1460 
     1461        || (r->headers_in.msie4 && r->unparsed_uri.len > 200)) 
     1462    { 
     1463        return NGX_DECLINED; 
     1464    } 
     1465 
     1466    clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); 
     1467 
     1468    if (r->http_version < clcf->gzip_http_version) { 
     1469        return NGX_DECLINED; 
     1470    } 
     1471 
     1472    if (r->headers_in.via == NULL) { 
     1473        goto ok; 
     1474    } 
     1475 
     1476    p = clcf->gzip_proxied; 
     1477 
     1478    if (p & NGX_HTTP_GZIP_PROXIED_OFF) { 
     1479        return NGX_DECLINED; 
     1480    } 
     1481 
     1482    if (p & NGX_HTTP_GZIP_PROXIED_ANY) { 
     1483        goto ok; 
     1484    } 
     1485 
     1486    if (r->headers_in.authorization && (p & NGX_HTTP_GZIP_PROXIED_AUTH)) { 
     1487        goto ok; 
     1488    } 
     1489 
     1490    e = r->headers_out.expires; 
     1491 
     1492    if (e) { 
     1493 
     1494        if (!(p & NGX_HTTP_GZIP_PROXIED_EXPIRED)) { 
     1495            return NGX_DECLINED; 
     1496        } 
     1497 
     1498        expires = ngx_http_parse_time(e->value.data, e->value.len); 
     1499        if (expires == NGX_ERROR) { 
     1500            return NGX_DECLINED; 
     1501        } 
     1502 
     1503        d = r->headers_out.date; 
     1504 
     1505        if (d) { 
     1506            date = ngx_http_parse_time(d->value.data, d->value.len); 
     1507            if (date == NGX_ERROR) { 
     1508                return NGX_DECLINED; 
     1509            } 
     1510 
     1511        } else { 
     1512            date = ngx_time(); 
     1513        } 
     1514 
     1515        if (expires < date) { 
     1516            goto ok; 
     1517        } 
     1518 
     1519        return NGX_DECLINED; 
     1520    } 
     1521 
     1522    cc = &r->headers_out.cache_control; 
     1523 
     1524    if (cc->elts) { 
     1525 
     1526        if ((p & NGX_HTTP_GZIP_PROXIED_NO_CACHE) 
     1527            && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_no_cache, 
     1528                                                 NULL) 
     1529               >= 0) 
     1530        { 
     1531            goto ok; 
     1532        } 
     1533 
     1534        if ((p & NGX_HTTP_GZIP_PROXIED_NO_STORE) 
     1535            && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_no_store, 
     1536                                                 NULL) 
     1537               >= 0) 
     1538        { 
     1539            goto ok; 
     1540        } 
     1541 
     1542        if ((p & NGX_HTTP_GZIP_PROXIED_PRIVATE) 
     1543            && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_private, 
     1544                                                 NULL) 
     1545               >= 0) 
     1546        { 
     1547            goto ok; 
     1548        } 
     1549 
     1550        return NGX_DECLINED; 
     1551    } 
     1552 
     1553    if ((p & NGX_HTTP_GZIP_PROXIED_NO_LM) && r->headers_out.last_modified) { 
     1554        return NGX_DECLINED; 
     1555    } 
     1556 
     1557    if ((p & NGX_HTTP_GZIP_PROXIED_NO_ETAG) && r->headers_out.etag) { 
     1558        return NGX_DECLINED; 
     1559    } 
     1560 
     1561ok: 
     1562 
     1563#if (NGX_PCRE) 
     1564 
     1565    if (clcf->gzip_disable && r->headers_in.user_agent) { 
     1566 
     1567        if (ngx_regex_exec_array(clcf->gzip_disable,  
     1568                                 &r->headers_in.user_agent->value, 
     1569                                 r->connection->log) 
     1570            != NGX_DECLINED) 
     1571        { 
     1572            return NGX_DECLINED; 
     1573        } 
     1574    } 
     1575 
     1576#endif 
     1577 
     1578    r->gzip = 1; 
     1579 
     1580    return NGX_OK; 
     1581} 
     1582 
     1583#endif 
    13511584 
    13521585 
     
    23522585     *     lcf->auto_redirect = 0; 
    23532586     *     lcf->alias = 0; 
     2587     *     lcf->gzip_proxied = 0; 
    23542588     */ 
    23552589 
     
    23822616    lcf->types_hash_bucket_size = NGX_CONF_UNSET_UINT; 
    23832617 
     2618#if (NGX_HTTP_GZIP) 
     2619    lcf->gzip_vary = NGX_CONF_UNSET; 
     2620    lcf->gzip_http_version = NGX_CONF_UNSET_UINT; 
     2621    lcf->gzip_disable = NGX_CONF_UNSET_PTR; 
     2622    lcf->gunzip = NGX_CONF_UNSET; 
     2623#endif 
     2624 
    23842625    return lcf; 
    23852626} 
     
    25682809        conf->open_files = prev->open_files; 
    25692810    } 
     2811 
     2812#if (NGX_HTTP_GZIP) 
     2813 
     2814    ngx_conf_merge_value(conf->gzip_vary, prev->gzip_vary, 0); 
     2815    ngx_conf_merge_value(conf->gunzip, prev->gunzip, 0); 
     2816    ngx_conf_merge_uint_value(conf->gzip_http_version, prev->gzip_http_version, 
     2817                              NGX_HTTP_VERSION_11); 
     2818    ngx_conf_merge_bitmask_value(conf->gzip_proxied, prev->gzip_proxied, 
     2819                              (NGX_CONF_BITMASK_SET|NGX_HTTP_GZIP_PROXIED_OFF)); 
     2820 
     2821    ngx_conf_merge_ptr_value(conf->gzip_disable, prev->gzip_disable, NULL); 
     2822 
     2823#endif 
    25702824 
    25712825    return NGX_CONF_OK; 
     
    32533507 
    32543508 
     3509#if (NGX_HTTP_GZIP) 
     3510 
     3511static char * 
     3512ngx_http_gzip_disable(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 
     3513{ 
     3514#if (NGX_PCRE) 
     3515    ngx_http_core_loc_conf_t  *clcf = conf; 
     3516 
     3517    ngx_str_t         err, *value; 
     3518    ngx_uint_t        i; 
     3519    ngx_regex_elt_t  *re; 
     3520    u_char            errstr[NGX_MAX_CONF_ERRSTR]; 
     3521 
     3522    if (clcf->gzip_disable == NGX_CONF_UNSET_PTR) { 
     3523        clcf->gzip_disable = ngx_array_create(cf->pool, 2, 
     3524                                              sizeof(ngx_regex_elt_t)); 
     3525        if (clcf->gzip_disable == NULL) { 
     3526            return NGX_CONF_ERROR; 
     3527        } 
     3528    } 
     3529 
     3530    value = cf->args->elts; 
     3531 
     3532    err.len = NGX_MAX_CONF_ERRSTR; 
     3533    err.data = errstr; 
     3534 
     3535    for (i = 1; i < cf->args->nelts; i++) { 
     3536 
     3537        re = ngx_array_push(clcf->gzip_disable); 
     3538        if (re == NULL) { 
     3539            return NGX_CONF_ERROR; 
     3540        } 
     3541 
     3542        re->regex = ngx_regex_compile(&value[i], NGX_REGEX_CASELESS, cf->pool, 
     3543                                      &err); 
     3544 
     3545        if (re->regex == NULL) { 
     3546            ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data); 
     3547            return NGX_CONF_ERROR; 
     3548        } 
     3549 
     3550        re->name = value[i].data; 
     3551    } 
     3552 
     3553    return NGX_CONF_OK; 
     3554 
     3555#else 
     3556    ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 
     3557                       "\"gzip_disable\" requires PCRE library"); 
     3558 
     3559    return NGX_CONF_ERROR; 
     3560#endif 
     3561} 
     3562 
     3563#endif 
     3564 
     3565 
    32553566static char * 
    32563567ngx_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 
  • server/src/http/ngx_http_variables.c

    r0019fc r7bf8e1  
    13131313 
    13141314 
     1315static ngx_int_t 
     1316ngx_http_optional_variable(ngx_http_request_t *r, 
     1317    ngx_http_variable_value_t *v, uintptr_t data) 
     1318{ 
     1319    *v = ngx_http_variable_null_value; 
     1320    return NGX_OK; 
     1321} 
     1322 
     1323 
    13151324ngx_int_t 
    13161325ngx_http_variables_init_vars(ngx_conf_t *cf) 
     
    13741383        } 
    13751384 
     1385        if (ngx_strncmp(v[i].name.data, "memcached_namespace", 19) == 0) { 
     1386            v[i].get_handler = ngx_http_optional_variable; 
     1387 
     1388            continue; 
     1389        } 
     1390 
    13761391        ngx_log_error(NGX_LOG_EMERG, cf->log, 0, 
    13771392                      "unknown \"%V\" variable", &v[i].name); 
Note: See TracChangeset for help on using the changeset viewer.