Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nginx/nginx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src/http
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2003-10-29 11:30:44 +0300
committerIgor Sysoev <igor@sysoev.ru>2003-10-29 11:30:44 +0300
commitb5faed2dc853ee7e6bda6004b16ceedc6c194641 (patch)
tree7812abde1b258c5e751ac6a85072c792549d55f5 /src/http
parentab0c4f5038cec58e23a023d8a1e01be038504e3e (diff)
nginx-0.0.1-2003-10-29-11:30:44 import
Diffstat (limited to 'src/http')
-rw-r--r--src/http/modules/ngx_http_gzip_filter.c15
-rw-r--r--src/http/modules/ngx_http_range_filter.c9
-rw-r--r--src/http/modules/proxy/ngx_http_proxy_handler.c52
-rw-r--r--src/http/modules/proxy/ngx_http_proxy_handler.h4
-rw-r--r--src/http/ngx_http.h3
-rw-r--r--src/http/ngx_http_core_module.c86
-rw-r--r--src/http/ngx_http_header_filter.c80
-rw-r--r--src/http/ngx_http_request.c63
-rw-r--r--src/http/ngx_http_request.h13
-rw-r--r--src/http/ngx_http_request_body.c2
-rw-r--r--src/http/ngx_http_special_response.c20
11 files changed, 240 insertions, 107 deletions
diff --git a/src/http/modules/ngx_http_gzip_filter.c b/src/http/modules/ngx_http_gzip_filter.c
index a32714da4..e9271a9b7 100644
--- a/src/http/modules/ngx_http_gzip_filter.c
+++ b/src/http/modules/ngx_http_gzip_filter.c
@@ -190,18 +190,23 @@ static int ngx_http_gzip_header_filter(ngx_http_request_t *r)
sizeof(ngx_http_gzip_ctx_t), NGX_ERROR);
ctx->request = r;
- ngx_test_null(r->headers_out.content_encoding,
- ngx_push_table(r->headers_out.headers),
- NGX_ERROR);
+ if (!(r->headers_out.content_encoding =
+ ngx_http_add_header(&r->headers_out, ngx_http_headers_out)))
+ {
+ return NGX_ERROR;
+ }
r->headers_out.content_encoding->key.len = 0;
r->headers_out.content_encoding->key.data = NULL;
- r->headers_out.content_encoding->value.len = 4;
+ r->headers_out.content_encoding->value.len = sizeof("gzip") - 1;
r->headers_out.content_encoding->value.data = "gzip";
ctx->length = r->headers_out.content_length_n;
r->headers_out.content_length_n = -1;
- r->headers_out.content_length = NULL;
+ if (r->headers_out.content_length) {
+ r->headers_out.content_length->key.len = 0;
+ r->headers_out.content_length = NULL;
+ }
r->filter |= NGX_HTTP_FILTER_NEED_IN_MEMORY;
return ngx_http_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 9233605a1..ff534bb9c 100644
--- a/src/http/modules/ngx_http_range_filter.c
+++ b/src/http/modules/ngx_http_range_filter.c
@@ -96,9 +96,12 @@ 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(r->headers_out.accept_ranges,
- ngx_push_table(r->headers_out.headers),
- NGX_ERROR);
+
+ if (!(r->headers_out.accept_ranges =
+ ngx_http_add_header(&r->headers_out, ngx_http_headers_out)))
+ {
+ return NGX_ERROR;
+ }
r->headers_out.accept_ranges->key.len = sizeof("Accept-Ranges") - 1;
r->headers_out.accept_ranges->key.data = "Accept-Ranges";
diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.c b/src/http/modules/proxy/ngx_http_proxy_handler.c
index 8483cd7ae..50c199cd2 100644
--- a/src/http/modules/proxy/ngx_http_proxy_handler.c
+++ b/src/http/modules/proxy/ngx_http_proxy_handler.c
@@ -475,6 +475,11 @@ static void ngx_http_proxy_send_request(ngx_http_proxy_ctx_t *p)
/* rc == NGX_OK */
+ if (c->read->ready) {
+ /* post aio operation */
+ ngx_http_proxy_process_upstream_status_line(c->read);
+ }
+
if (ngx_handle_level_write_event(c->write) == NGX_ERROR) {
ngx_http_proxy_finalize_request(p,
NGX_HTTP_INTERNAL_SERVER_ERROR);
@@ -742,8 +747,8 @@ static void ngx_http_proxy_process_upstream_headers(ngx_event_t *rev)
}
}
- ngx_log_debug(c->log, "HTTP proxy header: '%s: %s'" _
- h->key.data _ h->value.data);
+ ngx_log_debug(c->log, "HTTP proxy header: %08X '%s: %s'" _
+ h _ h->key.data _ h->value.data);
continue;
@@ -791,10 +796,6 @@ static ssize_t ngx_http_proxy_read_upstream_header(ngx_http_proxy_ctx_t *p)
n = p->header_in->last - p->header_in->pos;
if (n > 0) {
-#if 0
- /* TODO THINK */
- rev->ready = 0;
-#endif
return n;
}
@@ -804,7 +805,7 @@ static ssize_t ngx_http_proxy_read_upstream_header(ngx_http_proxy_ctx_t *p)
if (n == NGX_AGAIN) {
ngx_add_timer(rev, p->lcf->read_timeout);
- if (ngx_handle_read_event(rev) == NGX_ERROR) {
+ if (ngx_handle_read_event(rev, 0) == NGX_ERROR) {
ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
return NGX_ERROR;
}
@@ -829,10 +830,11 @@ static ssize_t ngx_http_proxy_read_upstream_header(ngx_http_proxy_ctx_t *p)
static void ngx_http_proxy_send_response(ngx_http_proxy_ctx_t *p)
{
- int rc, i;
- ngx_table_elt_t *ch, *ph;
- ngx_event_pipe_t *ep;
- ngx_http_request_t *r;
+ int rc, i;
+ ngx_table_elt_t *ch, *h;
+ ngx_event_pipe_t *ep;
+ ngx_http_request_t *r;
+ ngx_http_core_loc_conf_t *clcf;
r = p->request;
@@ -843,26 +845,26 @@ static void ngx_http_proxy_send_response(ngx_http_proxy_ctx_t *p)
/* copy an upstream header to r->headers_out */
- ph = (ngx_table_elt_t *) p->headers_in.headers->elts;
+ h = p->headers_in.headers->elts;
for (i = 0; i < p->headers_in.headers->nelts; i++) {
- if (&ph[i] == p->headers_in.connection) {
+ if (&h[i] == p->headers_in.connection) {
continue;
}
if (p->accel) {
- if (&ph[i] == p->headers_in.date
- || &ph[i] == p->headers_in.accept_ranges) {
+ if (&h[i] == p->headers_in.date
+ || &h[i] == p->headers_in.accept_ranges) {
continue;
}
- if (&ph[i] == p->headers_in.server && !p->lcf->pass_server) {
+ if (&h[i] == p->headers_in.server && !p->lcf->pass_server) {
continue;
}
}
- if (&ph[i] == p->headers_in.content_type) {
- r->headers_out.content_type = &ph[i];
+ if (&h[i] == p->headers_in.content_type) {
+ r->headers_out.content_type = &h[i];
r->headers_out.content_type->key.len = 0;
continue;
}
@@ -873,7 +875,7 @@ static void ngx_http_proxy_send_response(ngx_http_proxy_ctx_t *p)
return;
}
- *ch = ph[i];
+ *ch = h[i];
/*
* ngx_http_header_filter() output the following headers
@@ -883,17 +885,17 @@ static void ngx_http_proxy_send_response(ngx_http_proxy_ctx_t *p)
* r->headers_out.content_length
*/
- if (&ph[i] == p->headers_in.server) {
+ if (&h[i] == p->headers_in.server) {
r->headers_out.server = ch;
continue;
}
- if (&ph[i] == p->headers_in.date) {
+ if (&h[i] == p->headers_in.date) {
r->headers_out.date = ch;
continue;
}
- if (&ph[i] == p->headers_in.content_length) {
+ if (&h[i] == p->headers_in.content_length) {
r->headers_out.content_length_n =
ngx_atoi(p->headers_in.content_length->value.data,
@@ -977,6 +979,12 @@ static void ngx_http_proxy_send_response(ngx_http_proxy_ctx_t *p)
r->sendfile = 1;
}
+ clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
+
+ ep->read_timeout = p->lcf->read_timeout;
+ ep->send_timeout = clcf->send_timeout;
+ ep->send_lowat = clcf->send_lowat;
+
p->event_pipe = ep;
p->upstream.connection->read->event_handler = ngx_http_proxy_process_body;
diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.h b/src/http/modules/proxy/ngx_http_proxy_handler.h
index f371cbc1c..601a8f6ca 100644
--- a/src/http/modules/proxy/ngx_http_proxy_handler.h
+++ b/src/http/modules/proxy/ngx_http_proxy_handler.h
@@ -44,6 +44,8 @@ typedef struct {
typedef struct {
+ ngx_table_t *headers; /* it must be first field */
+
ngx_table_elt_t *date;
ngx_table_elt_t *server;
ngx_table_elt_t *connection;
@@ -53,8 +55,6 @@ typedef struct {
ngx_table_elt_t *accept_ranges;
off_t content_length_n;
-
- ngx_table_t *headers;
} ngx_http_proxy_headers_in_t;
diff --git a/src/http/ngx_http.h b/src/http/ngx_http.h
index 0bb04c20c..90a47f4a8 100644
--- a/src/http/ngx_http.h
+++ b/src/http/ngx_http.h
@@ -60,6 +60,9 @@ int ngx_http_special_response_handler(ngx_http_request_t *r, int error);
time_t ngx_http_parse_time(char *value, size_t len);
size_t ngx_http_get_time(char *buf, time_t t);
+ngx_table_elt_t *ngx_http_add_header(void *header,
+ ngx_http_header_t *http_headers);
+
int ngx_http_discard_body(ngx_http_request_t *r);
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index 56e99c97e..3725fb9ec 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -4,7 +4,9 @@
#include <ngx_event.h>
#include <ngx_http.h>
#include <nginx.h>
-
+#if __FreeBSD__
+#include <ngx_freebsd_init.h>
+#endif
static void ngx_http_phase_event_handler(ngx_event_t *rev);
@@ -31,6 +33,10 @@ static char *ngx_set_server_name(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
static char *ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
+static char *ngx_http_lowat_check(ngx_conf_t *cf, void *post, void *data);
+
+static ngx_conf_post_t ngx_http_lowat_post = { ngx_http_lowat_check } ;
+
static ngx_command_t ngx_http_core_commands[] = {
@@ -151,6 +157,13 @@ static ngx_command_t ngx_http_core_commands[] = {
offsetof(ngx_http_core_loc_conf_t, send_timeout),
NULL},
+ {ngx_string("send_lowat"),
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
+ ngx_conf_set_size_slot,
+ NGX_HTTP_LOC_CONF_OFFSET,
+ offsetof(ngx_http_core_loc_conf_t, send_lowat),
+ &ngx_http_lowat_post},
+
{ngx_string("keepalive_timeout"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_conf_set_msec_slot,
@@ -506,6 +519,49 @@ int ngx_http_delay_handler(ngx_http_request_t *r)
#endif
+ngx_table_elt_t *ngx_http_add_header(void *header,
+ ngx_http_header_t *http_headers)
+{
+ int i, j;
+ char *prev;
+ ngx_table_t *headers;
+ ngx_table_elt_t *h, *new;
+
+ headers = *(ngx_table_t **) header;
+
+ prev = headers->elts;
+
+ if (!(new = ngx_push_table(headers))) {
+ return NULL;
+ }
+
+ if (prev == headers->elts) {
+ return new;
+ }
+
+ h = headers->elts;
+ for (i = 0; i < headers->nelts; i++) {
+ if (h[i].key.len == 0) {
+ continue;
+ }
+
+ for (j = 0; http_headers[j].name.len != 0; j++) {
+ if (http_headers[j].name.len != h[i].key.len) {
+ continue;
+ }
+
+ if (ngx_strcasecmp(http_headers[j].name.data, h[i].key.data) == 0) {
+ *((ngx_table_elt_t **)
+ ((char *) &header + http_headers[j].offset)) = &h[i];
+ break;
+ }
+ }
+ }
+
+ return new;
+}
+
+
static int ngx_http_core_init(ngx_cycle_t *cycle)
{
#if 0
@@ -852,6 +908,7 @@ static void *ngx_http_core_create_loc_conf(ngx_conf_t *cf)
lcf->client_body_timeout = NGX_CONF_UNSET;
lcf->sendfile = NGX_CONF_UNSET;
lcf->send_timeout = NGX_CONF_UNSET;
+ lcf->send_lowat = NGX_CONF_UNSET;
lcf->discarded_buffer_size = NGX_CONF_UNSET;
lcf->keepalive_timeout = NGX_CONF_UNSET;
lcf->lingering_time = NGX_CONF_UNSET;
@@ -925,6 +982,7 @@ static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf,
prev->client_body_timeout, 10000);
ngx_conf_merge_value(conf->sendfile, prev->sendfile, 0);
ngx_conf_merge_msec_value(conf->send_timeout, prev->send_timeout, 10000);
+ ngx_conf_merge_size_value(conf->send_lowat, prev->send_lowat, 0);
ngx_conf_merge_size_value(conf->discarded_buffer_size,
prev->discarded_buffer_size, 1500);
ngx_conf_merge_msec_value(conf->keepalive_timeout,
@@ -1063,3 +1121,29 @@ static char *ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return NGX_CONF_OK;
}
+
+
+static char *ngx_http_lowat_check(ngx_conf_t *cf, void *post, void *data)
+{
+ int *np = data;
+
+#if (HAVE_LOWAT_EVENT)
+
+ if (*np >= ngx_freebsd_net_inet_tcp_sendspace) {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "\"send_lowat\" must be less than %d "
+ "(sysctl net.inet.tcp.sendspace)",
+ ngx_freebsd_net_inet_tcp_sendspace);
+
+ return NGX_CONF_ERROR;
+ }
+
+#else
+
+ ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
+ "\"send_lowat\" is not supported, ignored");
+
+#endif
+
+ return NGX_CONF_OK;
+}
diff --git a/src/http/ngx_http_header_filter.c b/src/http/ngx_http_header_filter.c
index e8cd5b8a1..e121d00b5 100644
--- a/src/http/ngx_http_header_filter.c
+++ b/src/http/ngx_http_header_filter.c
@@ -102,9 +102,8 @@ static int ngx_http_header_filter(ngx_http_request_t *r)
r->header_only = 1;
}
- /* 9 is for "HTTP/1.x ", 2 is for trailing "\r\n"
- and 2 is for end of header */
- len = 9 + 2 + 2;
+ /* 2 is for trailing "\r\n" and 2 is for "\r\n" in the end of header */
+ len = sizeof("HTTP/1.x ") - 1 + 2 + 2;
/* status line */
if (r->headers_out.status_line.len) {
@@ -150,29 +149,29 @@ static int ngx_http_header_filter(ngx_http_request_t *r)
len += r->headers_out.date->key.len
+ r->headers_out.date->value.len + 2;
} else {
- /* "Date: ... \r\n" */
- len += 37;
+ len += sizeof("Date: Mon, 28 Sep 1970 00:00:00 GMT" CRLF) - 1;
}
if (r->headers_out.content_range && r->headers_out.content_range->value.len)
{
- len += 15 + r->headers_out.content_range->value.len + 2;
+ len += sizeof("Content-Range: ") - 1
+ + r->headers_out.content_range->value.len + 2;
}
if (r->headers_out.content_length == NULL) {
if (r->headers_out.content_length_n >= 0) {
- /* "Content-Length: ... \r\n", 2^64 is 20 characters */
- len += 48;
+ /* 2^64 */
+ len += sizeof("Content-Length: 18446744073709551616" CRLF) - 1;
}
}
if (r->headers_out.content_type && r->headers_out.content_type->value.len) {
r->headers_out.content_type->key.len = 0;
- len += 14 + r->headers_out.content_type->value.len + 2;
+ len += sizeof("Content-Type: ") - 1
+ + r->headers_out.content_type->value.len + 2;
if (r->headers_out.charset.len) {
- /* "; charset= ... " */
- len += 10 + r->headers_out.charset.len;
+ len += sizeof("; charset=") - 1 + r->headers_out.charset.len;
}
}
@@ -187,9 +186,8 @@ static int ngx_http_header_filter(ngx_http_request_t *r)
&& r->headers_out.location->value.data[0] == '/')
{
r->headers_out.location->key.len = 0;
- /* "Location: http:// ... \r\n" */
- len += 17 + r->server_name->len
- + r->headers_out.location->value.len + 2;
+ len += sizeof("Location: http://") - 1,
+ + r->server_name->len + r->headers_out.location->value.len + 2;
if (r->port != 80) {
len += r->port_name->len;
@@ -201,24 +199,20 @@ static int ngx_http_header_filter(ngx_http_request_t *r)
+ r->headers_out.last_modified->value.len + 2;
} else if (r->headers_out.last_modified_time != -1) {
- /* "Last-Modified: ... \r\n" */
- len += 46;
+ len += sizeof("Last-Modified: Mon, 28 Sep 1970 00:00:00 GMT" CRLF) - 1;
}
if (r->chunked) {
- /* "Transfer-Encoding: chunked\r\n" */
- len += 28;
+ len += sizeof("Transfer-Encoding: chunked" CRLF) - 1;
}
if (r->keepalive) {
- /* "Connection: keep-alive\r\n" */
- len += 24;
+ len += sizeof("Connection: keep-alive" CRLF) - 1;
} else {
- /* "Connection: close\r\n" */
- len += 19;
+ len += sizeof("Connection: closed" CRLF) - 1;
}
- header = (ngx_table_elt_t *) r->headers_out.headers->elts;
+ header = r->headers_out.headers->elts;
for (i = 0; i < r->headers_out.headers->nelts; i++) {
if (header[i].key.len == 0) {
continue;
@@ -230,7 +224,7 @@ static int ngx_http_header_filter(ngx_http_request_t *r)
ngx_test_null(h, ngx_create_temp_hunk(r->pool, len, 0, 64), NGX_ERROR);
/* "HTTP/1.x " */
- h->last = ngx_cpymem(h->last, "HTTP/1.1 ", 9);
+ h->last = ngx_cpymem(h->last, "HTTP/1.1 ", sizeof("HTTP/1.x ") - 1);
/* status line */
if (r->headers_out.status_line.len) {
@@ -248,7 +242,7 @@ static int ngx_http_header_filter(ngx_http_request_t *r)
}
if (!(r->headers_out.date && r->headers_out.date->key.len)) {
- h->last = ngx_cpymem(h->last, "Date: ", 6);
+ h->last = ngx_cpymem(h->last, "Date: ", sizeof("Date: ") - 1);
h->last += ngx_http_get_time(h->last, time(NULL));
*(h->last++) = CR; *(h->last++) = LF;
}
@@ -256,7 +250,8 @@ static int ngx_http_header_filter(ngx_http_request_t *r)
if (r->headers_out.content_range && r->headers_out.content_range->value.len)
{
- h->last = ngx_cpymem(h->last, "Content-Range: ", 15);
+ h->last = ngx_cpymem(h->last, "Content-Range: ",
+ sizeof("Content-Range: ") - 1);
h->last = ngx_cpymem(h->last, r->headers_out.content_range->value.data,
r->headers_out.content_range->value.len);
*(h->last++) = CR; *(h->last++) = LF;
@@ -265,19 +260,22 @@ static int ngx_http_header_filter(ngx_http_request_t *r)
if (r->headers_out.content_length == NULL) {
/* 2^64 is 20 characters */
if (r->headers_out.content_length_n >= 0) {
- h->last += ngx_snprintf(h->last, 49,
- "Content-Length: " OFF_FMT CRLF,
- r->headers_out.content_length_n);
+ h->last += ngx_snprintf(h->last,
+ sizeof("Content-Length: 18446744073709551616" CRLF),
+ "Content-Length: " OFF_FMT CRLF,
+ r->headers_out.content_length_n);
}
}
if (r->headers_out.content_type && r->headers_out.content_type->value.len) {
- h->last = ngx_cpymem(h->last, "Content-Type: ", 14);
+ h->last = ngx_cpymem(h->last, "Content-Type: ",
+ sizeof("Content-Type: ") - 1);
h->last = ngx_cpymem(h->last, r->headers_out.content_type->value.data,
r->headers_out.content_type->value.len);
if (r->headers_out.charset.len) {
- h->last = ngx_cpymem(h->last, "; charset=", 10);
+ h->last = ngx_cpymem(h->last, "; charset=",
+ sizeof("; charset=") - 1);
h->last = ngx_cpymem(h->last, r->headers_out.charset.data,
r->headers_out.charset.len);
}
@@ -288,7 +286,8 @@ static int ngx_http_header_filter(ngx_http_request_t *r)
if (r->headers_out.content_encoding
&& r->headers_out.content_encoding->value.len)
{
- h->last = ngx_cpymem(h->last, "Content-Encoding: ", 18);
+ h->last = ngx_cpymem(h->last, "Content-Encoding: ",
+ sizeof("Content-Encoding: ") - 1);
h->last = ngx_cpymem(h->last,
r->headers_out.content_encoding->value.data,
r->headers_out.content_encoding->value.len);
@@ -300,7 +299,8 @@ static int ngx_http_header_filter(ngx_http_request_t *r)
&& r->headers_out.location->value.len
&& r->headers_out.location->value.data[0] == '/')
{
- h->last = ngx_cpymem(h->last, "Location: http://", 17);
+ h->last = ngx_cpymem(h->last, "Location: http://",
+ sizeof("Location: http://") - 1);
h->last = ngx_cpymem(h->last, r->server_name->data,
r->server_name->len);
if (r->port != 80) {
@@ -317,21 +317,25 @@ static int ngx_http_header_filter(ngx_http_request_t *r)
if (!(r->headers_out.last_modified && r->headers_out.last_modified->key.len)
&& r->headers_out.last_modified_time != -1)
{
- h->last = ngx_cpymem(h->last, "Last-Modified: ", 15);
+ h->last = ngx_cpymem(h->last, "Last-Modified: ",
+ sizeof("Last-Modified: ") - 1);
h->last += ngx_http_get_time(h->last,
- r->headers_out.last_modified_time);
+ r->headers_out.last_modified_time);
*(h->last++) = CR; *(h->last++) = LF;
}
if (r->chunked) {
- h->last = ngx_cpymem(h->last, "Transfer-Encoding: chunked" CRLF, 28);
+ h->last = ngx_cpymem(h->last, "Transfer-Encoding: chunked" CRLF,
+ sizeof("Transfer-Encoding: chunked" CRLF) - 1);
}
if (r->keepalive) {
- h->last = ngx_cpymem(h->last, "Connection: keep-alive" CRLF, 24);
+ h->last = ngx_cpymem(h->last, "Connection: keep-alive" CRLF,
+ sizeof("Connection: keep-alive" CRLF) - 1);
} else {
- h->last = ngx_cpymem(h->last, "Connection: close" CRLF, 19);
+ h->last = ngx_cpymem(h->last, "Connection: close" CRLF,
+ sizeof("Connection: close" CRLF) - 1);
}
for (i = 0; i < r->headers_out.headers->nelts; i++) {
diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c
index e3a495234..87a0799b5 100644
--- a/src/http/ngx_http_request.c
+++ b/src/http/ngx_http_request.c
@@ -44,7 +44,7 @@ static char *client_header_errors[] = {
-static ngx_http_header_t headers_in[] = {
+ngx_http_header_t ngx_http_headers_in[] = {
{ ngx_string("Host"), offsetof(ngx_http_headers_in_t, host) },
{ ngx_string("Connection"), offsetof(ngx_http_headers_in_t, connection) },
{ ngx_string("If-Modified-Since"),
@@ -66,6 +66,27 @@ static ngx_http_header_t headers_in[] = {
};
+ngx_http_header_t ngx_http_headers_out[] = {
+ { ngx_string("Server"), offsetof(ngx_http_headers_out_t, server) },
+ { ngx_string("Date"), offsetof(ngx_http_headers_out_t, date) },
+ { ngx_string("Content-Type"),
+ offsetof(ngx_http_headers_out_t, content_type) },
+ { ngx_string("Content-Length"),
+ offsetof(ngx_http_headers_out_t, content_length) },
+ { ngx_string("Content-Encoding"),
+ offsetof(ngx_http_headers_out_t, content_encoding) },
+
+ /* Location */
+
+ { ngx_string("Last-Modified"),
+ offsetof(ngx_http_headers_out_t, last_modified) },
+ { ngx_string("Accept-Ranges"),
+ offsetof(ngx_http_headers_out_t, accept_ranges) },
+
+ { ngx_null_string, 0 }
+};
+
+
static void ngx_http_dummy(ngx_event_t *wev)
{
return;
@@ -106,20 +127,14 @@ void ngx_http_init_connection(ngx_connection_t *c)
rev->event_handler = ngx_http_init_request;
if (rev->ready) {
- /* deferred accept */
+ /* deferred accept, aio, iocp, epoll */
ngx_http_init_request(rev);
return;
}
ngx_add_timer(rev, c->listening->post_accept_timeout);
- if (ngx_event_flags & (NGX_USE_AIO_EVENT|NGX_USE_EDGE_EVENT)) {
- /* aio, iocp, epoll */
- ngx_http_init_request(rev);
- return;
- }
-
- if (ngx_handle_read_event(rev) == NGX_ERROR) {
+ if (ngx_handle_read_event(rev, 0) == NGX_ERROR) {
ngx_http_close_connection(c);
return;
}
@@ -256,7 +271,7 @@ ngx_log_debug(rev->log, "IN: %08x" _ in_port);
return;
}
- r->headers_out.headers = ngx_create_table(r->pool, 10);
+ r->headers_out.headers = ngx_create_table(r->pool, 1);
if (r->headers_out.headers == NULL) {
ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
ngx_http_close_connection(c);
@@ -451,7 +466,7 @@ static void ngx_http_process_request_line(ngx_event_t *rev)
lctx = c->log->data;
lctx->action = "reading client request headers";
lctx->url = r->unparsed_uri.data;
- r->headers_in.headers = ngx_create_table(r->pool, 10);
+ r->headers_in.headers = ngx_create_table(r->pool, 1);
if (cscf->large_client_header
&& r->header_in->pos == r->header_in->last)
@@ -560,8 +575,8 @@ static void ngx_http_process_request_headers(ngx_event_t *rev)
/* a header line has been parsed successfully */
- h = ngx_push_table(r->headers_in.headers);
- if (h == NULL) {
+ if (!(h = ngx_http_add_header(&r->headers_in, ngx_http_headers_in)))
+ {
ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
ngx_http_close_connection(c);
return;
@@ -593,14 +608,16 @@ static void ngx_http_process_request_headers(ngx_event_t *rev)
h->value.data[h->value.len] = '\0';
}
- for (i = 0; headers_in[i].name.len != 0; i++) {
- if (headers_in[i].name.len != h->key.len) {
+ for (i = 0; ngx_http_headers_in[i].name.len != 0; i++) {
+ if (ngx_http_headers_in[i].name.len != h->key.len) {
continue;
}
- if (ngx_strcasecmp(headers_in[i].name.data, h->key.data) == 0) {
- *((ngx_table_elt_t **)
- ((char *) &r->headers_in + headers_in[i].offset)) = h;
+ if (ngx_strcasecmp(ngx_http_headers_in[i].name.data,
+ h->key.data) == 0)
+ {
+ *((ngx_table_elt_t **) ((char *) &r->headers_in
+ + ngx_http_headers_in[i].offset)) = h;
break;
}
}
@@ -692,10 +709,6 @@ static ssize_t ngx_http_read_request_header(ngx_http_request_t *r)
n = r->header_in->last - r->header_in->pos;
if (n > 0) {
-#if 0
- /* TODO: THINK - AIO ??? */
- rev->ready = 0;
-#endif
return n;
}
@@ -709,7 +722,7 @@ static ssize_t ngx_http_read_request_header(ngx_http_request_t *r)
r->header_timeout_set = 1;
}
- if (ngx_handle_read_event(rev) == NGX_ERROR) {
+ if (ngx_handle_read_event(rev, 0) == NGX_ERROR) {
ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
ngx_http_close_connection(r->connection);
return NGX_ERROR;
@@ -1157,7 +1170,7 @@ static void ngx_http_set_keepalive(ngx_http_request_t *r)
c->tcp_nopush = 0;
}
- if (rev->ready || (ngx_event_flags & NGX_USE_AIO_EVENT)) {
+ if (rev->ready) {
ngx_http_keepalive_handler(rev);
}
}
@@ -1256,7 +1269,7 @@ static void ngx_http_set_lingering_close(ngx_http_request_t *r)
return;
}
- if (rev->ready || (ngx_event_flags & NGX_USE_AIO_EVENT)) {
+ if (rev->ready) {
ngx_http_lingering_close_handler(rev);
}
}
diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h
index a05b97c48..5c7ffb726 100644
--- a/src/http/ngx_http_request.h
+++ b/src/http/ngx_http_request.h
@@ -68,6 +68,8 @@ typedef struct {
typedef struct {
+ ngx_table_t *headers; /* it must be first field */
+
ngx_table_elt_t *host;
ngx_table_elt_t *connection;
ngx_table_elt_t *if_modified_since;
@@ -83,8 +85,6 @@ typedef struct {
ssize_t content_length_n;
size_t connection_type;
ssize_t keep_alive_n;
-
- ngx_table_t *headers;
} ngx_http_headers_in_t;
@@ -108,6 +108,8 @@ typedef struct {
typedef struct {
+ ngx_table_t *headers; /* it must be first field */
+
int status;
ngx_str_t status_line;
@@ -124,8 +126,6 @@ typedef struct {
ngx_str_t charset;
ngx_array_t ranges;
- ngx_table_t *headers;
-
off_t content_length_n;
char *etag;
time_t date_time;
@@ -231,4 +231,9 @@ struct ngx_http_request_s {
};
+extern ngx_http_header_t ngx_http_headers_in[];
+extern ngx_http_header_t ngx_http_headers_out[];
+
+
+
#endif /* _NGX_HTTP_REQUEST_H_INCLUDED_ */
diff --git a/src/http/ngx_http_request_body.c b/src/http/ngx_http_request_body.c
index 1c9cd97a5..19730e7b3 100644
--- a/src/http/ngx_http_request_body.c
+++ b/src/http/ngx_http_request_body.c
@@ -112,7 +112,7 @@ static void ngx_http_read_client_request_body_handler(ngx_event_t *rev)
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
ngx_add_timer(rev, clcf->client_body_timeout);
- if (ngx_handle_read_event(rev) == NGX_ERROR) {
+ if (ngx_handle_read_event(rev, 0) == NGX_ERROR) {
ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
}
diff --git a/src/http/ngx_http_special_response.c b/src/http/ngx_http_special_response.c
index c1a37f1ca..8f9d8ce7d 100644
--- a/src/http/ngx_http_special_response.c
+++ b/src/http/ngx_http_special_response.c
@@ -218,9 +218,11 @@ int ngx_http_special_response_handler(ngx_http_request_t *r, int error)
+ sizeof(error_tail) - 1
+ sizeof(msie_stub) - 1;
- ngx_test_null(r->headers_out.content_type,
- ngx_push_table(r->headers_out.headers),
- NGX_HTTP_INTERNAL_SERVER_ERROR);
+ if (!(r->headers_out.content_type =
+ ngx_http_add_header(&r->headers_out, ngx_http_headers_out)))
+ {
+ return NGX_ERROR;
+ }
r->headers_out.content_type->key.len = 12;
r->headers_out.content_type->key.data = "Content-Type";
@@ -245,7 +247,9 @@ int ngx_http_special_response_handler(ngx_http_request_t *r, int error)
out = NULL;
ll = NULL;
- ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR);
+ if (!(h = ngx_calloc_hunk(r->pool))) {
+ return NGX_ERROR;
+ }
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;
@@ -254,7 +258,9 @@ int ngx_http_special_response_handler(ngx_http_request_t *r, int error)
ngx_chain_add_link(out, ll, cl);
- ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR);
+ if (!(h = ngx_calloc_hunk(r->pool))) {
+ return NGX_ERROR;
+ }
h->type = NGX_HUNK_MEMORY|NGX_HUNK_IN_MEMORY;
h->pos = error_tail;
h->last = error_tail + sizeof(error_tail) - 1;
@@ -270,7 +276,9 @@ int ngx_http_special_response_handler(ngx_http_request_t *r, int error)
&& error != NGX_HTTP_REQUEST_URI_TOO_LARGE
)
{
- ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR);
+ if (!(h = ngx_calloc_hunk(r->pool))) {
+ return NGX_ERROR;
+ }
h->type = NGX_HUNK_MEMORY|NGX_HUNK_IN_MEMORY;
h->pos = msie_stub;
h->last = msie_stub + sizeof(msie_stub) - 1;