diff options
| author | Igor Sysoev <igor@sysoev.ru> | 2003-10-02 05:39:37 +0000 |
|---|---|---|
| committer | Igor Sysoev <igor@sysoev.ru> | 2003-10-02 05:39:37 +0000 |
| commit | 87a01ea908356173d6387aea2af94ad0fe236bb4 (patch) | |
| tree | 1abe9d49f56322c179e224b9154a9c871d13dacb /src/http/modules | |
| parent | 2cdd7e9e5bd7c0ddcc5dbf57aa3ffb998fd3335f (diff) | |
| download | nginx-87a01ea908356173d6387aea2af94ad0fe236bb4.tar.gz nginx-87a01ea908356173d6387aea2af94ad0fe236bb4.tar.bz2 | |
nginx-0.0.1-2003-10-02-09:39:37 import
Diffstat (limited to 'src/http/modules')
| -rw-r--r-- | src/http/modules/ngx_http_gzip_filter.c | 32 | ||||
| -rw-r--r-- | src/http/modules/ngx_http_not_modified_filter.c | 3 | ||||
| -rw-r--r-- | src/http/modules/ngx_http_range_filter.c | 11 | ||||
| -rw-r--r-- | src/http/modules/proxy/ngx_http_proxy_handler.c | 125 | ||||
| -rw-r--r-- | src/http/modules/proxy/ngx_http_proxy_handler.h | 1 |
5 files changed, 114 insertions, 58 deletions
diff --git a/src/http/modules/ngx_http_gzip_filter.c b/src/http/modules/ngx_http_gzip_filter.c index 924414470..cef987bc3 100644 --- a/src/http/modules/ngx_http_gzip_filter.c +++ b/src/http/modules/ngx_http_gzip_filter.c @@ -173,7 +173,7 @@ static int ngx_http_gzip_header_filter(ngx_http_request_t *r) static int ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in) { - int rc, zin, zout; + int rc, wbits, mem_level, zin, zout; struct gztrailer *trailer; ngx_hunk_t *h; ngx_chain_t *ce; @@ -189,14 +189,27 @@ static int ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in) conf = ngx_http_get_module_loc_conf(r, ngx_http_gzip_filter_module); if (ctx->alloc == NULL) { + wbits = MAX_WBITS; + mem_level = MAX_MEM_LEVEL - 1; + + if (ctx->length > 0) { + + /* the actual zlib window size is smaller by 262 bytes */ + + while (ctx->length < ((1 << (wbits - 1)) - 262)) { + wbits--; + mem_level--; + } + } + #if 0 ngx_test_null(ctx->alloc, ngx_alloc(200K, r->log), NGX_ERROR); #else ctx->alloc = (void *) ~NULL; #endif + rc = deflateInit2(&ctx->zstream, /**/ 1, Z_DEFLATED, - /**/ -MAX_WBITS, /**/ MAX_MEM_LEVEL - 1, - Z_DEFAULT_STRATEGY); + -wbits, mem_level, Z_DEFAULT_STRATEGY); if (rc != Z_OK) { ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, @@ -244,7 +257,7 @@ static int ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in) ctx->in_hunk = ctx->in->hunk; ctx->in = ctx->in->next; - ctx->zstream.next_in = ctx->in_hunk->pos; + ctx->zstream.next_in = (unsigned char *) ctx->in_hunk->pos; ctx->zstream.avail_in = ctx->in_hunk->last - ctx->in_hunk->pos; if (ctx->in_hunk->type & NGX_HUNK_LAST) { @@ -283,7 +296,7 @@ static int ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in) break; } - ctx->zstream.next_out = ctx->out_hunk->pos; + ctx->zstream.next_out = (unsigned char *) ctx->out_hunk->pos; ctx->zstream.avail_out = conf->hunk_size; } @@ -302,7 +315,7 @@ ngx_log_debug(r->connection->log, "DEFLATE(): %08x %08x %d %d %d" _ ctx->zstream.next_in _ ctx->zstream.next_out _ ctx->zstream.avail_in _ ctx->zstream.avail_out _ rc); - ctx->in_hunk->pos = ctx->zstream.next_in; + ctx->in_hunk->pos = (char *) ctx->zstream.next_in; if (ctx->zstream.avail_out == 0) { ctx->out_hunk->last += conf->hunk_size; @@ -313,7 +326,7 @@ ngx_log_debug(r->connection->log, "DEFLATE(): %08x %08x %d %d %d" _ ctx->redo = 1; } else { - ctx->out_hunk->last = ctx->zstream.next_out; + ctx->out_hunk->last = (char *) ctx->zstream.next_out; ctx->redo = 0; if (ctx->flush == Z_SYNC_FLUSH) { @@ -378,10 +391,11 @@ ngx_log_debug(r->connection->log, "DEFLATE(): %08x %08x %d %d %d" _ ctx->zstream.avail_in = 0; ctx->zstream.avail_out = 0; - ngx_http_delete_ctx(r, ngx_http_gzip_filter_module); #if 0 - ngx_free(); + ngx_free(ctx->alloc); #endif + ngx_http_delete_ctx(r, ngx_http_gzip_filter_module); + break; } else if (conf->no_buffer && ctx->in == NULL) { diff --git a/src/http/modules/ngx_http_not_modified_filter.c b/src/http/modules/ngx_http_not_modified_filter.c index ac99ab0ca..ab22fa682 100644 --- a/src/http/modules/ngx_http_not_modified_filter.c +++ b/src/http/modules/ngx_http_not_modified_filter.c @@ -57,8 +57,7 @@ static int ngx_http_not_modified_header_filter(ngx_http_request_t *r) r->headers_out.content_length = -1; r->headers_out.content_type->key.len = 0; r->headers_out.content_type = NULL; - - /* TODO: delete "Accept-Ranges" header + r->headers_out.accept_ranges->key.len = 0; } return next_header_filter(r); diff --git a/src/http/modules/ngx_http_range_filter.c b/src/http/modules/ngx_http_range_filter.c index 5be469af5..8344aa630 100644 --- a/src/http/modules/ngx_http_range_filter.c +++ b/src/http/modules/ngx_http_range_filter.c @@ -43,7 +43,6 @@ static int ngx_http_range_header_filter(ngx_http_request_t *r) int rc, boundary, len, i; char *p; off_t start, end; - ngx_table_elt_t *accept_ranges; ngx_http_range_t *range; ngx_http_range_filter_ctx_t *ctx; @@ -61,14 +60,14 @@ static int ngx_http_range_header_filter(ngx_http_request_t *r) || r->headers_in.range->value.len < 7 || ngx_strncasecmp(r->headers_in.range->value.data, "bytes=", 6) != 0) { - ngx_test_null(accept_ranges, + ngx_test_null(r->headers_out.accept_ranges, ngx_push_table(r->headers_out.headers), NGX_ERROR); - accept_ranges->key.len = sizeof("Accept-Ranges") - 1; - accept_ranges->key.data = "Accept-Ranges"; - accept_ranges->value.len = sizeof("bytes") - 1; - accept_ranges->value.data = "bytes"; + r->headers_out.accept_ranges->key.len = sizeof("Accept-Ranges") - 1; + r->headers_out.accept_ranges->key.data = "Accept-Ranges"; + r->headers_out.accept_ranges->value.len = sizeof("bytes") - 1; + r->headers_out.accept_ranges->value.data = "bytes"; return next_header_filter(r); } diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.c b/src/http/modules/proxy/ngx_http_proxy_handler.c index 00f1e722e..819d64957 100644 --- a/src/http/modules/proxy/ngx_http_proxy_handler.c +++ b/src/http/modules/proxy/ngx_http_proxy_handler.c @@ -9,6 +9,8 @@ static void ngx_http_proxy_send_request(ngx_event_t *wev); +static void ngx_http_proxy_close_connection(ngx_connection_t *c); +static ngx_chain_t *ngx_http_proxy_copy_request_hunks(ngx_http_proxy_ctx_t *p); static void *ngx_http_proxy_create_loc_conf(ngx_conf_t *cf); @@ -66,33 +68,50 @@ int ngx_http_proxy_handler(ngx_http_request_t *r) p->action = "connecting to upstream"; p->request = r; p->upstream.peers = p->lcf->peers; + p->upstream.tries = p->lcf->peers->number; - /* TODO: change log->data, how to restore log->data ? */ + /* TODO: log->data would be changed, how to restore log->data ? */ p->upstream.log = r->connection->log; - do { + for ( ;; ) { rc = ngx_event_connect_peer(&p->upstream); if (rc == NGX_ERROR) { return NGX_HTTP_INTERNAL_SERVER_ERROR; } - if (rc == NGX_OK) { - ngx_http_proxy_send_request(p->upstream.connection->write); - return NGX_OK; + if (rc == NGX_CONNECT_ERROR) { + ngx_event_connect_peer_failed(&p->upstream); + + if (p->upstream.tries == 0) { + return NGX_HTTP_BAD_GATEWAY; + } } - if (rc == NGX_AGAIN) { - /* TODO */ return NGX_OK; + p->upstream.connection->data = p; + p->upstream.connection->write->event_handler = + ngx_http_proxy_send_request; + p->upstream.connection->read->event_handler = /* STUB */ NULL; + + if (p->upstream.tries > 1) { + ngx_test_null(p->work_request_hunks, + ngx_http_proxy_copy_request_hunks(p), + NGX_HTTP_INTERNAL_SERVER_ERROR); + } else { + p->work_request_hunks = p->request_hunks; } - /* rc == NGX_CONNECT_FAILED */ + if (rc == NGX_OK) { + ngx_http_proxy_send_request(p->upstream.connection->write); + return NGX_OK; + } - ngx_event_connect_peer_failed(&p->upstream); + /* rc == NGX_AGAIN */ - } while (p->upstream.tries); + /* timer */ - return NGX_HTTP_BAD_GATEWAY; + /* TODO */ return NGX_OK; + } } @@ -112,52 +131,45 @@ static void ngx_http_proxy_send_request(ngx_event_t *wev) if (chain == (ngx_chain_t *) -1) { ngx_http_proxy_close_connection(c); - do { + for ( ;; ) { rc = ngx_event_connect_peer(&p->upstream); - if (rc == NGX_OK) { + if (rc == NGX_ERROR) { + ngx_http_finalize_request(p->request, + NGX_HTTP_INTERNAL_SERVER_ERROR); + return; + } - /* copy chain and hunks p->request_hunks - from p->initial_request_hunks */ + if (rc == NGX_CONNECT_ERROR) { + ngx_event_connect_peer_failed(&p->upstream); - p->request_hunks = NULL; - if (ngx_chain_add_copy(r->pool, p->request_hunks, - p->initial_request_hunks) == NGX_ERROR) - { - return NGX_HTTP_INTERNAL_SERVER_ERROR; - } - - for (ce = p->request_hunks; ce; ce = ce->next) { - ce->hunk->pos = ce->hunk->start; + if (p->upstream.tries == 0) { + return; } + } + if (p->upstream.tries > 1) { + ngx_test_null(p->work_request_hunks, + ngx_http_proxy_copy_request_hunks(p), + /* void */); + } else { + p->work_request_hunks = p->request_hunks; + } + if (rc == NGX_OK) { c = p->connection; wev = c->write; break; } - if (rc == NGX_ERROR) { - ngx_http_finalize_request(p->request, - NGX_HTTP_INTERNAL_SERVER_ERROR); - return; - } - - if (rc == NGX_AGAIN) { - return; - } - - /* rc == NGX_CONNECT_FAILED */ + /* rc == NGX_AGAIN */ + return; - ngx_event_connect_peer_failed(&p->upstream); - - } while (p->upstream.tries); - - return; + } } else { - p->request_hunks = chain; + p->work_request_hunks = chain; ngx_del_timer(wev); @@ -175,6 +187,37 @@ static void ngx_http_proxy_send_request(ngx_event_t *wev) } } +static void ngx_http_proxy_close_connection(ngx_connection_t *c) +{ + return; +} + +static ngx_chain_t *ngx_http_proxy_copy_request_hunks(ngx_http_proxy_ctx_t *p) +{ + ngx_chain_t *ce, *te, *fe, **le; + +#if (NGX_SUPPRESS_WARN) + le = NULL; +#endif + + ngx_test_null(fe, ngx_alloc_chain_entry(p->request->pool), NULL); + + te = fe; + + for (ce = p->request_hunks; ce; ce = ce->next) { + te->hunk = ce->hunk; + *le = te; + le = &te->next; + ce->hunk->pos = ce->hunk->start; + + ngx_test_null(te, ngx_alloc_chain_entry(p->request->pool), NULL); + } + + *le = NULL; + + return fe; +} + static size_t ngx_http_proxy_log_error(void *data, char *buf, size_t len) { diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.h b/src/http/modules/proxy/ngx_http_proxy_handler.h index ce264c9a2..af237c06a 100644 --- a/src/http/modules/proxy/ngx_http_proxy_handler.h +++ b/src/http/modules/proxy/ngx_http_proxy_handler.h @@ -26,6 +26,7 @@ struct ngx_http_proxy_ctx_s { ngx_http_proxy_loc_conf_t *lcf; + ngx_chain_t *work_request_hunks; ngx_chain_t *request_hunks; char *action; |
