diff options
Diffstat (limited to 'src/http')
-rw-r--r-- | src/http/modules/ngx_http_proxy_module.c | 4 | ||||
-rw-r--r-- | src/http/ngx_http.c | 13 | ||||
-rw-r--r-- | src/http/ngx_http_config.h | 3 | ||||
-rw-r--r-- | src/http/ngx_http_core_module.c | 22 | ||||
-rw-r--r-- | src/http/ngx_http_core_module.h | 3 | ||||
-rw-r--r-- | src/http/ngx_http_header_filter_module.c | 30 | ||||
-rw-r--r-- | src/http/ngx_http_parse.c | 10 | ||||
-rw-r--r-- | src/http/ngx_http_request.c | 4 |
8 files changed, 57 insertions, 32 deletions
diff --git a/src/http/modules/ngx_http_proxy_module.c b/src/http/modules/ngx_http_proxy_module.c index 0211dab06..83625be7b 100644 --- a/src/http/modules/ngx_http_proxy_module.c +++ b/src/http/modules/ngx_http_proxy_module.c @@ -1013,6 +1013,10 @@ ngx_http_proxy_process_header(ngx_http_request_t *r) return NGX_OK; } + if (rc == NGX_AGAIN) { + return NGX_AGAIN; + } + /* there was error while a header line parsing */ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, diff --git a/src/http/ngx_http.c b/src/http/ngx_http.c index 94f718d50..0fb057568 100644 --- a/src/http/ngx_http.c +++ b/src/http/ngx_http.c @@ -360,7 +360,7 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) * to quickly find the server core module configuration at run-time */ - if (ngx_array_init(&in_ports, cf->pool, 10, sizeof(ngx_http_in_port_t)) + if (ngx_array_init(&in_ports, cf->pool, 2, sizeof(ngx_http_in_port_t)) != NGX_OK) { return NGX_CONF_ERROR; @@ -434,6 +434,7 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) if (inaddr == NULL) { return NGX_CONF_ERROR; } + in_addr = in_port[p].addrs.elts; /* * the INADDR_ANY must be the last resort @@ -578,7 +579,7 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) } for (n = 0; n < cmcf->server_names_hash; n++) { - if (ngx_array_init(&in_addr[a].hash[n], cf->pool, 5, + if (ngx_array_init(&in_addr[a].hash[n], cf->pool, 4, sizeof(ngx_http_server_name_t)) != NGX_OK) { return NGX_CONF_ERROR; @@ -595,6 +596,7 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) if (s_name == NULL) { return NGX_CONF_ERROR; } + name = in_addr[a].names.elts; *s_name = name[s]; } @@ -748,7 +750,7 @@ ngx_http_add_address(ngx_conf_t *cf, ngx_http_in_port_t *in_port, ngx_http_in_addr_t *in_addr; if (in_port->addrs.elts == NULL) { - if (ngx_array_init(&in_port->addrs, cf->pool, 10, + if (ngx_array_init(&in_port->addrs, cf->pool, 4, sizeof(ngx_http_in_addr_t)) != NGX_OK) { return NGX_ERROR; @@ -794,7 +796,7 @@ ngx_http_add_names(ngx_conf_t *cf, ngx_http_in_addr_t *in_addr, ngx_http_server_name_t *server_names, *name; if (in_addr->names.elts == NULL) { - if (ngx_array_init(&in_addr->names, cf->pool, 10, + if (ngx_array_init(&in_addr->names, cf->pool, 4, sizeof(ngx_http_server_name_t)) != NGX_OK) { return NGX_ERROR; @@ -802,7 +804,7 @@ ngx_http_add_names(ngx_conf_t *cf, ngx_http_in_addr_t *in_addr, } if (in_addr->wildcards.elts == NULL) { - if (ngx_array_init(&in_addr->wildcards, cf->pool, 10, + if (ngx_array_init(&in_addr->wildcards, cf->pool, 1, sizeof(ngx_http_server_name_t)) != NGX_OK) { return NGX_ERROR; @@ -834,6 +836,7 @@ ngx_http_add_names(ngx_conf_t *cf, ngx_http_in_addr_t *in_addr, if (name == NULL) { return NGX_ERROR; } + server_names = cscf->server_names.elts; *name = server_names[i]; } diff --git a/src/http/ngx_http_config.h b/src/http/ngx_http_config.h index 89110c023..d034351d9 100644 --- a/src/http/ngx_http_config.h +++ b/src/http/ngx_http_config.h @@ -8,7 +8,8 @@ #define _NGX_HTTP_CONFIG_H_INCLUDED_ -#include <ngx_alloc.h> +#include <ngx_config.h> +#include <ngx_core.h> #include <ngx_http.h> diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c index 42c8211d1..02795799a 100644 --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -319,6 +319,13 @@ static ngx_command_t ngx_http_core_commands[] = { offsetof(ngx_http_core_loc_conf_t, reset_timedout_connection), NULL }, + { ngx_string("port_in_redirect"), + NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, + ngx_conf_set_flag_slot, + NGX_HTTP_LOC_CONF_OFFSET, + offsetof(ngx_http_core_loc_conf_t, port_in_redirect), + NULL }, + { ngx_string("msie_padding"), NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, ngx_conf_set_flag_slot, @@ -1113,10 +1120,10 @@ ngx_http_delay_handler(ngx_http_request_t *r) static char * ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy) { - int m; char *rv; void *mconf; - ngx_conf_t save; + ngx_uint_t m; + ngx_conf_t pcf; ngx_http_module_t *module; ngx_http_conf_ctx_t *ctx, *http_ctx; ngx_http_core_srv_conf_t *cscf, **cscfp; @@ -1189,13 +1196,13 @@ ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy) /* parse inside server{} */ - save = *cf; + pcf = *cf; cf->ctx = ctx; cf->cmd_type = NGX_HTTP_SRV_CONF; rv = ngx_conf_parse(cf, NULL); - *cf = save; + *cf = pcf; if (rv != NGX_CONF_OK) { return rv; @@ -1622,6 +1629,7 @@ ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) ls->port = (getuid() == 0) ? 80 : 8000; #endif ls->family = AF_INET; + ls->default_server = 0; } if (conf->server_names.nelts == 0) { @@ -1726,6 +1734,7 @@ ngx_http_core_create_loc_conf(ngx_conf_t *cf) lcf->lingering_time = NGX_CONF_UNSET_MSEC; lcf->lingering_timeout = NGX_CONF_UNSET_MSEC; lcf->reset_timedout_connection = NGX_CONF_UNSET; + lcf->port_in_redirect = NGX_CONF_UNSET; lcf->msie_padding = NGX_CONF_UNSET; return lcf; @@ -1839,6 +1848,7 @@ ngx_http_core_merge_loc_conf(ngx_conf_t *cf, ngx_conf_merge_value(conf->reset_timedout_connection, prev->reset_timedout_connection, 0); + ngx_conf_merge_value(conf->port_in_redirect, prev->port_in_redirect, 1); ngx_conf_merge_value(conf->msie_padding, prev->msie_padding, 1); if (conf->open_files == NULL) { @@ -1857,8 +1867,8 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) u_char *addr; ngx_int_t port; ngx_uint_t p; - struct hostent *h; ngx_str_t *args; + struct hostent *h; ngx_http_listen_t *ls; /* @@ -1874,9 +1884,9 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) /* AF_INET only */ ls->family = AF_INET; - ls->default_server = 0; ls->file_name = cf->conf_file->file.name; ls->line = cf->conf_file->line; + ls->default_server = 0; args = cf->args->elts; addr = args[1].data; diff --git a/src/http/ngx_http_core_module.h b/src/http/ngx_http_core_module.h index 463c6b71b..14090b916 100644 --- a/src/http/ngx_http_core_module.h +++ b/src/http/ngx_http_core_module.h @@ -20,7 +20,7 @@ typedef struct { ngx_str_t file_name; ngx_int_t line; - unsigned default_server:1; + ngx_uint_t default_server; /* unsigned default_server:1; */ } ngx_http_listen_t; @@ -206,6 +206,7 @@ struct ngx_http_core_loc_conf_s { ngx_flag_t tcp_nopush; /* tcp_nopush */ ngx_flag_t tcp_nodelay; /* tcp_nodelay */ ngx_flag_t reset_timedout_connection; /* reset_timedout_connection */ + ngx_flag_t port_in_redirect; /* port_in_redirect */ ngx_flag_t msie_padding; /* msie_padding */ ngx_array_t *error_pages; /* error_page */ diff --git a/src/http/ngx_http_header_filter_module.c b/src/http/ngx_http_header_filter_module.c index a45f2e570..daf6c8580 100644 --- a/src/http/ngx_http_header_filter_module.c +++ b/src/http/ngx_http_header_filter_module.c @@ -258,6 +258,8 @@ ngx_http_header_filter(ngx_http_request_t *r) len += sizeof("Last-Modified: Mon, 28 Sep 1970 06:00:00 GMT" CRLF) - 1; } + clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); + if (r->headers_out.location && r->headers_out.location->value.len && r->headers_out.location->value.data[0] == '/') @@ -270,7 +272,7 @@ ngx_http_header_filter(ngx_http_request_t *r) + r->server_name.len + r->headers_out.location->value.len + 2; - if (r->port != 443) { + if (clcf->port_in_redirect && r->port != 443) { len += r->port_text->len; } @@ -281,7 +283,7 @@ ngx_http_header_filter(ngx_http_request_t *r) + r->server_name.len + r->headers_out.location->value.len + 2; - if (r->port != 80) { + if (clcf->port_in_redirect && r->port != 80) { len += r->port_text->len; } } @@ -291,8 +293,6 @@ ngx_http_header_filter(ngx_http_request_t *r) len += sizeof("Transfer-Encoding: chunked" CRLF) - 1; } - clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); - if (r->keepalive) { len += sizeof("Connection: keep-alive" CRLF) - 1; @@ -425,18 +425,20 @@ ngx_http_header_filter(ngx_http_request_t *r) b->last = ngx_cpymem(b->last, r->server_name.data, r->server_name.len); + if (clcf->port_in_redirect) { #if (NGX_HTTP_SSL) - if (r->connection->ssl) { - if (r->port != 443) { - b->last = ngx_cpymem(b->last, r->port_text->data, - r->port_text->len); - } - } else + if (r->connection->ssl) { + if (r->port != 443) { + b->last = ngx_cpymem(b->last, r->port_text->data, + r->port_text->len); + } + } else #endif - { - if (r->port != 80) { - b->last = ngx_cpymem(b->last, r->port_text->data, - r->port_text->len); + { + if (r->port != 80) { + b->last = ngx_cpymem(b->last, r->port_text->data, + r->port_text->len); + } } } diff --git a/src/http/ngx_http_parse.c b/src/http/ngx_http_parse.c index 027d9efe6..302cd819a 100644 --- a/src/http/ngx_http_parse.c +++ b/src/http/ngx_http_parse.c @@ -112,7 +112,7 @@ ngx_http_parse_request_line(ngx_http_request_t *r, ngx_buf_t *b) case sw_spaces_before_uri: c = (u_char) (ch | 0x20); - if (c >= 'a' && c <= 'f') { + if (c >= 'a' && c <= 'z') { r->schema_start = p; state = sw_schema; break; @@ -133,7 +133,7 @@ ngx_http_parse_request_line(ngx_http_request_t *r, ngx_buf_t *b) case sw_schema: c = (u_char) (ch | 0x20); - if (c >= 'a' && c <= 'f') { + if (c >= 'a' && c <= 'z') { break; } @@ -171,7 +171,7 @@ ngx_http_parse_request_line(ngx_http_request_t *r, ngx_buf_t *b) case sw_host: c = (u_char) (ch | 0x20); - if (c >= 'a' && c <= 'f') { + if (c >= 'a' && c <= 'z') { break; } @@ -215,7 +215,7 @@ ngx_http_parse_request_line(ngx_http_request_t *r, ngx_buf_t *b) case sw_after_slash_in_uri: c = (u_char) (ch | 0x20); - if (c >= 'a' && c <= 'f') { + if (c >= 'a' && c <= 'z') { state = sw_check_uri; break; } @@ -277,7 +277,7 @@ ngx_http_parse_request_line(ngx_http_request_t *r, ngx_buf_t *b) case sw_check_uri: c = (u_char) (ch | 0x20); - if (c >= 'a' && c <= 'f') { + if (c >= 'a' && c <= 'z') { break; } diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c index 37a176a0a..f04c17fa8 100644 --- a/src/http/ngx_http_request.c +++ b/src/http/ngx_http_request.c @@ -1722,6 +1722,10 @@ ngx_http_discard_body(ngx_http_request_t *r) ssize_t size; ngx_event_t *rev; + if (r->main) { + return NGX_OK; + } + rev = r->connection->read; ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0, "http set discard body"); |