From 66307e3c5ab38b862357196477c857cf44879732 Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Thu, 27 Nov 2008 14:22:34 +0000 Subject: [PATCH] r2068 merge: the "Expect" header support --- src/http/modules/ngx_http_proxy_module.c | 1 + src/http/ngx_http_core_module.c | 50 +++++++++++++++++++++++- src/http/ngx_http_request.c | 4 ++ src/http/ngx_http_request.h | 2 + 4 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/http/modules/ngx_http_proxy_module.c b/src/http/modules/ngx_http_proxy_module.c index 1d8264801..f5c6ceeaf 100644 --- a/src/http/modules/ngx_http_proxy_module.c +++ b/src/http/modules/ngx_http_proxy_module.c @@ -424,6 +424,7 @@ static ngx_keyval_t ngx_http_proxy_headers[] = { { ngx_string("Host"), ngx_string("$proxy_host") }, { ngx_string("Connection"), ngx_string("close") }, { ngx_string("Keep-Alive"), ngx_string("") }, + { ngx_string("Expect"), ngx_string("") }, { ngx_null_string, ngx_null_string } }; diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c index f9b11b930..b58137d25 100644 --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -30,6 +30,7 @@ typedef struct { static ngx_int_t ngx_http_core_find_location(ngx_http_request_t *r, ngx_array_t *locations, ngx_uint_t regex_start, size_t len); +static ngx_int_t ngx_http_core_send_continue(ngx_http_request_t *r); static ngx_int_t ngx_http_core_preconfiguration(ngx_conf_t *cf); static void *ngx_http_core_create_main_conf(ngx_conf_t *cf); @@ -785,7 +786,7 @@ ngx_http_core_find_config_phase(ngx_http_request_t *r, { u_char *p; size_t len; - ngx_int_t rc; + ngx_int_t rc, expect; ngx_http_core_loc_conf_t *clcf; ngx_http_core_srv_conf_t *cscf; @@ -832,6 +833,14 @@ ngx_http_core_find_config_phase(ngx_http_request_t *r, return NGX_OK; } + if (r->headers_in.expect) { + expect = ngx_http_core_send_continue(r); + + if (expect != NGX_OK) { + ngx_http_finalize_request(r, expect); + return NGX_OK; + } + } if (rc == NGX_HTTP_LOCATION_AUTO_REDIRECT) { r->headers_out.location = ngx_list_push(&r->headers_out.headers); @@ -1252,6 +1261,45 @@ ngx_http_core_find_location(ngx_http_request_t *r, } +static ngx_int_t +ngx_http_core_send_continue(ngx_http_request_t *r) +{ + ngx_int_t n; + ngx_str_t *expect; + + if (r->expect_tested) { + return NGX_OK; + } + + r->expect_tested = 1; + + expect = &r->headers_in.expect->value; + + if (expect->len != sizeof("100-continue") - 1 + || ngx_strncasecmp(expect->data, (u_char *) "100-continue", + sizeof("100-continue") - 1) + != 0) + { + return NGX_OK; + } + + ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "send 100 Continue"); + + n = r->connection->send(r->connection, + (u_char *) "HTTP/1.1 100 Continue" CRLF CRLF, + sizeof("HTTP/1.1 100 Continue" CRLF CRLF) - 1); + + if (n == sizeof("HTTP/1.1 100 Continue" CRLF CRLF) - 1) { + return NGX_OK; + } + + /* we assume that such small packet should be send successfully */ + + return NGX_HTTP_INTERNAL_SERVER_ERROR; +} + + ngx_int_t ngx_http_set_content_type(ngx_http_request_t *r) { diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c index aa61c5e62..738c1fde9 100644 --- a/src/http/ngx_http_request.c +++ b/src/http/ngx_http_request.c @@ -109,6 +109,10 @@ ngx_http_header_t ngx_http_headers_in[] = { offsetof(ngx_http_headers_in_t, transfer_encoding), ngx_http_process_header_line }, + { ngx_string("Expect"), + offsetof(ngx_http_headers_in_t, expect), + ngx_http_process_unique_header_line }, + #if (NGX_HTTP_GZIP) { ngx_string("Accept-Encoding"), offsetof(ngx_http_headers_in_t, accept_encoding), diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h index 2e7ff54b6..1a4eae106 100644 --- a/src/http/ngx_http_request.h +++ b/src/http/ngx_http_request.h @@ -171,6 +171,7 @@ typedef struct { ngx_table_elt_t *if_range; ngx_table_elt_t *transfer_encoding; + ngx_table_elt_t *expect; #if (NGX_HTTP_GZIP) ngx_table_elt_t *accept_encoding; @@ -467,6 +468,7 @@ struct ngx_http_request_s { unsigned request_complete:1; unsigned request_output:1; unsigned header_sent:1; + unsigned expect_tested:1; unsigned done:1; unsigned utf8:1;