Changeset 2a28c1


Ignore:
Timestamp:
02/03/08 15:02:34 (4 years ago)
Author:
Tomash Brechko <tomash.brechko@…>
Branches:
master-v0.7, master-v0.6, memcached_gzip, upstream_count_limit
Children:
dbd2c3, f54237
Parents:
e1c857 (diff), 2bbdb3 (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/03/08 15:02:34)
git-committer:
Tomash Brechko <tomash.brechko@…> (02/03/08 15:02:34)
Message:

Merge branch 'gunzip' into memcached_gzip

Location:
server/src/http/modules
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • server/src/http/modules/ngx_http_gzip_filter_module.c

    r233310 r2bbdb3  
    319319 
    320320    if (ctx->preallocated == NULL) { 
    321         wbits = conf->wbits; 
     321        wbits = (!r->gunzip ? conf->wbits : 15); 
    322322        memlevel = conf->memlevel; 
    323323 
    324         if (ctx->length > 0) { 
     324        if (!r->gunzip && ctx->length > 0) { 
    325325 
    326326            /* the actual zlib window size is smaller by 262 bytes */ 
     
    543543            ctx->out_buf->last = ctx->zstream.next_out; 
    544544 
    545             if (ctx->zstream.avail_out == 0) { 
    546  
    547                 /* zlib wants to output some more gzipped data */ 
    548  
    549                 cl = ngx_alloc_chain_link(r->pool); 
    550                 if (cl == NULL) { 
    551                     ngx_http_gzip_error(ctx); 
    552                     return NGX_ERROR; 
    553                 } 
    554  
    555                 cl->buf = ctx->out_buf; 
    556                 cl->next = NULL; 
    557                 *ctx->last_out = cl; 
    558                 ctx->last_out = &cl->next; 
    559  
    560                 ctx->redo = 1; 
    561  
    562                 continue; 
    563             } 
    564  
    565545            ctx->redo = 0; 
    566546 
    567             if (ctx->flush == Z_SYNC_FLUSH 
    568                 && ctx->out_buf->last > ctx->out_buf->pos) { 
    569  
    570                 ctx->zstream.avail_out = 0; 
     547            if (ctx->flush == Z_SYNC_FLUSH) { 
     548 
    571549                ctx->out_buf->flush = 1; 
    572550                ctx->flush = Z_NO_FLUSH; 
    573551 
    574                 cl = ngx_alloc_chain_link(r->pool); 
    575                 if (cl == NULL) { 
    576                     ngx_http_gzip_error(ctx); 
    577                     return NGX_ERROR; 
    578                 } 
    579  
    580                 cl->buf = ctx->out_buf; 
    581                 cl->next = NULL; 
    582                 *ctx->last_out = cl; 
    583                 ctx->last_out = &cl->next; 
    584  
    585                 break; 
     552                /* 
     553                 * On decompression there might be not enough input 
     554                 * data to produce any output data. 
     555                 */ 
     556                if (ctx->out_buf->last > ctx->out_buf->pos) { 
     557 
     558                    ctx->zstream.avail_out = 0; 
     559 
     560                    cl = ngx_alloc_chain_link(r->pool); 
     561                    if (cl == NULL) { 
     562                        ngx_http_gzip_error(ctx); 
     563                        return NGX_ERROR; 
     564                    } 
     565 
     566                    cl->buf = ctx->out_buf; 
     567                    cl->next = NULL; 
     568                    *ctx->last_out = cl; 
     569                    ctx->last_out = &cl->next; 
     570 
     571                    break; 
     572                } 
    586573            } 
    587574 
     
    596583                    ctx->zout = ctx->zstream.total_out; 
    597584 
    598                     r->gunzip = 0; 
    599585                    rc = inflateEnd(&ctx->zstream); 
    600586                } 
     
    667653                } else { 
    668654                    ctx->out_buf->last_buf = 1; 
     655                    r->gunzip = 0; 
    669656                } 
    670657 
     
    677664 
    678665                break; 
     666            } 
     667 
     668            if (ctx->zstream.avail_out == 0) { 
     669 
     670                /* zlib wants to output some more gzipped data */ 
     671 
     672                cl = ngx_alloc_chain_link(r->pool); 
     673                if (cl == NULL) { 
     674                    ngx_http_gzip_error(ctx); 
     675                    return NGX_ERROR; 
     676                } 
     677 
     678                cl->buf = ctx->out_buf; 
     679                cl->next = NULL; 
     680                *ctx->last_out = cl; 
     681                ctx->last_out = &cl->next; 
     682 
     683                ctx->redo = 1; 
     684 
     685                continue; 
    679686            } 
    680687 
  • server/src/http/modules/ngx_http_memcached_module.c

    r0019fc re1c857  
    1414    ngx_http_upstream_conf_t   upstream; 
    1515    ngx_int_t                  index; 
     16    ngx_uint_t                 gzip_flag; 
    1617} ngx_http_memcached_loc_conf_t; 
    1718 
     
    99100      offsetof(ngx_http_memcached_loc_conf_t, upstream.next_upstream), 
    100101      &ngx_http_memcached_next_upstream_masks }, 
     102 
     103    { ngx_string("memcached_gzip_flag"), 
     104      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, 
     105      ngx_conf_set_num_slot, 
     106      NGX_HTTP_LOC_CONF_OFFSET, 
     107      offsetof(ngx_http_memcached_loc_conf_t, gzip_flag), 
     108      NULL }, 
    101109 
    102110    { ngx_string("memcached_upstream_max_fails"), 
     
    298306ngx_http_memcached_process_header(ngx_http_request_t *r) 
    299307{ 
    300     u_char                    *p, *len; 
     308    u_char                    *p, *beg; 
    301309    ngx_str_t                  line; 
    302310    ngx_http_upstream_t       *u; 
    303311    ngx_http_memcached_ctx_t  *ctx; 
     312    ngx_http_memcached_loc_conf_t  *mlcf; 
     313    uint32_t                   flags; 
     314    ngx_table_elt_t           *h; 
     315    ngx_http_core_loc_conf_t  *clcf; 
    304316 
    305317    u = r->upstream; 
     
    346358        } 
    347359 
    348         /* skip flags */ 
    349  
    350         while (*p) { 
    351             if (*p++ == ' ') { 
    352                 goto length; 
    353             } 
     360        beg = p; 
     361 
     362        while (*p && *p++ != ' ') { /* void */ } 
     363 
     364        if (! *p) { 
     365            goto no_valid; 
    354366        } 
    355367 
    356         goto no_valid; 
    357  
    358     length: 
    359  
    360         len = p; 
     368        flags = ngx_atoof(beg, p - beg - 1); 
     369 
     370        beg = p; 
    361371 
    362372        while (*p && *p++ != CR) { /* void */ } 
    363373 
    364         r->headers_out.content_length_n = ngx_atoof(len, p - len - 1); 
     374        r->headers_out.content_length_n = ngx_atoof(beg, p - beg - 1); 
    365375        if (r->headers_out.content_length_n == -1) { 
    366376            ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, 
     
    369379                          &line, &ctx->key); 
    370380            return NGX_HTTP_UPSTREAM_INVALID_HEADER; 
     381        } 
     382 
     383        mlcf = ngx_http_get_module_loc_conf(r, ngx_http_memcached_module); 
     384 
     385        if (flags & mlcf->gzip_flag) { 
     386#if (NGX_HTTP_GZIP) 
     387            clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); 
     388 
     389            if (ngx_http_gzip_ok(r) == NGX_OK) { 
     390                h = ngx_list_push(&r->headers_out.headers); 
     391                if (h == NULL) { 
     392                    return NGX_ERROR; 
     393                } 
     394 
     395                h->hash = 1; 
     396                h->key.len = sizeof("Content-Encoding") - 1; 
     397                h->key.data = (u_char *) "Content-Encoding"; 
     398                h->value.len = sizeof("gzip") - 1; 
     399                h->value.data = (u_char *) "gzip"; 
     400 
     401                r->headers_out.content_encoding = h; 
     402 
     403                if (clcf->gzip_vary) { 
     404                    h = ngx_list_push(&r->headers_out.headers); 
     405                    if (h == NULL) { 
     406                        return NGX_ERROR; 
     407                    } 
     408 
     409                    h->hash = 1; 
     410                    h->key.len = sizeof("Vary") - 1; 
     411                    h->key.data = (u_char *) "Vary"; 
     412                    h->value.len = sizeof("Accept-Encoding") - 1; 
     413                    h->value.data = (u_char *) "Accept-Encoding"; 
     414                } 
     415            } else { 
     416                if (clcf->gunzip) { 
     417                    r->gunzip = 1; 
     418                } else { 
     419#endif 
     420                    /* 
     421                     * If the client can't accept compressed data, and 
     422                     * automatic decompression is not enabled, we 
     423                     * return 404 in the hope that the next upstream 
     424                     * will return uncompressed data. 
     425                     */ 
     426                    u->headers_in.status_n = 404; 
     427                    u->state->status = 404; 
     428 
     429                    return NGX_OK; 
     430#if (NGX_HTTP_GZIP) 
     431                } 
     432            } 
     433#endif 
    371434        } 
    372435 
     
    532595 
    533596    conf->upstream.buffer_size = NGX_CONF_UNSET_SIZE; 
     597 
     598    conf->gzip_flag = NGX_CONF_UNSET_UINT; 
    534599 
    535600    /* the hardcoded values */ 
     
    576641                               |NGX_HTTP_UPSTREAM_FT_TIMEOUT)); 
    577642 
     643    ngx_conf_merge_uint_value(conf->gzip_flag, 
     644                              prev->gzip_flag, 0); 
     645 
    578646    if (conf->upstream.next_upstream & NGX_HTTP_UPSTREAM_FT_OFF) { 
    579647        conf->upstream.next_upstream = NGX_CONF_BITMASK_SET 
Note: See TracChangeset for help on using the changeset viewer.