Mercurial > hg > nginx
comparison src/http/ngx_http_request_body.c @ 2474:6175f886ddfb stable-0.6
r2420, r2421, r2435, r2436, r2437 merge:
*) send "100 Continue" for HTTP/1.1 only
*) do not send "100 Continue" for subrequests
*) send "100 Continue" just before reading request body
*) set send() slot for POSIX systems
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 26 Jan 2009 15:22:24 +0000 |
parents | 02a22cd5282a |
children |
comparison
equal
deleted
inserted
replaced
2473:afba93b8bf06 | 2474:6175f886ddfb |
---|---|
14 static ngx_int_t ngx_http_do_read_client_request_body(ngx_http_request_t *r); | 14 static ngx_int_t ngx_http_do_read_client_request_body(ngx_http_request_t *r); |
15 static ngx_int_t ngx_http_write_request_body(ngx_http_request_t *r, | 15 static ngx_int_t ngx_http_write_request_body(ngx_http_request_t *r, |
16 ngx_chain_t *body); | 16 ngx_chain_t *body); |
17 static void ngx_http_read_discarded_request_body_handler(ngx_http_request_t *r); | 17 static void ngx_http_read_discarded_request_body_handler(ngx_http_request_t *r); |
18 static ngx_int_t ngx_http_read_discarded_request_body(ngx_http_request_t *r); | 18 static ngx_int_t ngx_http_read_discarded_request_body(ngx_http_request_t *r); |
19 static ngx_int_t ngx_http_test_expect(ngx_http_request_t *r); | |
19 | 20 |
20 | 21 |
21 /* | 22 /* |
22 * on completion ngx_http_read_client_request_body() adds to | 23 * on completion ngx_http_read_client_request_body() adds to |
23 * r->request_body->bufs one or two bufs: | 24 * r->request_body->bufs one or two bufs: |
38 ngx_http_core_loc_conf_t *clcf; | 39 ngx_http_core_loc_conf_t *clcf; |
39 | 40 |
40 if (r->request_body || r->discard_body) { | 41 if (r->request_body || r->discard_body) { |
41 post_handler(r); | 42 post_handler(r); |
42 return NGX_OK; | 43 return NGX_OK; |
44 } | |
45 | |
46 if (ngx_http_test_expect(r) != NGX_OK) { | |
47 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
43 } | 48 } |
44 | 49 |
45 rb = ngx_pcalloc(r->pool, sizeof(ngx_http_request_body_t)); | 50 rb = ngx_pcalloc(r->pool, sizeof(ngx_http_request_body_t)); |
46 if (rb == NULL) { | 51 if (rb == NULL) { |
47 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 52 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
432 | 437 |
433 if (r != r->main || r->discard_body) { | 438 if (r != r->main || r->discard_body) { |
434 return NGX_OK; | 439 return NGX_OK; |
435 } | 440 } |
436 | 441 |
442 if (ngx_http_test_expect(r) != NGX_OK) { | |
443 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
444 } | |
445 | |
437 rev = r->connection->read; | 446 rev = r->connection->read; |
438 | 447 |
439 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0, "http set discard body"); | 448 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0, "http set discard body"); |
440 | 449 |
441 if (rev->timer_set) { | 450 if (rev->timer_set) { |
580 | 589 |
581 } while (r->connection->read->ready); | 590 } while (r->connection->read->ready); |
582 | 591 |
583 return NGX_AGAIN; | 592 return NGX_AGAIN; |
584 } | 593 } |
594 | |
595 | |
596 static ngx_int_t | |
597 ngx_http_test_expect(ngx_http_request_t *r) | |
598 { | |
599 ngx_int_t n; | |
600 ngx_str_t *expect; | |
601 | |
602 if (r->expect_tested | |
603 || r->headers_in.expect == NULL | |
604 || r->http_version < NGX_HTTP_VERSION_11) | |
605 { | |
606 return NGX_OK; | |
607 } | |
608 | |
609 r->expect_tested = 1; | |
610 | |
611 expect = &r->headers_in.expect->value; | |
612 | |
613 if (expect->len != sizeof("100-continue") - 1 | |
614 || ngx_strncasecmp(expect->data, (u_char *) "100-continue", | |
615 sizeof("100-continue") - 1) | |
616 != 0) | |
617 { | |
618 return NGX_OK; | |
619 } | |
620 | |
621 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
622 "send 100 Continue"); | |
623 | |
624 n = r->connection->send(r->connection, | |
625 (u_char *) "HTTP/1.1 100 Continue" CRLF CRLF, | |
626 sizeof("HTTP/1.1 100 Continue" CRLF CRLF) - 1); | |
627 | |
628 if (n == sizeof("HTTP/1.1 100 Continue" CRLF CRLF) - 1) { | |
629 return NGX_OK; | |
630 } | |
631 | |
632 /* we assume that such small packet should be send successfully */ | |
633 | |
634 return NGX_ERROR; | |
635 } |