summaryrefslogtreecommitdiffhomepage
path: root/src/http
diff options
context:
space:
mode:
authorSergey Kandaurov <pluknet@nginx.com>2020-11-24 17:19:40 +0000
committerSergey Kandaurov <pluknet@nginx.com>2020-11-24 17:19:40 +0000
commit5a9a897d7b632d6123aacabf1c0f141db0ad799b (patch)
treebbc25e7a291e8721d91cd11186627068eaab7cad /src/http
parent219053e3e3bd18ecb195815df0023da40dbdff9d (diff)
parent84a2201964df4c255f7b605951a0ddbae124184f (diff)
downloadnginx-5a9a897d7b632d6123aacabf1c0f141db0ad799b.tar.gz
nginx-5a9a897d7b632d6123aacabf1c0f141db0ad799b.tar.bz2
Merged with the default branch.
Diffstat (limited to 'src/http')
-rw-r--r--src/http/modules/ngx_http_grpc_module.c39
-rw-r--r--src/http/ngx_http_request.c46
-rw-r--r--src/http/ngx_http_request_body.c9
-rw-r--r--src/http/v2/ngx_http_v2.c42
4 files changed, 82 insertions, 54 deletions
diff --git a/src/http/modules/ngx_http_grpc_module.c b/src/http/modules/ngx_http_grpc_module.c
index 7e14af8d9..aa7576561 100644
--- a/src/http/modules/ngx_http_grpc_module.c
+++ b/src/http/modules/ngx_http_grpc_module.c
@@ -1141,20 +1141,11 @@ ngx_http_grpc_create_request(ngx_http_request_t *r)
f->flags |= NGX_HTTP_V2_END_HEADERS_FLAG;
-#if (NGX_DEBUG)
- if (r->connection->log->log_level & NGX_LOG_DEBUG_HTTP) {
- u_char buf[512];
- size_t n, m;
-
- n = ngx_min(b->last - b->pos, 256);
- m = ngx_hex_dump(buf, b->pos, n) - buf;
-
- ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "grpc header: %*s%s, len: %uz",
- m, buf, b->last - b->pos > 256 ? "..." : "",
- b->last - b->pos);
- }
-#endif
+ ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+ "grpc header: %*xs%s, len: %uz",
+ (size_t) ngx_min(b->last - b->pos, 256), b->pos,
+ b->last - b->pos > 256 ? "..." : "",
+ b->last - b->pos);
if (r->request_body_no_buffering) {
@@ -1604,20 +1595,11 @@ ngx_http_grpc_process_header(ngx_http_request_t *r)
u = r->upstream;
b = &u->buffer;
-#if (NGX_DEBUG)
- if (r->connection->log->log_level & NGX_LOG_DEBUG_HTTP) {
- u_char buf[512];
- size_t n, m;
-
- n = ngx_min(b->last - b->pos, 256);
- m = ngx_hex_dump(buf, b->pos, n) - buf;
-
- ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "grpc response: %*s%s, len: %uz",
- m, buf, b->last - b->pos > 256 ? "..." : "",
- b->last - b->pos);
- }
-#endif
+ ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+ "grpc response: %*xs%s, len: %uz",
+ (size_t) ngx_min(b->last - b->pos, 256),
+ b->pos, b->last - b->pos > 256 ? "..." : "",
+ b->last - b->pos);
ctx = ngx_http_grpc_get_ctx(r);
@@ -1987,6 +1969,7 @@ ngx_http_grpc_filter_init(void *data)
}
u->length = 0;
+ ctx->done = 1;
} else {
u->length = 1;
diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c
index 8df43891a..3b9e59005 100644
--- a/src/http/ngx_http_request.c
+++ b/src/http/ngx_http_request.c
@@ -49,7 +49,7 @@ static void ngx_http_request_finalizer(ngx_http_request_t *r);
static void ngx_http_set_keepalive(ngx_http_request_t *r);
static void ngx_http_keepalive_handler(ngx_event_t *ev);
-static void ngx_http_set_lingering_close(ngx_http_request_t *r);
+static void ngx_http_set_lingering_close(ngx_connection_t *c);
static void ngx_http_lingering_close_handler(ngx_event_t *ev);
static ngx_int_t ngx_http_post_action(ngx_http_request_t *r);
static void ngx_http_close_request(ngx_http_request_t *r, ngx_int_t error);
@@ -2893,7 +2893,7 @@ ngx_http_finalize_connection(ngx_http_request_t *r)
|| r->header_in->pos < r->header_in->last
|| r->connection->read->ready)))
{
- ngx_http_set_lingering_close(r);
+ ngx_http_set_lingering_close(r->connection);
return;
}
@@ -3191,13 +3191,6 @@ ngx_http_set_keepalive(ngx_http_request_t *r)
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "set http keepalive handler");
- if (r->discard_body) {
- r->write_event_handler = ngx_http_request_empty_handler;
- r->lingering_time = ngx_time() + (time_t) (clcf->lingering_time / 1000);
- ngx_add_timer(rev, clcf->lingering_timeout);
- return;
- }
-
c->log->action = "closing request";
hc = r->http_connection;
@@ -3527,22 +3520,43 @@ ngx_http_keepalive_handler(ngx_event_t *rev)
static void
-ngx_http_set_lingering_close(ngx_http_request_t *r)
+ngx_http_set_lingering_close(ngx_connection_t *c)
{
ngx_event_t *rev, *wev;
- ngx_connection_t *c;
+ ngx_http_request_t *r;
ngx_http_core_loc_conf_t *clcf;
- c = r->connection;
+ r = c->data;
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
+ if (r->lingering_time == 0) {
+ r->lingering_time = ngx_time() + (time_t) (clcf->lingering_time / 1000);
+ }
+
+#if (NGX_HTTP_SSL)
+ if (c->ssl) {
+ ngx_int_t rc;
+
+ rc = ngx_ssl_shutdown(c);
+
+ if (rc == NGX_ERROR) {
+ ngx_http_close_request(r, 0);
+ return;
+ }
+
+ if (rc == NGX_AGAIN) {
+ c->ssl->handler = ngx_http_set_lingering_close;
+ return;
+ }
+
+ c->recv = ngx_recv;
+ }
+#endif
+
rev = c->read;
rev->handler = ngx_http_lingering_close_handler;
- r->lingering_time = ngx_time() + (time_t) (clcf->lingering_time / 1000);
- ngx_add_timer(rev, clcf->lingering_timeout);
-
if (ngx_handle_read_event(rev, 0) != NGX_OK) {
ngx_http_close_request(r, 0);
return;
@@ -3567,6 +3581,8 @@ ngx_http_set_lingering_close(ngx_http_request_t *r)
}
}
+ ngx_add_timer(rev, clcf->lingering_timeout);
+
if (rev->ready) {
ngx_http_lingering_close_handler(rev);
}
diff --git a/src/http/ngx_http_request_body.c b/src/http/ngx_http_request_body.c
index c8ed658cd..c0257a21e 100644
--- a/src/http/ngx_http_request_body.c
+++ b/src/http/ngx_http_request_body.c
@@ -137,8 +137,9 @@ ngx_http_read_client_request_body(ngx_http_request_t *r,
} else {
/* set rb->rest */
- if (ngx_http_request_body_filter(r, NULL) != NGX_OK) {
- rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
+ rc = ngx_http_request_body_filter(r, NULL);
+
+ if (rc != NGX_OK) {
goto done;
}
}
@@ -305,6 +306,9 @@ ngx_http_do_read_client_request_body(ngx_http_request_t *r)
return NGX_AGAIN;
}
+ ngx_log_error(NGX_LOG_ALERT, c->log, 0,
+ "busy buffers after request body flush");
+
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@@ -679,6 +683,7 @@ ngx_http_discarded_request_body_handler(ngx_http_request_t *r)
if (rc == NGX_OK) {
r->discard_body = 0;
r->lingering_close = 0;
+ r->lingering_time = 0;
ngx_http_finalize_request(r, NGX_DONE);
return;
}
diff --git a/src/http/v2/ngx_http_v2.c b/src/http/v2/ngx_http_v2.c
index 43a4fded5..58916a184 100644
--- a/src/http/v2/ngx_http_v2.c
+++ b/src/http/v2/ngx_http_v2.c
@@ -60,7 +60,7 @@ typedef struct {
static void ngx_http_v2_read_handler(ngx_event_t *rev);
static void ngx_http_v2_write_handler(ngx_event_t *wev);
static void ngx_http_v2_handle_connection(ngx_http_v2_connection_t *h2c);
-static void ngx_http_v2_lingering_close(ngx_http_v2_connection_t *h2c);
+static void ngx_http_v2_lingering_close(ngx_connection_t *c);
static void ngx_http_v2_lingering_close_handler(ngx_event_t *rev);
static u_char *ngx_http_v2_state_proxy_protocol(ngx_http_v2_connection_t *h2c,
@@ -664,7 +664,7 @@ ngx_http_v2_handle_connection(ngx_http_v2_connection_t *h2c)
}
if (h2c->goaway) {
- ngx_http_v2_lingering_close(h2c);
+ ngx_http_v2_lingering_close(c);
return;
}
@@ -703,13 +703,13 @@ ngx_http_v2_handle_connection(ngx_http_v2_connection_t *h2c)
static void
-ngx_http_v2_lingering_close(ngx_http_v2_connection_t *h2c)
+ngx_http_v2_lingering_close(ngx_connection_t *c)
{
ngx_event_t *rev, *wev;
- ngx_connection_t *c;
+ ngx_http_v2_connection_t *h2c;
ngx_http_core_loc_conf_t *clcf;
- c = h2c->connection;
+ h2c = c->data;
clcf = ngx_http_get_module_loc_conf(h2c->http_connection->conf_ctx,
ngx_http_core_module);
@@ -719,12 +719,34 @@ ngx_http_v2_lingering_close(ngx_http_v2_connection_t *h2c)
return;
}
+ if (h2c->lingering_time == 0) {
+ h2c->lingering_time = ngx_time()
+ + (time_t) (clcf->lingering_time / 1000);
+ }
+
+#if (NGX_HTTP_SSL)
+ if (c->ssl) {
+ ngx_int_t rc;
+
+ rc = ngx_ssl_shutdown(c);
+
+ if (rc == NGX_ERROR) {
+ ngx_http_close_connection(c);
+ return;
+ }
+
+ if (rc == NGX_AGAIN) {
+ c->ssl->handler = ngx_http_v2_lingering_close;
+ return;
+ }
+
+ c->recv = ngx_recv;
+ }
+#endif
+
rev = c->read;
rev->handler = ngx_http_v2_lingering_close_handler;
- h2c->lingering_time = ngx_time() + (time_t) (clcf->lingering_time / 1000);
- ngx_add_timer(rev, clcf->lingering_timeout);
-
if (ngx_handle_read_event(rev, 0) != NGX_OK) {
ngx_http_close_connection(c);
return;
@@ -747,6 +769,8 @@ ngx_http_v2_lingering_close(ngx_http_v2_connection_t *h2c)
return;
}
+ ngx_add_timer(rev, clcf->lingering_timeout);
+
if (rev->ready) {
ngx_http_v2_lingering_close_handler(rev);
}
@@ -4757,7 +4781,7 @@ done:
return;
}
- ngx_http_v2_lingering_close(h2c);
+ ngx_http_v2_lingering_close(c);
}