comparison src/http/ngx_http_event.c @ 24:77c7629a2627

nginx-0.0.1-2002-12-10-21:05:12 import
author Igor Sysoev <igor@sysoev.ru>
date Tue, 10 Dec 2002 18:05:12 +0000
parents f540a63026c9
children 53cb81681040
comparison
equal deleted inserted replaced
23:f540a63026c9 24:77c7629a2627
20 /* STUB */ 20 /* STUB */
21 #include <ngx_http_output_filter.h> 21 #include <ngx_http_output_filter.h>
22 int ngx_http_static_handler(ngx_http_request_t *r); 22 int ngx_http_static_handler(ngx_http_request_t *r);
23 int ngx_http_index_handler(ngx_http_request_t *r); 23 int ngx_http_index_handler(ngx_http_request_t *r);
24 int ngx_http_proxy_handler(ngx_http_request_t *r); 24 int ngx_http_proxy_handler(ngx_http_request_t *r);
25 /* */ 25 /**/
26 26
27 int ngx_http_init_connection(ngx_connection_t *c); 27 int ngx_http_init_connection(ngx_connection_t *c);
28 28
29 static int ngx_http_init_request(ngx_event_t *ev); 29 static int ngx_http_init_request(ngx_event_t *ev);
30 static int ngx_http_process_request(ngx_event_t *ev); 30 static int ngx_http_process_request_header(ngx_event_t *ev);
31 31
32 static int ngx_http_process_request_line(ngx_http_request_t *r); 32 static int ngx_http_process_request_line(ngx_http_request_t *r);
33 static int ngx_http_process_request_header(ngx_http_request_t *r); 33 static int ngx_http_process_request_headers(ngx_http_request_t *r);
34 static int ngx_http_process_request_header_line(ngx_http_request_t *r); 34 static int ngx_http_process_request_header_line(ngx_http_request_t *r);
35 35
36 static int ngx_http_event_handler(ngx_http_request_t *r);
36 static int ngx_http_block_read(ngx_event_t *ev); 37 static int ngx_http_block_read(ngx_event_t *ev);
38
39
37 static int ngx_http_read_discarded_body(ngx_event_t *ev); 40 static int ngx_http_read_discarded_body(ngx_event_t *ev);
38 41
39 static int ngx_http_event_handler(ngx_http_request_t *r); 42 int ngx_http_handler(ngx_http_request_t *r);
40 static int ngx_http_handler(ngx_http_request_t *r);
41 static int ngx_http_set_default_handler(ngx_http_request_t *r); 43 static int ngx_http_set_default_handler(ngx_http_request_t *r);
42 44
43 static int ngx_http_writer(ngx_event_t *ev); 45 static int ngx_http_writer(ngx_event_t *ev);
44 static int ngx_http_set_lingering_close(ngx_http_request_t *r); 46 static int ngx_http_set_lingering_close(ngx_http_request_t *r);
45 static int ngx_http_keepalive_handler(ngx_event_t *ev); 47 static int ngx_http_keepalive_handler(ngx_event_t *ev);
46 static int ngx_http_lingering_close(ngx_event_t *ev); 48 static int ngx_http_lingering_close(ngx_event_t *ev);
47 49
48 static int ngx_http_special_response(ngx_http_request_t *r, int error); 50 #if 0
49 static int ngx_http_redirect(ngx_http_request_t *r, int redirect); 51 int ngx_http_special_response(ngx_http_request_t *r, int error);
50 static int ngx_http_error(ngx_http_request_t *r, int error); 52 int ngx_http_redirect(ngx_http_request_t *r, int redirect);
51 53 int ngx_http_error(ngx_http_request_t *r, int error);
52 static int ngx_http_close_request(ngx_http_request_t *r); 54 int ngx_http_close_request(ngx_http_request_t *r);
55 #endif
56
53 static int ngx_http_close_connection(ngx_event_t *ev); 57 static int ngx_http_close_connection(ngx_event_t *ev);
54 static size_t ngx_http_log_error(void *data, char *buf, size_t len); 58 static size_t ngx_http_log_error(void *data, char *buf, size_t len);
55 59
56 60
57 61
97 101
98 ngx_test_null(addr, ngx_palloc(c->pool, c->socklen), NGX_ERROR); 102 ngx_test_null(addr, ngx_palloc(c->pool, c->socklen), NGX_ERROR);
99 ngx_memcpy(addr, c->sockaddr, c->socklen); 103 ngx_memcpy(addr, c->sockaddr, c->socklen);
100 c->sockaddr = addr; 104 c->sockaddr = addr;
101 105
102 ngx_test_null(c->addr_text, ngx_palloc(c->pool, c->addr_textlen), 106 ngx_test_null(c->addr_text.data, ngx_palloc(c->pool, c->addr_text.len),
103 NGX_ERROR); 107 NGX_ERROR);
108
109 /* STUB: should be ngx_inet_ntop() */
104 #if (WIN32) 110 #if (WIN32)
105 c->addr_text = inet_ntoa((struct in_addr *) 111 c->addr_text.data = inet_ntoa((struct in_addr *)
106 ((char *)c->sockaddr + c->addr)); 112 ((char *)c->sockaddr + c->addr));
107 #else 113 #else
108 inet_ntop(c->family, (char *)c->sockaddr + c->addr, 114 inet_ntop(c->family, (char *)c->sockaddr + c->addr,
109 c->addr_text, c->addr_textlen); 115 c->addr_text.data, c->addr_text.len);
110 #endif 116 #endif
117 /**/
111 118
112 ngx_test_null(ctx, ngx_pcalloc(c->pool, sizeof(ngx_http_log_ctx_t)), 119 ngx_test_null(ctx, ngx_pcalloc(c->pool, sizeof(ngx_http_log_ctx_t)),
113 NGX_ERROR); 120 NGX_ERROR);
114 ctx->client = c->addr_text; 121 ctx->client = c->addr_text.data;
115 ctx->action = "reading client request line"; 122 ctx->action = "reading client request line";
116 c->log->data = ctx; 123 c->log->data = ctx;
117 c->log->handler = ngx_http_log_error; 124 c->log->handler = ngx_http_log_error;
118 125
119 #if (HAVE_DEFERRED_ACCEPT) 126 #if (HAVE_DEFERRED_ACCEPT)
120 if (ev->ready) { 127 if (ev->ready) {
121 return ngx_http_init_request(ev); 128 return ngx_http_init_request(ev);
122 } else { 129 } else {
123 #endif 130 #endif
131 /* STUB: post_accept_timeout should be in http_conf */
124 ngx_add_timer(ev, c->post_accept_timeout); 132 ngx_add_timer(ev, c->post_accept_timeout);
125 #if (USE_KQUEUE) 133 #if (USE_KQUEUE)
126 return ngx_add_event(ev, NGX_READ_EVENT, NGX_CLEAR_EVENT); 134 return ngx_add_event(ev, NGX_READ_EVENT, NGX_CLEAR_EVENT);
127 #else 135 #else
128 #if (HAVE_AIO_EVENT) 136 #if (HAVE_AIO_EVENT)
157 165
158 c->data = r; 166 c->data = r;
159 r->connection = c; 167 r->connection = c;
160 r->server = srv; 168 r->server = srv;
161 169
170 /* STUB */
162 r->srv_conf = ngx_srv_conf; 171 r->srv_conf = ngx_srv_conf;
163 r->loc_conf = ngx_loc_conf; 172 r->loc_conf = ngx_loc_conf;
173 /**/
164 174
165 if (c->buffer == NULL) { 175 if (c->buffer == NULL) {
166 ngx_test_null(c->buffer, 176 ngx_test_null(c->buffer,
167 ngx_create_temp_hunk(c->pool, srv->header_buffer_size, 177 ngx_create_temp_hunk(c->pool, srv->header_buffer_size,
168 0, 0), 178 0, 0),
177 ngx_http_close_request(r)); 187 ngx_http_close_request(r));
178 188
179 ngx_test_null(r->ctx, ngx_pcalloc(r->pool, sizeof(void *) * ngx_max_module), 189 ngx_test_null(r->ctx, ngx_pcalloc(r->pool, sizeof(void *) * ngx_max_module),
180 ngx_http_close_request(r)); 190 ngx_http_close_request(r));
181 191
182 ev->event_handler = ngx_http_process_request; 192 ev->event_handler = ngx_http_process_request_header;
183 r->state_handler = ngx_http_process_request_line; 193 r->state_handler = ngx_http_process_request_line;
184 r->process_header = 1;
185 r->header_timeout = 1; 194 r->header_timeout = 1;
186 195
187 return ngx_http_process_request(ev); 196 return ngx_http_process_request_header(ev);
188 } 197 }
189 198
190 199
191 static int ngx_http_process_request(ngx_event_t *ev) 200 static int ngx_http_process_request_header(ngx_event_t *ev)
192 { 201 {
193 int n, rc; 202 int n, rc;
194 ngx_connection_t *c ; 203 ngx_connection_t *c ;
195 ngx_http_request_t *r; 204 ngx_http_request_t *r;
196 ngx_http_log_ctx_t *ctx; 205 ngx_http_log_ctx_t *ctx;
211 220
212 if (n == NGX_AGAIN) { 221 if (n == NGX_AGAIN) {
213 if (r->header_timeout) { 222 if (r->header_timeout) {
214 r->header_timeout = 0; 223 r->header_timeout = 0;
215 ngx_del_timer(ev); 224 ngx_del_timer(ev);
225 /* STUB: r->server->header_timeout
226 OR r->srv_conf->header_timeout ? */
216 ngx_add_timer(ev, r->server->header_timeout); 227 ngx_add_timer(ev, r->server->header_timeout);
217 } 228 }
218 return NGX_AGAIN; 229 return NGX_AGAIN;
219 } 230 }
220 231
222 return ngx_http_close_request(r); 233 return ngx_http_close_request(r);
223 234
224 ngx_log_debug(ev->log, "http read %d" _ n); 235 ngx_log_debug(ev->log, "http read %d" _ n);
225 236
226 if (n == 0) { 237 if (n == 0) {
227 if (c->unexpected_eof) 238 ngx_log_error(NGX_LOG_INFO, c->log, 0,
228 ngx_log_error(NGX_LOG_INFO, c->log, 0, 239 "client has prematurely closed connection");
229 "client prematurely closed connection");
230 return ngx_http_close_request(r); 240 return ngx_http_close_request(r);
231 } 241 }
232 242
233 r->header_in->last.mem += n; 243 r->header_in->last.mem += n;
234 } 244 }
235 245
236 /* state_handlers are called in following order: 246 /* state_handlers are called in following order:
237 ngx_http_process_request_line(r) 247 ngx_http_process_request_line(r)
238 ngx_http_process_request_header(r) */ 248 ngx_http_process_request_headers(r) */
239 249
240 do { 250 do {
241 rc = (r->state_handler)(r); 251 rc = (r->state_handler)(r);
242 252
243 if (rc == NGX_ERROR) 253 if (rc == NGX_ERROR)
244 return rc; 254 return rc;
245 255
246 /* rc == NGX_OK || rc == NGX_AGAIN */ 256 } while (rc == NGX_AGAIN && r->header_in->pos.mem < r->header_in->last.mem);
247
248 } while (r->process_header
249 && r->header_in->pos.mem < r->header_in->last.mem);
250 257
251 if (r->header_timeout) { 258 if (r->header_timeout) {
252 r->header_timeout = 0; 259 r->header_timeout = 0;
253 ngx_del_timer(ev); 260 ngx_del_timer(ev);
254 ngx_add_timer(ev, r->server->header_timeout); 261 ngx_add_timer(ev, r->server->header_timeout);
255 } 262 }
256 263
257 return rc; 264 if (rc == NGX_OK)
265 return ngx_http_event_handler(r);
266 else
267 return rc;
258 } 268 }
259 269
260 270
261 static int ngx_http_process_request_line(ngx_http_request_t *r) 271 static int ngx_http_process_request_line(ngx_http_request_t *r)
262 { 272 {
268 rc = ngx_read_http_request_line(r); 278 rc = ngx_read_http_request_line(r);
269 279
270 c = r->connection; 280 c = r->connection;
271 281
272 if (rc == NGX_OK) { 282 if (rc == NGX_OK) {
273 len = r->uri_end - r->uri_start + 1; 283 r->uri.len = r->uri_end - r->uri_start;
274 ngx_test_null(r->uri, ngx_palloc(r->pool, len), 284 ngx_test_null(r->uri.data, ngx_palloc(r->pool, r->uri.len + 1),
275 ngx_http_close_request(r)); 285 ngx_http_close_request(r));
276 ngx_cpystrn(r->uri, r->uri_start, len); 286 ngx_cpystrn(r->uri.data, r->uri_start, r->uri.len + 1);
277 287
278 r->request_line.len = r->request_end - r->header_in->start; 288 r->request_line.len = r->request_end - r->header_in->start;
279 ngx_test_null(r->request_line.data, 289 ngx_test_null(r->request_line.data,
280 ngx_palloc(r->pool, r->request_line.len + 1), 290 ngx_palloc(r->pool, r->request_line.len + 1),
281 ngx_http_close_request(r)); 291 ngx_http_close_request(r));
297 307
298 ngx_log_debug(c->log, "REQ: '%s'" _ *request); 308 ngx_log_debug(c->log, "REQ: '%s'" _ *request);
299 /* */ 309 /* */
300 310
301 if (r->uri_ext) { 311 if (r->uri_ext) {
302 ngx_test_null(r->exten, 312 r->exten.len = r->uri_end - r->uri_ext;
303 ngx_palloc(r->pool, r->uri_end - r->uri_ext + 1), 313 ngx_test_null(r->exten.data,
314 ngx_palloc(r->pool, r->exten.len + 1),
304 ngx_http_close_request(r)); 315 ngx_http_close_request(r));
305 ngx_cpystrn(r->exten, r->uri_ext, r->uri_end - r->uri_ext + 1); 316 ngx_cpystrn(r->exten.data, r->uri_ext, r->exten.len + 1);
306 } 317 }
307 318
308 ngx_log_debug(r->connection->log, "HTTP: %d, %d, %s %s" _ 319 ngx_log_debug(r->connection->log, "HTTP: %d, %d, %s %s" _
309 r->method _ r->http_version _ r->uri _ r->exten); 320 r->method _ r->http_version _
321 r->uri.data _ r->exten.data);
310 322
311 if (r->http_version == 9) 323 if (r->http_version == 9)
312 return ngx_http_event_handler(r); 324 return NGX_OK;
313 325
314 /* TODO: check too long URI - no space for header, compact buffer */ 326 /* TODO: check too long URI - no space for header, compact buffer */
315 327
316 r->headers_in.headers = ngx_create_table(r->pool, 10); 328 r->headers_in.headers = ngx_create_table(r->pool, 10);
317 329 /* THINK: when to create out.headers ? */
318 r->state_handler = ngx_http_process_request_header; 330 r->headers_out.headers = ngx_create_table(r->pool, 10);
331
332 r->state_handler = ngx_http_process_request_headers;
319 ctx = r->connection->log->data; 333 ctx = r->connection->log->data;
320 ctx->action = "reading client request headers"; 334 ctx->action = "reading client request headers";
321 335
322 return NGX_OK; 336 return NGX_AGAIN;
323 } 337 }
324 338
325 if (r->header_in->last.mem >= r->header_in->end) { 339 if (r->header_in->last.mem >= r->header_in->end) {
326 rc = NGX_HTTP_PARSE_TOO_LONG_URI; 340 rc = NGX_HTTP_PARSE_TOO_LONG_URI;
327 341
340 NGX_HTTP_REQUEST_URI_TOO_LARGE: 354 NGX_HTTP_REQUEST_URI_TOO_LARGE:
341 NGX_HTTP_BAD_REQUEST); 355 NGX_HTTP_BAD_REQUEST);
342 } 356 }
343 357
344 358
345 static int ngx_http_process_request_header(ngx_http_request_t *r) 359 static int ngx_http_process_request_headers(ngx_http_request_t *r)
346 { 360 {
347 int rc; 361 int rc;
348 ngx_http_log_ctx_t *ctx; 362 ngx_http_log_ctx_t *ctx;
349 363
350 for ( ;; ) { 364 for ( ;; ) {
351 rc = ngx_read_http_header_line(r); 365 rc = ngx_read_http_header_line(r, r->header_in);
352 366
353 /* TODO: check too long header, compact buffer */ 367 /* TODO: check too long header, compact buffer */
354 368
355 if (rc == NGX_OK) { 369 if (rc == NGX_OK) {
356 if (ngx_http_process_request_header_line(r) == NGX_ERROR) 370 if (ngx_http_process_request_header_line(r) == NGX_ERROR)
357 return ngx_http_error(r, NGX_HTTP_BAD_REQUEST); 371 return ngx_http_error(r, NGX_HTTP_BAD_REQUEST);
358 372
359 } else if (rc == NGX_HTTP_PARSE_HEADER_DONE) { 373 } else if (rc == NGX_HTTP_PARSE_HEADER_DONE) {
360 ngx_log_debug(r->connection->log, "HTTP header done"); 374 ngx_log_debug(r->connection->log, "HTTP header done");
361 return ngx_http_event_handler(r); 375 return NGX_OK;
362 376
363 } else if (rc == NGX_AGAIN) { 377 } else if (rc == NGX_AGAIN) {
364 return NGX_AGAIN; 378 return NGX_AGAIN;
365 379
366 } else if (rc == NGX_HTTP_PARSE_INVALID_HEADER) { 380 } else if (rc == NGX_HTTP_PARSE_INVALID_HEADER) {
406 420
407 return NGX_OK; 421 return NGX_OK;
408 } 422 }
409 423
410 424
411 /* ******************** */
412
413 void ngx_http_discard_body(ngx_http_request_t *r)
414 {
415 ngx_log_debug(r->connection->log, "set discard body");
416
417 ngx_del_timer(r->connection->read);
418
419 if (r->client_content_length)
420 r->connection->read->event_handler = ngx_http_read_discarded_body;
421 }
422
423 static int ngx_http_read_discarded_body(ngx_event_t *ev)
424 {
425 size_t size;
426 ssize_t n;
427 ngx_connection_t *c;
428 ngx_http_request_t *r;
429
430 c = (ngx_connection_t *) ev->data;
431 r = (ngx_http_request_t *) c->data;
432
433 ngx_log_debug(ev->log, "http read discarded body");
434
435 if (ev->timedout)
436 return NGX_ERROR;
437
438 if (r->discarded_buffer == NULL)
439 ngx_test_null(r->discarded_buffer,
440 ngx_palloc(r->pool, r->server->discarded_buffer_size),
441 NGX_ERROR);
442
443 size = r->client_content_length;
444 if (size > r->server->discarded_buffer_size)
445 size = r->server->discarded_buffer_size;
446
447 n = ngx_event_recv(c, r->discarded_buffer, size);
448 if (n == NGX_ERROR)
449 return NGX_ERROR;
450
451 if (n == NGX_AGAIN)
452 return NGX_OK;
453
454 r->client_content_length -= n;
455 /* XXX: what if r->client_content_length == 0 ? */
456 return NGX_OK;
457 }
458
459 static int ngx_http_discarded_read(ngx_event_t *ev)
460 {
461 ssize_t n;
462 ngx_connection_t *c;
463 ngx_http_request_t *r;
464
465 c = (ngx_connection_t *) ev->data;
466 r = (ngx_http_request_t *) c->data;
467
468 ngx_log_debug(ev->log, "http discarded read");
469
470 if (ev->timedout)
471 return NGX_ERROR;
472
473 if (r->discarded_buffer == NULL)
474 ngx_test_null(r->discarded_buffer,
475 ngx_palloc(r->pool, r->server->discarded_buffer_size),
476 NGX_ERROR);
477
478 n = ngx_event_recv(c, r->discarded_buffer,
479 r->server->discarded_buffer_size);
480
481 return n;
482 }
483
484 /* ******************** */
485
486
487 static int ngx_http_event_handler(ngx_http_request_t *r) 425 static int ngx_http_event_handler(ngx_http_request_t *r)
488 { 426 {
489 int rc; 427 int rc;
490 ngx_msec_t timeout; 428 ngx_msec_t timeout;
491 429
492 ngx_log_debug(r->connection->log, "UA: '%s: %s'" _ 430 ngx_del_timer(r->connection->read);
493 r->headers_in.user_agent->key.data _ 431 r->header_timeout = 0;
494 r->headers_in.user_agent->value.data); 432
433 r->state_handler = NULL;
434 r->connection->read->event_handler = ngx_http_block_read;
495 435
496 rc = ngx_http_handler(r); 436 rc = ngx_http_handler(r);
497 437
498 /* handler is still busy */ 438 /* handler is still busy */
499 if (rc == NGX_WAITING) 439 if (rc == NGX_WAITING)
551 r->connection->buffer->pos.mem = r->connection->buffer->last.mem 491 r->connection->buffer->pos.mem = r->connection->buffer->last.mem
552 = r->connection->buffer->start; 492 = r->connection->buffer->start;
553 r->connection->read->event_handler = ngx_http_keepalive_handler; 493 r->connection->read->event_handler = ngx_http_keepalive_handler;
554 } 494 }
555 495
556 static int ngx_http_handler(ngx_http_request_t *r) 496
497 static int ngx_http_block_read(ngx_event_t *ev)
498 {
499 ngx_log_debug(ev->log, "http read blocked");
500
501 ev->blocked = 1;
502 return ngx_del_event(ev, NGX_READ_EVENT);
503 }
504
505
506
507 /* FIND PLACE ******************** */
508
509 void ngx_http_discard_body(ngx_http_request_t *r)
510 {
511 ngx_log_debug(r->connection->log, "set discard body");
512
513 ngx_del_timer(r->connection->read);
514
515 if (r->client_content_length)
516 r->connection->read->event_handler = ngx_http_read_discarded_body;
517 }
518
519
520 static int ngx_http_read_discarded_body(ngx_event_t *ev)
521 {
522 size_t size;
523 ssize_t n;
524 ngx_connection_t *c;
525 ngx_http_request_t *r;
526
527 c = (ngx_connection_t *) ev->data;
528 r = (ngx_http_request_t *) c->data;
529
530 ngx_log_debug(ev->log, "http read discarded body");
531
532 if (ev->timedout)
533 return NGX_ERROR;
534
535 if (r->discarded_buffer == NULL)
536 ngx_test_null(r->discarded_buffer,
537 ngx_palloc(r->pool, r->server->discarded_buffer_size),
538 NGX_ERROR);
539
540 size = r->client_content_length;
541 if (size > r->server->discarded_buffer_size)
542 size = r->server->discarded_buffer_size;
543
544 n = ngx_event_recv(c, r->discarded_buffer, size);
545 if (n == NGX_ERROR)
546 return NGX_ERROR;
547
548 if (n == NGX_AGAIN)
549 return NGX_OK;
550
551 r->client_content_length -= n;
552 /* XXX: what if r->client_content_length == 0 ? */
553 return NGX_OK;
554 }
555
556
557 static int ngx_http_discarded_read(ngx_event_t *ev)
558 {
559 ssize_t n;
560 ngx_connection_t *c;
561 ngx_http_request_t *r;
562
563 c = (ngx_connection_t *) ev->data;
564 r = (ngx_http_request_t *) c->data;
565
566 ngx_log_debug(ev->log, "http discarded read");
567
568 if (ev->timedout)
569 return NGX_ERROR;
570
571 if (r->discarded_buffer == NULL)
572 ngx_test_null(r->discarded_buffer,
573 ngx_palloc(r->pool, r->server->discarded_buffer_size),
574 NGX_ERROR);
575
576 n = ngx_event_recv(c, r->discarded_buffer,
577 r->server->discarded_buffer_size);
578
579 return n;
580 }
581
582 /* ******************** */
583
584
585 #if 0
586 int ngx_http_handler(ngx_http_request_t *r)
557 { 587 {
558 int rc; 588 int rc;
559 589
560 ngx_del_timer(r->connection->read);
561 r->header_timeout = 0;
562
563 r->process_header = 0;
564 r->state_handler = NULL;
565 r->connection->unexpected_eof = 0; 590 r->connection->unexpected_eof = 0;
566 r->lingering_close = 1; 591 r->lingering_close = 1;
567 592
568 r->connection->read->event_handler = ngx_http_block_read;
569
570 /* STUB: should find handler */ 593 /* STUB: should find handler */
571 #if 0 594 #if 1
572 r->filter = NGX_HTTP_FILTER_NEED_IN_MEMORY; 595 r->filter = NGX_HTTP_FILTER_NEED_IN_MEMORY;
573 #endif 596 #endif
574 rc = ngx_http_set_default_handler(r); 597 rc = ngx_http_set_default_handler(r);
575 598
576 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) 599 if (rc >= NGX_HTTP_SPECIAL_RESPONSE)
578 601
579 rc = r->handler(r); 602 rc = r->handler(r);
580 603
581 return rc; 604 return rc;
582 } 605 }
583 606 #endif
584 int ngx_http_internal_redirect(ngx_http_request_t *r, char *uri) 607
585 { 608
586 ngx_log_debug(r->connection->log, "internal redirect: '%s'" _ uri); 609 #if 0
587
588 r->uri = uri;
589 r->uri_start = uri;
590 r->uri_end = uri + strlen(uri);
591 return ngx_http_handler(r);
592 }
593
594 static int ngx_http_set_default_handler(ngx_http_request_t *r) 610 static int ngx_http_set_default_handler(ngx_http_request_t *r)
595 { 611 {
596 int err, rc; 612 ngx_err_t err;
597 char *name, *loc, *file; 613 char *name, *loc, *file;
598 614
599 #if 1 615 #if 0
600 /* STUB */ 616 /* STUB */
601 r->handler = ngx_http_proxy_handler; 617 r->handler = ngx_http_proxy_handler;
602 return NGX_OK; 618 return NGX_OK;
603 #endif 619 #endif
604 620
648 664
649 r->handler = ngx_http_static_handler; 665 r->handler = ngx_http_static_handler;
650 666
651 return NGX_OK; 667 return NGX_OK;
652 } 668 }
653 669 #endif
654
655 static int ngx_http_block_read(ngx_event_t *ev)
656 {
657 ngx_log_debug(ev->log, "http read blocked");
658
659 ev->blocked = 1;
660 return ngx_del_event(ev, NGX_READ_EVENT);
661 }
662 670
663 671
664 static int ngx_http_writer(ngx_event_t *ev) 672 static int ngx_http_writer(ngx_event_t *ev)
665 { 673 {
666 int rc; 674 int rc;
723 731
724 ngx_http_close_request(r); 732 ngx_http_close_request(r);
725 c->buffer->pos.mem = c->buffer->last.mem = c->buffer->start; 733 c->buffer->pos.mem = c->buffer->last.mem = c->buffer->start;
726 c->read->event_handler = ngx_http_keepalive_handler; 734 c->read->event_handler = ngx_http_keepalive_handler;
727 } 735 }
736
728 737
729 static int ngx_http_set_lingering_close(ngx_http_request_t *r) 738 static int ngx_http_set_lingering_close(ngx_http_request_t *r)
730 { 739 {
731 r->lingering_time = ngx_time() + r->server->lingering_time; 740 r->lingering_time = ngx_time() + r->server->lingering_time;
732 r->connection->read->event_handler = ngx_http_lingering_close; 741 r->connection->read->event_handler = ngx_http_lingering_close;
840 849
841 return NGX_OK; 850 return NGX_OK;
842 } 851 }
843 852
844 853
845 static int ngx_http_special_response(ngx_http_request_t *r, int error)
846 {
847 return ngx_http_error(r, error);
848 }
849
850
851 static int ngx_http_redirect(ngx_http_request_t *r, int redirect)
852 {
853 /* STUB */
854
855 /* log request */
856
857 return ngx_http_close_request(r);
858 }
859
860
861 static int ngx_http_error(ngx_http_request_t *r, int error)
862 {
863 /* STUB */
864 ngx_log_debug(r->connection->log, "http error: %d" _ error);
865
866 /* log request */
867
868 return ngx_http_close_request(r);
869 }
870
871 #if 0
872
873 static int ngx_process_http_request(ngx_http_request_t *r)
874 {
875 int fd;
876 struct stat sb;
877 ngx_http_header_out_t *header_out;
878 ngx_chunk_t *header, *ch;
879
880 int index = (*(r->uri_end - 1) == '/') ? sizeof(NGX_INDEX) : 1;
881 char *name = ngx_palloc(r->pool,
882 r->uri_end - r->uri_start + strlen(ngx_root) + index);
883 strcpy(name, ngx_root);
884 strcat(name, r->uri_start);
885 if (*(r->uri_end - 1) == '/')
886 strcat(name, NGX_INDEX);
887
888 ngx_log_debug(r->connection->log, "HTTP URI: '%s'", name);
889
890 if ((fd = open(name, O_RDONLY)) == -1) {
891 ngx_log_error(NGX_LOG_ERR, r->connection->log, errno,
892 "open %s failed", name);
893 return -1;
894 }
895
896 if (fstat(fd, &sb) == -1) {
897 ngx_log_error(NGX_LOG_ERR, r->connection->log, errno,
898 "fstat %s failed", name);
899 return -1;
900 }
901
902 header_out = ngx_palloc(r->pool, sizeof(ngx_http_header_out_t));
903
904 header_out->status = NGX_HTTP_OK;
905 header_out->content_length = sb.st_size;
906 header_out->last_modified = sb.st_mtime;
907 header_out->content_type = "text/html";
908 header_out->charset = "koi8-r";
909 header_out->date = time(NULL);
910 header_out->connection = NGX_HTTP_CONN_CLOSE;
911
912 /*
913 header_out->connection = NGX_HTTP_CONN_KEEP_ALIVE;
914 r->connection->read->event_handler = ngx_http_init_request;
915 */
916
917 header = ngx_http_header(r, header_out);
918 ch = ngx_palloc(r->pool, sizeof(ngx_chunk_t));
919 ch->ident = fd;
920 ch->offset = 0;
921 ch->size = sb.st_size;
922 ch->next = NULL;
923 header->next = ch;
924
925 ngx_event_write(r->connection, header);
926
927 return 0;
928 }
929
930 #endif
931
932 static int ngx_http_close_request(ngx_http_request_t *r)
933 {
934 /*
935 if (r->logging)
936 ngx_http_log_request(r);
937 */
938
939 ngx_destroy_pool(r->pool);
940
941 ngx_log_debug(r->connection->log, "http close");
942
943 ngx_del_timer(r->connection->read);
944 ngx_del_timer(r->connection->write);
945
946 return NGX_DONE;
947 }
948
949
950 static int ngx_http_close_connection(ngx_event_t *ev) 854 static int ngx_http_close_connection(ngx_event_t *ev)
951 { 855 {
952 int i, len; 856 int i, len;
953 char **requests, *requests_line, *prev, *new; 857 char **requests, *requests_line, *prev, *new;
954 ngx_connection_t *c = (ngx_connection_t *) ev->data; 858 ngx_connection_t *c = (ngx_connection_t *) ev->data;