comparison src/http/ngx_http_event.c @ 18:72ad26c77d2d

nginx-0.0.1-2002-10-04-21:58:04 import
author Igor Sysoev <igor@sysoev.ru>
date Fri, 04 Oct 2002 17:58:04 +0000
parents 8dd06e2844f5
children d7908993fdeb
comparison
equal deleted inserted replaced
17:8dd06e2844f5 18:72ad26c77d2d
45 static int ngx_http_special_response(ngx_http_request_t *r, int error); 45 static int ngx_http_special_response(ngx_http_request_t *r, int error);
46 static int ngx_http_redirect(ngx_http_request_t *r, int redirect); 46 static int ngx_http_redirect(ngx_http_request_t *r, int redirect);
47 static int ngx_http_error(ngx_http_request_t *r, int error); 47 static int ngx_http_error(ngx_http_request_t *r, int error);
48 48
49 static int ngx_http_close_request(ngx_http_request_t *r); 49 static int ngx_http_close_request(ngx_http_request_t *r);
50 static int ngx_http_close_connection(ngx_event_t *ev);
50 static size_t ngx_http_log_error(void *data, char *buf, size_t len); 51 static size_t ngx_http_log_error(void *data, char *buf, size_t len);
51 52
52 53
53 54
54 static char *header_errors[] = { 55 static char *header_errors[] = {
67 ngx_http_server_t *srv; 68 ngx_http_server_t *srv;
68 ngx_http_log_ctx_t *ctx; 69 ngx_http_log_ctx_t *ctx;
69 70
70 ev = c->read; 71 ev = c->read;
71 ev->event_handler = ngx_http_init_request; 72 ev->event_handler = ngx_http_init_request;
73
72 srv = (ngx_http_server_t *) c->server; 74 srv = (ngx_http_server_t *) c->server;
73 75
74 ngx_test_null(c->pool, 76 ngx_test_null(c->pool,
75 ngx_create_pool(srv->connection_pool_size, ev->log), 77 ngx_create_pool(srv->connection_pool_size, ev->log),
76 NGX_ERROR); 78 NGX_ERROR);
79
80 ngx_test_null(c->requests, ngx_create_array(c->pool, 10, sizeof(char *)),
81 NGX_ERROR);
82
83 ev->close_handler = ngx_http_close_connection;
84 c->write->close_handler = ngx_http_close_connection;
77 85
78 ngx_test_null(addr, ngx_palloc(c->pool, c->socklen), NGX_ERROR); 86 ngx_test_null(addr, ngx_palloc(c->pool, c->socklen), NGX_ERROR);
79 ngx_memcpy(addr, c->sockaddr, c->socklen); 87 ngx_memcpy(addr, c->sockaddr, c->socklen);
80 c->sockaddr = addr; 88 c->sockaddr = addr;
81 89
238 } 246 }
239 247
240 248
241 static int ngx_http_process_request_line(ngx_http_request_t *r) 249 static int ngx_http_process_request_line(ngx_http_request_t *r)
242 { 250 {
243 int rc; 251 int rc, len;
252 char **request;
253 ngx_connection_t *c;
244 ngx_http_log_ctx_t *ctx; 254 ngx_http_log_ctx_t *ctx;
245 255
246 rc = ngx_read_http_request_line(r); 256 rc = ngx_read_http_request_line(r);
257
258 c = r->connection;
247 259
248 if (rc == NGX_OK) { 260 if (rc == NGX_OK) {
249 ngx_test_null(r->uri, 261 ngx_test_null(r->uri,
250 ngx_palloc(r->pool, r->uri_end - r->uri_start + 1), 262 ngx_palloc(r->pool, r->uri_end - r->uri_start + 1),
251 ngx_http_close_request(r)); 263 ngx_http_close_request(r));
252 ngx_cpystrn(r->uri, r->uri_start, r->uri_end - r->uri_start + 1); 264 ngx_cpystrn(r->uri, r->uri_start, r->uri_end - r->uri_start + 1);
265
266 ngx_test_null(request, ngx_push_array(c->requests),
267 ngx_http_close_request(r));
268
269 if (r->request_end)
270 len = r->request_end - r->header_in->start + 1;
271 else
272 len = 1;
273 c->requests_len += len;
274 ngx_test_null(*request, ngx_palloc(c->pool, len),
275 ngx_http_close_request(r));
276 ngx_cpystrn(*request, r->header_in->start, len);
277
278 ngx_log_debug(c->log, "REQ: '%s'" _ *request);
253 279
254 if (r->uri_ext) { 280 if (r->uri_ext) {
255 ngx_test_null(r->exten, 281 ngx_test_null(r->exten,
256 ngx_palloc(r->pool, r->uri_end - r->uri_ext + 1), 282 ngx_palloc(r->pool, r->uri_end - r->uri_ext + 1),
257 ngx_http_close_request(r)); 283 ngx_http_close_request(r));
860 886
861 return NGX_DONE; 887 return NGX_DONE;
862 } 888 }
863 889
864 890
891 static int ngx_http_close_connection(ngx_event_t *ev)
892 {
893 int i, len;
894 char **requests, *requests_line, *prev, *new;
895 ngx_connection_t *c = (ngx_connection_t *) ev->data;
896
897 if (c->requests->nelts > 1) {
898 len = c->requests_len + c->requests->nelts * 2 - 1;
899
900 ngx_test_null(requests_line, ngx_palloc(c->pool, len),
901 ngx_event_close_connection(ev));
902
903 requests = (char **) c->requests->elts;
904 prev = requests_line;
905 new = ngx_cpystrn(prev, requests[0], len);
906 len -= new - prev;
907 prev = new;
908
909 for (i = 1; i < c->requests->nelts; i++) {
910 new = ngx_cpystrn(prev, ", ", len);
911 new = ngx_cpystrn(new, requests[i], len);
912 len -= new - prev;
913 prev = new;
914 }
915
916 } else {
917 requests_line = * (char **) c->requests->elts;
918 }
919
920 ngx_log_error(NGX_LOG_INFO, c->log, 0,
921 "REQUESTS: %d, '%s'", c->requests->nelts, requests_line);
922
923 return ngx_event_close_connection(ev);
924 }
925
926
865 static size_t ngx_http_log_error(void *data, char *buf, size_t len) 927 static size_t ngx_http_log_error(void *data, char *buf, size_t len)
866 { 928 {
867 ngx_http_log_ctx_t *ctx = (ngx_http_log_ctx_t *) data; 929 ngx_http_log_ctx_t *ctx = (ngx_http_log_ctx_t *) data;
868 930
869 if (ctx->url) 931 if (ctx->url)