Changeset dbd2c3


Ignore:
Timestamp:
02/04/08 16:11:49 (4 years ago)
Author:
Tomash Brechko <tomash.brechko@…>
Branches:
master-v0.7, master-v0.6, memcached_gzip, upstream_count_limit
Children:
b649a6, f54237
Parents:
2a28c1 (diff), 95d817 (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/04/08 16:11:49)
git-committer:
Tomash Brechko <tomash.brechko@…> (02/04/08 16:11:49)
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

    r2bbdb3 r95d817  
    309309    ngx_http_gzip_ctx_t   *ctx; 
    310310    ngx_http_gzip_conf_t  *conf; 
     311    const char            *method = (r->gunzip ? "inflate" : "deflate"); 
    311312 
    312313    ctx = ngx_http_get_module_ctx(r, ngx_http_gzip_filter_module); 
     
    366367        if (rc != Z_OK) { 
    367368            ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, 
    368                           "deflateInit2() failed: %d", rc); 
     369                          "%sInit2() failed: %d", method, rc); 
    369370            ngx_http_gzip_error(ctx); 
    370371            return NGX_ERROR; 
     
    456457 
    457458                if (ctx->in_buf->last_buf) { 
    458                     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); 
    459482 
    460483                } else if (ctx->in_buf->flush) { 
     
    474497 
    475498 
    476             /* is there a space for the gzipped data ? */ 
     499            /* is there a space for the output data ? */ 
    477500 
    478501            if (ctx->zstream.avail_out == 0) { 
     
    503526            } 
    504527 
    505             ngx_log_debug6(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 
    506                          "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, 
    507531                         ctx->zstream.next_in, ctx->zstream.next_out, 
    508532                         ctx->zstream.avail_in, ctx->zstream.avail_out, 
     
    515539            } 
    516540 
    517             if (rc != Z_OK && rc != Z_STREAM_END && rc != Z_BUF_ERROR) { 
     541            if (rc != Z_OK && rc != Z_STREAM_END) { 
    518542                ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, 
    519                               "deflate() failed: %d, %d", ctx->flush, rc); 
     543                              "%s() failed: %d, %d", method, ctx->flush, rc); 
    520544                ngx_http_gzip_error(ctx); 
    521545                return NGX_ERROR; 
    522546            } 
    523547 
    524             ngx_log_debug5(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 
    525                            "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, 
    526551                           ctx->zstream.next_in, ctx->zstream.next_out, 
    527552                           ctx->zstream.avail_in, ctx->zstream.avail_out, 
    528553                           rc); 
    529554 
    530             ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 
    531                            "gzip in_buf:%p pos:%p", 
    532                            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); 
    533558 
    534559 
     
    588613                if (rc != Z_OK) { 
    589614                    ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, 
    590                                   "deflateEnd() failed: %d", rc); 
     615                                  "%sEnd() failed: %d", method, rc); 
    591616                    ngx_http_gzip_error(ctx); 
    592617                    return NGX_ERROR; 
     
    601626                } 
    602627 
    603                 cl->buf = ctx->out_buf; 
    604                 cl->next = NULL; 
    605                 *ctx->last_out = cl; 
    606                 ctx->last_out = &cl->next; 
     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                } 
    607639 
    608640                if (!r->gunzip) { 
  • 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.