diff options
Diffstat (limited to '')
| -rw-r--r-- | src/http/modules/ngx_http_chunked_filter.c | 4 | ||||
| -rw-r--r-- | src/http/modules/ngx_http_gzip_filter.c | 4 | ||||
| -rw-r--r-- | src/http/modules/ngx_http_index_handler.c | 2 | ||||
| -rw-r--r-- | src/http/modules/ngx_http_range_filter.c | 8 | ||||
| -rw-r--r-- | src/http/modules/proxy/ngx_http_proxy_handler.c | 6 | ||||
| -rw-r--r-- | src/http/modules/proxy/ngx_http_proxy_handler.h | 8 | ||||
| -rw-r--r-- | src/http/modules/proxy/ngx_http_proxy_upstream.c | 33 | ||||
| -rw-r--r-- | src/http/ngx_http.h | 9 | ||||
| -rw-r--r-- | src/http/ngx_http_log_handler.c | 4 | ||||
| -rw-r--r-- | src/http/ngx_http_request_body.c | 75 | ||||
| -rw-r--r-- | src/http/ngx_http_special_response.c | 4 |
11 files changed, 90 insertions, 67 deletions
diff --git a/src/http/modules/ngx_http_chunked_filter.c b/src/http/modules/ngx_http_chunked_filter.c index 21e2f5b7c..61eae5d3c 100644 --- a/src/http/modules/ngx_http_chunked_filter.c +++ b/src/http/modules/ngx_http_chunked_filter.c @@ -101,12 +101,12 @@ static int ngx_http_chunked_body_filter(ngx_http_request_t *r, ngx_chain_t *in) if (cl->hunk->type & NGX_HUNK_LAST) { cl->hunk->type &= ~NGX_HUNK_LAST; h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_MEMORY|NGX_HUNK_LAST; - h->pos = CRLF "0" CRLF CRLF; + h->pos = (u_char *) CRLF "0" CRLF CRLF; h->last = h->pos + 7; } else { h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_MEMORY; - h->pos = CRLF; + h->pos = (u_char *) CRLF; h->last = h->pos + 2; } diff --git a/src/http/modules/ngx_http_gzip_filter.c b/src/http/modules/ngx_http_gzip_filter.c index 57177b509..a1cbfb042 100644 --- a/src/http/modules/ngx_http_gzip_filter.c +++ b/src/http/modules/ngx_http_gzip_filter.c @@ -217,9 +217,9 @@ static int ngx_http_gzip_header_filter(ngx_http_request_t *r) } r->headers_out.content_encoding->key.len = sizeof("Content-Encoding") - 1; - r->headers_out.content_encoding->key.data = "Content-Encoding"; + r->headers_out.content_encoding->key.data = (u_char *) "Content-Encoding"; r->headers_out.content_encoding->value.len = sizeof("gzip") - 1; - r->headers_out.content_encoding->value.data = "gzip"; + r->headers_out.content_encoding->value.data = (u_char *) "gzip"; ctx->length = r->headers_out.content_length_n; r->headers_out.content_length_n = -1; diff --git a/src/http/modules/ngx_http_index_handler.c b/src/http/modules/ngx_http_index_handler.c index dd965d0cc..12e96f1c1 100644 --- a/src/http/modules/ngx_http_index_handler.c +++ b/src/http/modules/ngx_http_index_handler.c @@ -21,7 +21,7 @@ typedef struct { } ngx_http_index_ctx_t; -#define NGX_HTTP_DEFAULT_INDEX "index.html" +#define NGX_HTTP_DEFAULT_INDEX (u_char *) "index.html" static ngx_int_t ngx_http_index_test_dir(ngx_http_request_t *r, diff --git a/src/http/modules/ngx_http_range_filter.c b/src/http/modules/ngx_http_range_filter.c index 3f3a6a3f1..5bf4be06a 100644 --- a/src/http/modules/ngx_http_range_filter.c +++ b/src/http/modules/ngx_http_range_filter.c @@ -108,9 +108,9 @@ static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r) } 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->key.data = (u_char *) "Accept-Ranges"; r->headers_out.accept_ranges->value.len = sizeof("bytes") - 1; - r->headers_out.accept_ranges->value.data = "bytes"; + r->headers_out.accept_ranges->value.data = (u_char *) "bytes"; return ngx_http_next_header_filter(r); } @@ -230,7 +230,7 @@ static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r) } r->headers_out.content_range->key.len = sizeof("Content-Range") - 1; - r->headers_out.content_range->key.data = "Content-Range"; + r->headers_out.content_range->key.data = (u_char *) "Content-Range"; ngx_test_null(r->headers_out.content_range->value.data, ngx_palloc(r->pool, 8 + 20 + 1), @@ -261,7 +261,7 @@ static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r) } r->headers_out.content_range->key.len = sizeof("Content-Range") - 1; - r->headers_out.content_range->key.data = "Content-Range"; + r->headers_out.content_range->key.data = (u_char *) "Content-Range"; ngx_test_null(r->headers_out.content_range->value.data, ngx_palloc(r->pool, 6 + 20 + 1 + 20 + 1 + 20 + 1), diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.c b/src/http/modules/proxy/ngx_http_proxy_handler.c index 61fea1c4e..3fc8d0ef4 100644 --- a/src/http/modules/proxy/ngx_http_proxy_handler.c +++ b/src/http/modules/proxy/ngx_http_proxy_handler.c @@ -1073,7 +1073,7 @@ static char *ngx_http_proxy_parse_upstream(ngx_str_t *url, u->default_port = 1; u->port = htons(80); u->port_text.len = 2; - u->port_text.data = "80"; + u->port_text.data = (u_char *) "80"; return NULL; } @@ -1097,14 +1097,14 @@ static char *ngx_http_proxy_parse_upstream(ngx_str_t *url, u->host_header.len = i; - u->uri.data = "/"; + u->uri.data = (u_char *) "/"; u->uri.len = 1; if (u->port_text.data == NULL) { u->default_port = 1; u->port = htons(80); u->port_text.len = 2; - u->port_text.data = "80"; + u->port_text.data = (u_char *) "80"; return NULL; } diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.h b/src/http/modules/proxy/ngx_http_proxy_handler.h index 2e6cb8473..ee95f1b44 100644 --- a/src/http/modules/proxy/ngx_http_proxy_handler.h +++ b/src/http/modules/proxy/ngx_http_proxy_handler.h @@ -184,7 +184,13 @@ struct ngx_http_proxy_ctx_s { ngx_http_proxy_state_t *state; ngx_array_t states; /* of ngx_http_proxy_state_t */ - u_char *action; + /* + * we declare "action" as "char *" because the actions are usually + * the static strings and in the "u_char *" case we have to override + * all the time their types + */ + + char *action; ngx_http_log_ctx_t *saved_ctx; ngx_log_handler_pt saved_handler; }; diff --git a/src/http/modules/proxy/ngx_http_proxy_upstream.c b/src/http/modules/proxy/ngx_http_proxy_upstream.c index a4b6fda3e..f4bc1c4ed 100644 --- a/src/http/modules/proxy/ngx_http_proxy_upstream.c +++ b/src/http/modules/proxy/ngx_http_proxy_upstream.c @@ -305,7 +305,7 @@ static void ngx_http_proxy_init_upstream(void *data) ngx_http_request_t *r; ngx_output_chain_ctx_t *output; ngx_chain_writer_ctx_t *writer; - ngx_http_proxy_log_ctx_t *lctx; + ngx_http_proxy_log_ctx_t *ctx; r = p->request; @@ -345,17 +345,17 @@ static void ngx_http_proxy_init_upstream(void *data) r->request_hunks = cl; - if (!(lctx = ngx_pcalloc(r->pool, sizeof(ngx_http_proxy_log_ctx_t)))) { + if (!(ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_proxy_log_ctx_t)))) { ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR); return; } - lctx->connection = r->connection->number; - lctx->proxy = p; + ctx->connection = r->connection->number; + ctx->proxy = p; p->upstream->peer.log = r->connection->log; p->saved_ctx = r->connection->log->data; p->saved_handler = r->connection->log->handler; - r->connection->log->data = lctx; + r->connection->log->data = ctx; r->connection->log->handler = ngx_http_proxy_log_error; p->action = "connecting to upstream"; @@ -378,7 +378,6 @@ static void ngx_http_proxy_init_upstream(void *data) } output->output_ctx = writer; - writer->pool = r->pool; if (p->lcf->busy_lock && !p->busy_locked) { @@ -393,6 +392,7 @@ static void ngx_http_proxy_reinit_upstream(ngx_http_proxy_ctx_t *p) { ngx_chain_t *cl; ngx_output_chain_ctx_t *output; + ngx_chain_writer_ctx_t *writer; output = p->upstream->output_chain_ctx; @@ -402,7 +402,7 @@ static void ngx_http_proxy_reinit_upstream(ngx_http_proxy_ctx_t *p) cl->hunk->pos = cl->hunk->start; } - /* reinit ngx_output_chain() context */ + /* reinit the ngx_output_chain() context */ output->hunk = NULL; output->in = NULL; @@ -488,6 +488,7 @@ static void ngx_http_proxy_connect(ngx_http_proxy_ctx_t *p) ngx_connection_t *c; ngx_http_request_t *r; ngx_output_chain_ctx_t *output; + ngx_chain_writer_ctx_t *writer; p->action = "connecting to upstream"; @@ -517,14 +518,18 @@ static void ngx_http_proxy_connect(ngx_http_proxy_ctx_t *p) c->pool = r->pool; c->read->log = c->write->log = c->log = r->connection->log; + /* init or reinit the ngx_output_chain() and ngx_chain_writer() contexts */ + output = p->upstream->output_chain_ctx; + writer = output->output_ctx; + writer->out = NULL; + writer->last = &writer->out; + writer->connection = c; if (p->upstream->peer.tries > 1 && p->request_sent) { ngx_http_proxy_reinit_upstream(p); } - /* init or reinit ngx_output_chain() context */ - if (r->request_body_hunk) { if (!(output->free = ngx_alloc_chain_link(r->pool))) { ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR); @@ -563,9 +568,8 @@ static void ngx_http_proxy_connect(ngx_http_proxy_ctx_t *p) static void ngx_http_proxy_send_request(ngx_http_proxy_ctx_t *p) { - int rc; - ngx_connection_t *c; - ngx_chain_writer_ctx_t *writer; + int rc; + ngx_connection_t *c; c = p->upstream->peer.connection; @@ -586,11 +590,6 @@ static void ngx_http_proxy_send_request(ngx_http_proxy_ctx_t *p) p->action = "sending request to upstream"; - writer = p->upstream->output_chain_ctx->output_ctx; - writer->out = NULL; - writer->last = &writer->out; - writer->connection = c; - rc = ngx_output_chain(p->upstream->output_chain_ctx, p->request_sent ? NULL : p->request->request_hunks); diff --git a/src/http/ngx_http.h b/src/http/ngx_http.h index 35879d41c..ec2778a4c 100644 --- a/src/http/ngx_http.h +++ b/src/http/ngx_http.h @@ -23,7 +23,14 @@ typedef struct ngx_http_cleanup_s ngx_http_cleanup_t; typedef struct { u_int connection; - u_char *action; + + /* + * we declare "action" as "char *" because the actions are usually + * the static strings and in the "u_char *" case we have to override + * all the time their types + */ + + char *action; u_char *client; u_char *url; } ngx_http_log_ctx_t; diff --git a/src/http/ngx_http_log_handler.c b/src/http/ngx_http_log_handler.c index c46b119f5..3edb55b54 100644 --- a/src/http/ngx_http_log_handler.c +++ b/src/http/ngx_http_log_handler.c @@ -597,7 +597,7 @@ static void *ngx_http_log_create_main_conf(ngx_conf_t *cf) } value->len = sizeof("combined") - 1; - value->data = "combined"; + value->data = (u_char *) "combined"; if (!(value = ngx_push_array(cf->args))) { return NGX_CONF_ERROR; @@ -699,7 +699,7 @@ static char *ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, name = value[2]; } else { name.len = sizeof("combined") - 1; - name.data = "combined"; + name.data = (u_char *) "combined"; } fmt = lmcf->formats.elts; diff --git a/src/http/ngx_http_request_body.c b/src/http/ngx_http_request_body.c index 404e45f0d..4b97b430e 100644 --- a/src/http/ngx_http_request_body.c +++ b/src/http/ngx_http_request_body.c @@ -83,55 +83,65 @@ static void ngx_http_read_client_request_body_handler(ngx_event_t *rev) c = rev->data; r = c->data; - if (r->request_body_hunk->end - r->request_body_hunk->last == 0) { - n = ngx_write_chain_to_temp_file(r->temp_file, + ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, + "http read client request body"); + + for ( ;; ) { + if (r->request_body_hunk->last == r->request_body_hunk->end) { + n = ngx_write_chain_to_temp_file(r->temp_file, r->request_hunks->next ? r->request_hunks->next: r->request_hunks); - /* TODO: n == 0 or not complete and level event */ - if (n == NGX_ERROR) { - ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); - return; + /* TODO: n == 0 or not complete and level event */ + + if (n == NGX_ERROR) { + ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); + return; + } + + r->temp_file->offset += n; + + r->request_body_hunk->pos = r->request_body_hunk->start; + r->request_body_hunk->last = r->request_body_hunk->start; } - r->temp_file->offset += n; + size = r->request_body_hunk->end - r->request_body_hunk->last; - r->request_body_hunk->pos = r->request_body_hunk->start; - r->request_body_hunk->last = r->request_body_hunk->start; - } + if (size > r->request_body_len) { + size = r->request_body_len; + } - size = r->request_body_hunk->end - r->request_body_hunk->last; + n = ngx_recv(c, r->request_body_hunk->last, size); - if (size > r->request_body_len) { - size = r->request_body_len; - } + if (n == NGX_AGAIN) { + clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); + ngx_add_timer(rev, clcf->client_body_timeout); - n = ngx_recv(c, r->request_body_hunk->last, size); + if (ngx_handle_read_event(rev, 0) == NGX_ERROR) { + ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); + } - if (n == NGX_AGAIN) { - clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); - ngx_add_timer(rev, clcf->client_body_timeout); + return; + } - if (ngx_handle_read_event(rev, 0) == NGX_ERROR) { - ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); + if (n == 0) { + ngx_log_error(NGX_LOG_INFO, c->log, 0, + "client closed prematurely connection"); } - return; - } + if (n == 0 || n == NGX_ERROR) { + ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST); + return; + } - if (n == 0) { - ngx_log_error(NGX_LOG_INFO, c->log, 0, - "client closed prematurely connection"); - } + r->request_body_hunk->last += n; + r->request_body_len -= n; - if (n == 0 || n == NGX_ERROR) { - ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST); - return; + if (r->request_body_hunk->last < r->request_body_hunk->end) { + break; + } } - r->request_body_hunk->last += n; - r->request_body_len -= n; - if (r->request_body_len) { return; } @@ -142,6 +152,7 @@ static void ngx_http_read_client_request_body_handler(ngx_event_t *rev) n = ngx_write_chain_to_temp_file(r->temp_file, r->request_hunks->next ? r->request_hunks->next: r->request_hunks); + /* TODO: n == 0 or not complete and level event */ if (n == NGX_ERROR) { diff --git a/src/http/ngx_http_special_response.c b/src/http/ngx_http_special_response.c index f27177bec..ff26e902b 100644 --- a/src/http/ngx_http_special_response.c +++ b/src/http/ngx_http_special_response.c @@ -248,9 +248,9 @@ int ngx_http_special_response_handler(ngx_http_request_t *r, int error) } r->headers_out.content_type->key.len = sizeof("Content-Type") - 1; - r->headers_out.content_type->key.data = "Content-Type"; + r->headers_out.content_type->key.data = (u_char *) "Content-Type"; r->headers_out.content_type->value.len = sizeof("text/html") - 1; - r->headers_out.content_type->value.data = "text/html"; + r->headers_out.content_type->value.data = (u_char *) "text/html"; } else { r->headers_out.content_length_n = -1; |
