comparison src/http/ngx_http_core_module.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 821497e016b6
children 1e53534e6800
comparison
equal deleted inserted replaced
2435:821497e016b6 2436:26d9d4a41e91
21 21
22 22
23 static ngx_int_t ngx_http_core_find_location(ngx_http_request_t *r); 23 static ngx_int_t ngx_http_core_find_location(ngx_http_request_t *r);
24 static ngx_int_t ngx_http_core_find_static_location(ngx_http_request_t *r, 24 static ngx_int_t ngx_http_core_find_static_location(ngx_http_request_t *r,
25 ngx_http_location_tree_node_t *node); 25 ngx_http_location_tree_node_t *node);
26 static ngx_int_t ngx_http_core_send_continue(ngx_http_request_t *r);
27 26
28 static ngx_int_t ngx_http_core_preconfiguration(ngx_conf_t *cf); 27 static ngx_int_t ngx_http_core_preconfiguration(ngx_conf_t *cf);
29 static void *ngx_http_core_create_main_conf(ngx_conf_t *cf); 28 static void *ngx_http_core_create_main_conf(ngx_conf_t *cf);
30 static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf); 29 static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf);
31 static void *ngx_http_core_create_srv_conf(ngx_conf_t *cf); 30 static void *ngx_http_core_create_srv_conf(ngx_conf_t *cf);
816 ngx_http_core_find_config_phase(ngx_http_request_t *r, 815 ngx_http_core_find_config_phase(ngx_http_request_t *r,
817 ngx_http_phase_handler_t *ph) 816 ngx_http_phase_handler_t *ph)
818 { 817 {
819 u_char *p; 818 u_char *p;
820 size_t len; 819 size_t len;
821 ngx_int_t rc, expect; 820 ngx_int_t rc;
822 ngx_http_core_loc_conf_t *clcf; 821 ngx_http_core_loc_conf_t *clcf;
823 822
824 r->content_handler = NULL; 823 r->content_handler = NULL;
825 r->uri_changed = 0; 824 r->uri_changed = 0;
826 825
858 "client intended to send too large body: %O bytes", 857 "client intended to send too large body: %O bytes",
859 r->headers_in.content_length_n); 858 r->headers_in.content_length_n);
860 859
861 ngx_http_finalize_request(r, NGX_HTTP_REQUEST_ENTITY_TOO_LARGE); 860 ngx_http_finalize_request(r, NGX_HTTP_REQUEST_ENTITY_TOO_LARGE);
862 return NGX_OK; 861 return NGX_OK;
863 }
864
865 if (r->headers_in.expect
866 && r == r->main
867 && r->http_version > NGX_HTTP_VERSION_10)
868 {
869 expect = ngx_http_core_send_continue(r);
870
871 if (expect != NGX_OK) {
872 ngx_http_finalize_request(r, expect);
873 return NGX_OK;
874 }
875 } 862 }
876 863
877 if (rc == NGX_DONE) { 864 if (rc == NGX_DONE) {
878 r->headers_out.location = ngx_list_push(&r->headers_out.headers); 865 r->headers_out.location = ngx_list_push(&r->headers_out.headers);
879 if (r->headers_out.location == NULL) { 866 if (r->headers_out.location == NULL) {
1491 node = node->left; 1478 node = node->left;
1492 } 1479 }
1493 } 1480 }
1494 1481
1495 1482
1496 static ngx_int_t
1497 ngx_http_core_send_continue(ngx_http_request_t *r)
1498 {
1499 ngx_int_t n;
1500 ngx_str_t *expect;
1501
1502 if (r->expect_tested) {
1503 return NGX_OK;
1504 }
1505
1506 r->expect_tested = 1;
1507
1508 expect = &r->headers_in.expect->value;
1509
1510 if (expect->len != sizeof("100-continue") - 1
1511 || ngx_strncasecmp(expect->data, (u_char *) "100-continue",
1512 sizeof("100-continue") - 1)
1513 != 0)
1514 {
1515 return NGX_OK;
1516 }
1517
1518 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1519 "send 100 Continue");
1520
1521 n = r->connection->send(r->connection,
1522 (u_char *) "HTTP/1.1 100 Continue" CRLF CRLF,
1523 sizeof("HTTP/1.1 100 Continue" CRLF CRLF) - 1);
1524
1525 if (n == sizeof("HTTP/1.1 100 Continue" CRLF CRLF) - 1) {
1526 return NGX_OK;
1527 }
1528
1529 /* we assume that such small packet should be send successfully */
1530
1531 return NGX_HTTP_INTERNAL_SERVER_ERROR;
1532 }
1533
1534
1535 void * 1483 void *
1536 ngx_http_test_content_type(ngx_http_request_t *r, ngx_hash_t *types_hash) 1484 ngx_http_test_content_type(ngx_http_request_t *r, ngx_hash_t *types_hash)
1537 { 1485 {
1538 u_char c, *p; 1486 u_char c, *p;
1539 ngx_uint_t i, hash; 1487 ngx_uint_t i, hash;
2126 } 2074 }
2127 2075
2128 sr->internal = 1; 2076 sr->internal = 1;
2129 2077
2130 sr->discard_body = r->discard_body; 2078 sr->discard_body = r->discard_body;
2079 sr->expect_tested = 1;
2131 sr->main_filter_need_in_memory = r->main_filter_need_in_memory; 2080 sr->main_filter_need_in_memory = r->main_filter_need_in_memory;
2132 2081
2133 sr->uri_changes = NGX_HTTP_MAX_URI_CHANGES + 1; 2082 sr->uri_changes = NGX_HTTP_MAX_URI_CHANGES + 1;
2134 2083
2135 r->main->subrequests++; 2084 r->main->subrequests++;