diff options
Diffstat (limited to 'src/http')
| -rw-r--r-- | src/http/modules/ngx_http_chunked_filter.c | 2 | ||||
| -rw-r--r-- | src/http/modules/ngx_http_index_handler.c | 2 | ||||
| -rw-r--r-- | src/http/modules/ngx_http_range_filter.c | 10 | ||||
| -rw-r--r-- | src/http/ngx_http.c | 30 | ||||
| -rw-r--r-- | src/http/ngx_http_core_module.c | 30 | ||||
| -rw-r--r-- | src/http/ngx_http_core_module.h | 5 | ||||
| -rw-r--r-- | src/http/ngx_http_event.c | 69 | ||||
| -rw-r--r-- | src/http/ngx_http_output_filter.c | 2 | ||||
| -rw-r--r-- | src/http/ngx_http_special_response.c | 73 | ||||
| -rw-r--r-- | src/http/ngx_http_write_filter.c | 7 |
10 files changed, 155 insertions, 75 deletions
diff --git a/src/http/modules/ngx_http_chunked_filter.c b/src/http/modules/ngx_http_chunked_filter.c index 75a0cdfd6..bdd0a7c7a 100644 --- a/src/http/modules/ngx_http_chunked_filter.c +++ b/src/http/modules/ngx_http_chunked_filter.c @@ -85,7 +85,7 @@ static int ngx_http_chunked_body_filter(ngx_http_request_t *r, ngx_chain_t *in) } ngx_test_null(chunk, ngx_palloc(r->pool, 11), NGX_ERROR); - len = ngx_snprintf(chunk, 11, "%x" CRLF, size); + len = ngx_snprintf(chunk, 11, SIZEX_FMT CRLF, size); ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_TEMP; diff --git a/src/http/modules/ngx_http_index_handler.c b/src/http/modules/ngx_http_index_handler.c index cc7c92790..ffb9779bf 100644 --- a/src/http/modules/ngx_http_index_handler.c +++ b/src/http/modules/ngx_http_index_handler.c @@ -240,7 +240,7 @@ static char *ngx_http_index_merge_conf(ngx_pool_t *p, void *parent, void *child) if (conf->max_index_len == 0) { if (prev->max_index_len != 0) { - ngx_memcpy(conf, prev, sizeof(ngx_http_index_conf_t)); + ngx_memcpy(conf, prev, sizeof(ngx_http_index_conf_t)); return NGX_CONF_OK; } diff --git a/src/http/modules/ngx_http_range_filter.c b/src/http/modules/ngx_http_range_filter.c index d32123b12..d0273ec1c 100644 --- a/src/http/modules/ngx_http_range_filter.c +++ b/src/http/modules/ngx_http_range_filter.c @@ -61,6 +61,10 @@ static int ngx_http_range_header_filter(ngx_http_request_t *r) ngx_init_array(r->headers_out.ranges, r->pool, 5, sizeof(ngx_http_range_t), NGX_ERROR); +#if (NGX_SUPPRESS_WARN) + range = NULL; +#endif + rc = 0; p = r->headers_in.range->value.data + 6; @@ -149,7 +153,7 @@ static int ngx_http_range_header_filter(ngx_http_request_t *r) ngx_palloc(r->pool, 8 + 20 + 1), NGX_ERROR); - r->headers_out.content_range->value.len = + r->headers_out.content_range->value.len = ngx_snprintf(r->headers_out.content_range->value.data, 8 + 20 + 1, "bytes */" OFF_FMT, r->headers_out.content_length); @@ -170,7 +174,7 @@ static int ngx_http_range_header_filter(ngx_http_request_t *r) ngx_palloc(r->pool, 6 + 20 + 1 + 20 + 1 + 20 + 1), NGX_ERROR); - r->headers_out.content_range->value.len = + r->headers_out.content_range->value.len = ngx_snprintf(r->headers_out.content_range->value.data, 6 + 20 + 1 + 20 + 1 + 20 + 1, "bytes " OFF_FMT "-" OFF_FMT "/" OFF_FMT, @@ -244,7 +248,7 @@ static int ngx_http_range_header_filter(ngx_http_request_t *r) ngx_palloc(r->pool, 20 + 1 + 20 + 1 + 20 + 5), NGX_ERROR); - range[i].content_range.len = + range[i].content_range.len = ngx_snprintf(range[i].content_range.data, 20 + 1 + 20 + 1 + 20 + 5, OFF_FMT "-" OFF_FMT "/" OFF_FMT CRLF CRLF, diff --git a/src/http/ngx_http.c b/src/http/ngx_http.c index 44b650e0c..005f230fb 100644 --- a/src/http/ngx_http.c +++ b/src/http/ngx_http.c @@ -1,13 +1,10 @@ #include <ngx_config.h> #include <ngx_core.h> - -#include <ngx_listen.h> - +#include <ngx_event.h> #include <ngx_http.h> -static void ngx_http_init_filters(ngx_pool_t *pool, ngx_module_t **modules); static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); @@ -54,17 +51,20 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) char *rv; struct sockaddr_in *addr_in; ngx_array_t in_ports; - ngx_listen_t *ls; + ngx_listening_t *ls; ngx_http_module_t *module; ngx_conf_t pcf; ngx_http_conf_ctx_t *ctx; ngx_http_in_port_t *in_port, *inport; ngx_http_in_addr_t *in_addr, *inaddr; ngx_http_core_main_conf_t *cmcf; - ngx_http_core_srv_conf_t **cscfp; + ngx_http_core_srv_conf_t **cscfp, *cscf; ngx_http_core_loc_conf_t **clcfp; ngx_http_listen_t *lscf; ngx_http_server_name_t *s_name, *name; +#if (WIN32) + ngx_iocp_conf_t *iocpcf; +#endif /* the main http context */ ngx_test_null(ctx, @@ -431,7 +431,7 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) ngx_test_null(ls, ngx_push_array(&ngx_listening_sockets), NGX_CONF_ERROR); - ngx_memzero(ls, sizeof(ngx_listen_t)); + ngx_memzero(ls, sizeof(ngx_listening_t)); ngx_test_null(addr_in, ngx_pcalloc(cf->pool, sizeof(struct sockaddr_in)), @@ -456,7 +456,7 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) ls->family = AF_INET; ls->type = SOCK_STREAM; ls->protocol = IPPROTO_IP; -#if (NGX_OVERLAPPED) +#if (WIN32) ls->flags = WSA_FLAG_OVERLAPPED; #endif ls->sockaddr = (struct sockaddr *) addr_in; @@ -468,8 +468,18 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) ls->handler = ngx_http_init_connection; ls->log = cf->log; - ls->pool_size = cmcf->connection_pool_size; - ls->post_accept_timeout = cmcf->post_accept_timeout; + + cscf = in_addr[a].core_srv_conf; + ls->pool_size = cscf->connection_pool_size; + ls->post_accept_timeout = cscf->post_accept_timeout; + +#if (WIN32) + iocpcf = ngx_event_get_conf(ngx_iocp_module); + if (iocpcf->acceptex_read) { + ls->post_accept_buffer_size = cscf->client_header_buffer_size; + } +#endif + ls->ctx = ctx; if (in_port[p].addrs.nelts > 1) { diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c index 08a9980ea..a4e6023c3 100644 --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -1,10 +1,6 @@ #include <ngx_config.h> #include <ngx_core.h> - -/* ???? */ -#include <ngx_listen.h> - #include <ngx_http.h> #include <nginx.h> @@ -46,17 +42,17 @@ static ngx_command_t ngx_http_core_commands[] = { NULL}, {ngx_string("connection_pool_size"), - NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1, + NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1, ngx_conf_set_size_slot, - NGX_HTTP_MAIN_CONF_OFFSET, - offsetof(ngx_http_core_main_conf_t, connection_pool_size), + NGX_HTTP_SRV_CONF_OFFSET, + offsetof(ngx_http_core_srv_conf_t, connection_pool_size), NULL}, {ngx_string("post_accept_timeout"), - NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1, + NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1, ngx_conf_set_msec_slot, - NGX_HTTP_MAIN_CONF_OFFSET, - offsetof(ngx_http_core_main_conf_t, post_accept_timeout), + NGX_HTTP_SRV_CONF_OFFSET, + offsetof(ngx_http_core_srv_conf_t, post_accept_timeout), NULL}, {ngx_string("request_pool_size"), @@ -738,9 +734,6 @@ static void *ngx_http_core_create_main_conf(ngx_pool_t *pool) ngx_palloc(pool, sizeof(ngx_http_core_main_conf_t)), NGX_CONF_ERROR); - cmcf->connection_pool_size = NGX_CONF_UNSET; - cmcf->post_accept_timeout = NGX_CONF_UNSET; - ngx_init_array(cmcf->servers, pool, 5, sizeof(ngx_http_core_srv_conf_t *), NGX_CONF_ERROR); @@ -752,8 +745,7 @@ static char *ngx_http_core_init_main_conf(ngx_pool_t *pool, void *conf) { ngx_http_core_main_conf_t *cmcf = conf; - ngx_conf_init_size_value(cmcf->connection_pool_size, 16384); - ngx_conf_init_msec_value(cmcf->post_accept_timeout, 30000); + /* TODO: remove it if no directives */ return NGX_CONF_OK; } @@ -773,6 +765,8 @@ static void *ngx_http_core_create_srv_conf(ngx_pool_t *pool) ngx_init_array(cscf->server_names, pool, 5, sizeof(ngx_http_server_name_t), NGX_CONF_ERROR); + cscf->connection_pool_size = NGX_CONF_UNSET; + cscf->post_accept_timeout = NGX_CONF_UNSET; cscf->request_pool_size = NGX_CONF_UNSET; cscf->client_header_timeout = NGX_CONF_UNSET; cscf->client_header_buffer_size = NGX_CONF_UNSET; @@ -827,6 +821,10 @@ static char *ngx_http_core_merge_srv_conf(ngx_pool_t *pool, n->core_srv_conf = conf; } + ngx_conf_merge_size_value(conf->connection_pool_size, + prev->connection_pool_size, 16384); + ngx_conf_merge_msec_value(conf->post_accept_timeout, + prev->post_accept_timeout, 30000); ngx_conf_merge_size_value(conf->request_pool_size, prev->request_pool_size, 16384); ngx_conf_merge_msec_value(conf->client_header_timeout, @@ -945,7 +943,7 @@ static char *ngx_set_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) ngx_str_t *args; ngx_http_listen_t *ls; - /* TODO: check duplicate 'listen' directives, + /* TODO: check duplicate 'listen' directives, add resolved name to server names ??? */ ngx_test_null(ls, ngx_push_array(&scf->listen), NGX_CONF_ERROR); diff --git a/src/http/ngx_http_core_module.h b/src/http/ngx_http_core_module.h index 113c197a8..4cf966a1d 100644 --- a/src/http/ngx_http_core_module.h +++ b/src/http/ngx_http_core_module.h @@ -18,9 +18,6 @@ typedef struct { typedef struct { - int connection_pool_size; - int post_accept_timeout; - ngx_array_t servers; /* array of ngx_http_core_srv_conf_t */ } ngx_http_core_main_conf_t; @@ -36,6 +33,8 @@ typedef struct { ngx_http_conf_ctx_t *ctx; /* server ctx */ + ngx_msec_t post_accept_timeout; + ssize_t connection_pool_size; size_t request_pool_size; ngx_msec_t client_header_timeout; size_t client_header_buffer_size; diff --git a/src/http/ngx_http_event.c b/src/http/ngx_http_event.c index be6d3910a..991b87d3b 100644 --- a/src/http/ngx_http_event.c +++ b/src/http/ngx_http_event.c @@ -67,14 +67,15 @@ void ngx_http_init_connection(ngx_connection_t *c) ngx_event_t *rev; ngx_http_log_ctx_t *lcx; - c->addr_text.data = ngx_palloc(c->pool, c->addr_text_max_len); + c->addr_text.data = ngx_palloc(c->pool, c->listening->addr_text_max_len); if (c->addr_text.data == NULL) { ngx_http_close_connection(c); return; } - c->addr_text.len = ngx_sock_ntop(c->family, c->sockaddr, - c->addr_text.data, c->addr_text_max_len); + c->addr_text.len = ngx_sock_ntop(c->listening->family, c->sockaddr, + c->addr_text.data, + c->listening->addr_text_max_len); if (c->addr_text.len == 0) { ngx_http_close_connection(c); return; @@ -100,7 +101,7 @@ void ngx_http_init_connection(ngx_connection_t *c) return; } - ngx_add_timer(rev, c->post_accept_timeout); + ngx_add_timer(rev, c->listening->post_accept_timeout); rev->timer_set = 1; if (ngx_event_flags & (NGX_HAVE_AIO_EVENT|NGX_HAVE_EDGE_EVENT)) { @@ -158,19 +159,30 @@ static void ngx_http_init_request(ngx_event_t *rev) if (in_port->addrs.nelts > 1) { - /* there're the several addresses on this port and one of them - is "*:port" so getsockname() is needed to determine - the server address */ + /* + * there're the several addresses on this port and one of them + * is "*:port" so getsockname() is needed to determine + * the server address. + * AcceptEx() already gave this address. + */ - /* TODO: AcceptEx() already gave this sockaddr_in */ +#if (WIN32) + if (c->local_sockaddr) { + r->in_addr = + ((struct sockaddr_in *) c->local_sockaddr)->sin_addr.s_addr; - len = sizeof(struct sockaddr_in); - if (getsockname(c->fd, (struct sockaddr *) &addr_in, &len) == -1) { - ngx_log_error(NGX_LOG_CRIT, rev->log, ngx_socket_errno, - "getsockname() failed"); - ngx_http_close_connection(c); - return; + } else { +#endif + len = sizeof(struct sockaddr_in); + if (getsockname(c->fd, (struct sockaddr *) &addr_in, &len) == -1) { + ngx_log_error(NGX_LOG_CRIT, rev->log, ngx_socket_errno, + "getsockname() failed"); + ngx_http_close_connection(c); + return; + } +#if (WIN32) } +#endif r->in_addr = addr_in.sin_addr.s_addr; @@ -689,18 +701,19 @@ static ssize_t ngx_http_read_request_header(ngx_http_request_t *r) ngx_event_t *rev; ngx_http_core_srv_conf_t *cscf; + rev = r->connection->read; + n = r->header_in->last - r->header_in->pos; if (n > 0) { + rev->ready = 0; return n; } - n = ngx_event_recv(r->connection, r->header_in->last, - r->header_in->end - r->header_in->last); + n = ngx_recv(r->connection, r->header_in->last, + r->header_in->end - r->header_in->last); if (n == NGX_AGAIN) { - rev = r->connection->read; - if (!r->header_timeout_set) { if (rev->timer_set) { ngx_del_timer(rev); @@ -773,6 +786,20 @@ void ngx_http_finalize_request(ngx_http_request_t *r, int error) } rc = ngx_http_special_response_handler(r, rc); + + if (rc == NGX_AGAIN) { + return; + } + + if (rc == NGX_ERROR) { + ngx_http_close_request(r, 0); + ngx_http_close_connection(r->connection); + return; + } + + } else if (rc == NGX_ERROR) { + r->keepalive = 0; + r->lingering_close = 0; } rev = r->connection->read; @@ -1028,7 +1055,7 @@ static int ngx_http_read_discarded_body(ngx_http_request_t *r) size = clcf->discarded_buffer_size; } - n = ngx_event_recv(r->connection, r->discarded_buffer, size); + n = ngx_recv(r->connection, r->discarded_buffer, size); if (n == NGX_ERROR) { return NGX_HTTP_BAD_REQUEST; } @@ -1169,7 +1196,7 @@ static void ngx_http_keepalive_handler(ngx_event_t *rev) rev->ignore_econnreset = 1; ngx_set_socket_errno(0); - n = ngx_event_recv(c, c->buffer->last, c->buffer->end - c->buffer->last); + n = ngx_recv(c, c->buffer->last, c->buffer->end - c->buffer->last); rev->ignore_econnreset = 0; if (n == NGX_AGAIN) { @@ -1307,7 +1334,7 @@ static void ngx_http_lingering_close_handler(ngx_event_t *rev) } do { - n = ngx_event_recv(c, r->discarded_buffer, clcf->discarded_buffer_size); + n = ngx_recv(c, r->discarded_buffer, clcf->discarded_buffer_size); ngx_log_debug(c->log, "lingering read: %d" _ n); diff --git a/src/http/ngx_http_output_filter.c b/src/http/ngx_http_output_filter.c index c0c4dd4cf..7ee6a9673 100644 --- a/src/http/ngx_http_output_filter.c +++ b/src/http/ngx_http_output_filter.c @@ -5,7 +5,7 @@ typedef struct { - size_t hunk_size; + ssize_t hunk_size; } ngx_http_output_filter_conf_t; diff --git a/src/http/ngx_http_special_response.c b/src/http/ngx_http_special_response.c index 9a5dea1f8..9e3bb9ae3 100644 --- a/src/http/ngx_http_special_response.c +++ b/src/http/ngx_http_special_response.c @@ -12,6 +12,16 @@ static char error_tail[] = ; +static char msie_stub[] = +"<!-- The padding to disable MSIE's friendly error page -->" CRLF +"<!-- The padding to disable MSIE's friendly error page -->" CRLF +"<!-- The padding to disable MSIE's friendly error page -->" CRLF +"<!-- The padding to disable MSIE's friendly error page -->" CRLF +"<!-- The padding to disable MSIE's friendly error page -->" CRLF +"<!-- The padding to disable MSIE's friendly error page -->" CRLF +; + + static char error_302_page[] = "<html>" CRLF "<head><title>302 Found</title></head>" CRLF @@ -134,8 +144,8 @@ static ngx_str_t error_pages[] = { int ngx_http_special_response_handler(ngx_http_request_t *r, int error) { - int err; - ngx_hunk_t *message, *tail; + int err, rc; + ngx_hunk_t *h; r->headers_out.status = error; @@ -172,7 +182,8 @@ int ngx_http_special_response_handler(ngx_http_request_t *r, int error) if (error_pages[err].len) { r->headers_out.content_length = error_pages[err].len - + sizeof(error_tail); + + sizeof(error_tail) - 1 + + sizeof(msie_stub) - 1; ngx_test_null(r->headers_out.content_type, ngx_push_table(r->headers_out.headers), @@ -187,29 +198,63 @@ int ngx_http_special_response_handler(ngx_http_request_t *r, int error) r->headers_out.content_length = -1; } - if (ngx_http_send_header(r) == NGX_ERROR) { + rc = ngx_http_send_header(r); + if (rc == NGX_ERROR) { return NGX_ERROR; } + if (r->header_only) { + if (rc == NGX_AGAIN) { + ngx_http_set_write_handler(r); + return NGX_AGAIN; + } + + return NGX_OK; + } + if (error_pages[err].len == 0) { return NGX_OK; } - ngx_test_null(message, ngx_pcalloc(r->pool, sizeof(ngx_hunk_t)), NGX_ERROR); + ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); - message->type = NGX_HUNK_MEMORY|NGX_HUNK_IN_MEMORY; - message->pos = error_pages[err].data; - message->last = error_pages[err].data + error_pages[err].len; + h->type = NGX_HUNK_MEMORY|NGX_HUNK_IN_MEMORY; + h->pos = error_pages[err].data; + h->last = error_pages[err].data + error_pages[err].len; - if (ngx_http_output_filter(r, message) == NGX_ERROR) { + if (ngx_http_output_filter(r, h) == NGX_ERROR) { return NGX_ERROR; } - ngx_test_null(tail, ngx_pcalloc(r->pool, sizeof(ngx_hunk_t)), NGX_ERROR); + ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); + + h->type = NGX_HUNK_MEMORY|NGX_HUNK_IN_MEMORY; + h->pos = error_tail; + h->last = error_tail + sizeof(error_tail) - 1; + + if (1) { + if (ngx_http_output_filter(r, h) == NGX_ERROR) { + return NGX_ERROR; + } + + ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); + + h->type = NGX_HUNK_MEMORY|NGX_HUNK_IN_MEMORY; + h->pos = msie_stub; + h->last = msie_stub + sizeof(msie_stub) - 1; + } + + h->type |= NGX_HUNK_LAST; + + rc = ngx_http_output_filter(r, h); + + if (r->main == NULL) { + if (rc == NGX_AGAIN) { + ngx_http_set_write_handler(r); + return NGX_AGAIN; + } + } - tail->type = NGX_HUNK_MEMORY|NGX_HUNK_LAST|NGX_HUNK_IN_MEMORY; - tail->pos = error_tail; - tail->last = error_tail + sizeof(error_tail); + return NGX_OK; - return ngx_http_output_filter(r, tail); } diff --git a/src/http/ngx_http_write_filter.c b/src/http/ngx_http_write_filter.c index 59d4a6925..6b76f7390 100644 --- a/src/http/ngx_http_write_filter.c +++ b/src/http/ngx_http_write_filter.c @@ -1,11 +1,12 @@ #include <ngx_config.h> #include <ngx_core.h> +#include <ngx_event.h> #include <ngx_http.h> typedef struct { - size_t buffer_output; + ssize_t buffer_output; } ngx_http_write_filter_conf_t; @@ -139,11 +140,7 @@ int ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in) return NGX_AGAIN; } -#if 1 chain = ngx_write_chain(r->connection, ctx->out); -#else - chain = ngx_write_chain(r->connection, ctx->out, flush); -#endif #if (NGX_DEBUG_WRITE_FILTER) ngx_log_debug(r->connection->log, "write filter %x" _ chain); |
