Mercurial > hg > nginx
comparison src/http/modules/ngx_http_grpc_module.c @ 7235:c2a0a838c40f
gRPC: special handling of "trailer only" responses.
The gRPC protocol makes a distinction between HEADERS frame with
the END_STREAM flag set, and a HEADERS frame followed by an empty
DATA frame with the END_STREAM flag. The latter is not permitted,
and results in errors not being propagated through nginx. Instead,
gRPC clients complain that "server closed the stream without sending
trailers" (seen in grpc-go) or "13: Received RST_STREAM with error
code 2" (seen in grpc-c).
To fix this, nginx now returns HEADERS with the END_STREAM flag if
the response length is known to be 0, and we are not expecting
any trailer headers to be added. And the response length is
explicitly set to 0 in the gRPC proxy if we see initial HEADERS frame
with the END_STREAM flag set.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Sat, 17 Mar 2018 23:04:26 +0300 |
parents | c693daca57f7 |
children | 413189f03c8d |
comparison
equal
deleted
inserted
replaced
7234:c693daca57f7 | 7235:c2a0a838c40f |
---|---|
1741 /* a whole header has been parsed successfully */ | 1741 /* a whole header has been parsed successfully */ |
1742 | 1742 |
1743 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 1743 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1744 "grpc header done"); | 1744 "grpc header done"); |
1745 | 1745 |
1746 if (ctx->end_stream | 1746 if (ctx->end_stream) { |
1747 && ctx->in == NULL | 1747 u->headers_in.content_length_n = 0; |
1748 && ctx->out == NULL | 1748 |
1749 && ctx->output_closed | 1749 if (ctx->in == NULL |
1750 && b->last == b->pos) | 1750 && ctx->out == NULL |
1751 { | 1751 && ctx->output_closed |
1752 u->keepalive = 1; | 1752 && b->last == b->pos) |
1753 { | |
1754 u->keepalive = 1; | |
1755 } | |
1753 } | 1756 } |
1754 | 1757 |
1755 return NGX_OK; | 1758 return NGX_OK; |
1756 } | 1759 } |
1757 | 1760 |