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