nginx-0.0.1-2002-10-04-21:58:04 import
diff --git a/src/http/ngx_http.c b/src/http/ngx_http.c index 7cecd5d..83ce8dd 100644 --- a/src/http/ngx_http.c +++ b/src/http/ngx_http.c
@@ -31,8 +31,8 @@ #if (WIN32) ngx_http_server.doc_root = "html"; #else - ngx_http_server.doc_root = "/home/is/dox/"; ngx_http_server.doc_root = "/home/is/work/xml/site-1.0.0/html"; + ngx_http_server.doc_root = "/home/is/dox/"; #endif ngx_http_server.doc_root_len = strlen(ngx_http_server.doc_root) + 1;
diff --git a/src/http/ngx_http.h b/src/http/ngx_http.h index 28c4321..026c167 100644 --- a/src/http/ngx_http.h +++ b/src/http/ngx_http.h
@@ -122,14 +122,15 @@ unsigned logging:1; unsigned header_only:1; - unsigned unusual_uri:1; - unsigned complex_uri:1; + unsigned unusual_uri:1; /* URI is not started with '/' - "GET http://" */ + unsigned complex_uri:1; /* URI with "./" or with "//" */ int state; char *uri_start; char *uri_end; char *uri_ext; char *args_start; + char *request_end; char *header_name_start; char *header_name_end; char *header_start;
diff --git a/src/http/ngx_http_event.c b/src/http/ngx_http_event.c index aa56704..258a6c7 100644 --- a/src/http/ngx_http_event.c +++ b/src/http/ngx_http_event.c
@@ -47,6 +47,7 @@ static int ngx_http_error(ngx_http_request_t *r, int error); static int ngx_http_close_request(ngx_http_request_t *r); +static int ngx_http_close_connection(ngx_event_t *ev); static size_t ngx_http_log_error(void *data, char *buf, size_t len); @@ -69,12 +70,19 @@ ev = c->read; ev->event_handler = ngx_http_init_request; + srv = (ngx_http_server_t *) c->server; ngx_test_null(c->pool, ngx_create_pool(srv->connection_pool_size, ev->log), NGX_ERROR); + ngx_test_null(c->requests, ngx_create_array(c->pool, 10, sizeof(char *)), + NGX_ERROR); + + ev->close_handler = ngx_http_close_connection; + c->write->close_handler = ngx_http_close_connection; + ngx_test_null(addr, ngx_palloc(c->pool, c->socklen), NGX_ERROR); ngx_memcpy(addr, c->sockaddr, c->socklen); c->sockaddr = addr; @@ -240,17 +248,35 @@ static int ngx_http_process_request_line(ngx_http_request_t *r) { - int rc; + int rc, len; + char **request; + ngx_connection_t *c; ngx_http_log_ctx_t *ctx; rc = ngx_read_http_request_line(r); + c = r->connection; + if (rc == NGX_OK) { ngx_test_null(r->uri, ngx_palloc(r->pool, r->uri_end - r->uri_start + 1), ngx_http_close_request(r)); ngx_cpystrn(r->uri, r->uri_start, r->uri_end - r->uri_start + 1); + ngx_test_null(request, ngx_push_array(c->requests), + ngx_http_close_request(r)); + + if (r->request_end) + len = r->request_end - r->header_in->start + 1; + else + len = 1; + c->requests_len += len; + ngx_test_null(*request, ngx_palloc(c->pool, len), + ngx_http_close_request(r)); + ngx_cpystrn(*request, r->header_in->start, len); + + ngx_log_debug(c->log, "REQ: '%s'" _ *request); + if (r->uri_ext) { ngx_test_null(r->exten, ngx_palloc(r->pool, r->uri_end - r->uri_ext + 1), @@ -862,6 +888,42 @@ } +static int ngx_http_close_connection(ngx_event_t *ev) +{ + int i, len; + char **requests, *requests_line, *prev, *new; + ngx_connection_t *c = (ngx_connection_t *) ev->data; + + if (c->requests->nelts > 1) { + len = c->requests_len + c->requests->nelts * 2 - 1; + + ngx_test_null(requests_line, ngx_palloc(c->pool, len), + ngx_event_close_connection(ev)); + + requests = (char **) c->requests->elts; + prev = requests_line; + new = ngx_cpystrn(prev, requests[0], len); + len -= new - prev; + prev = new; + + for (i = 1; i < c->requests->nelts; i++) { + new = ngx_cpystrn(prev, ", ", len); + new = ngx_cpystrn(new, requests[i], len); + len -= new - prev; + prev = new; + } + + } else { + requests_line = * (char **) c->requests->elts; + } + + ngx_log_error(NGX_LOG_INFO, c->log, 0, + "REQUESTS: %d, '%s'", c->requests->nelts, requests_line); + + return ngx_event_close_connection(ev); +} + + static size_t ngx_http_log_error(void *data, char *buf, size_t len) { ngx_http_log_ctx_t *ctx = (ngx_http_log_ctx_t *) data;
diff --git a/src/http/ngx_http_parse.c b/src/http/ngx_http_parse.c index 155dec6..8f2db68 100644 --- a/src/http/ngx_http_parse.c +++ b/src/http/ngx_http_parse.c
@@ -32,7 +32,7 @@ state, p, r->header_in->last, ch, p); */ - /* GCC 2.95.2 and VC 6.0 compiles this switch as jump table */ + /* GCC 2.95.2 and VC 6.0 compile this switch as jump table */ switch (state) { @@ -257,7 +257,6 @@ return NGX_HTTP_PARSE_INVALID_REQUEST; r->http_minor = ch - '0'; - state = sw_minor_digit; break; @@ -281,6 +280,7 @@ /* end of request line */ case sw_almost_done: + r->request_end = p - 2; switch (ch) { case LF: state = sw_done; @@ -295,6 +295,8 @@ r->header_in->pos.mem = p; if (state == sw_done) { + if (r->request_end == NULL) + r->request_end = p - 1; r->http_version = r->http_major * 1000 + r->http_minor; r->state = sw_start; if (r->http_version == 9 && r->method == NGX_HTTP_HEAD)