HTTP/2: retain r->request_body in requests without request body.

This is alternative to 4dbf1fbb2c8b229b881719a4438f28e99050171e,
which broke gRPC-gateway.

Reported by Ian Sherman.

Change-Id: Ifb6946ef2da95a53a0b2dbac330e0fc54f509bed
Signed-off-by: Piotr Sikora <piotrsikora@google.com>
Reviewed-on: https://nginx-review.googlesource.com/2960
Reviewed-by: Feng Li <fengli@google.com>
diff --git a/src/http/v2/ngx_http_v2.c b/src/http/v2/ngx_http_v2.c
index ca52d96..8bc35c8 100644
--- a/src/http/v2/ngx_http_v2.c
+++ b/src/http/v2/ngx_http_v2.c
@@ -3619,9 +3619,7 @@
 
     stream = r->stream;
 
-    if (stream->skip_data
-        || (stream->in_closed && stream->preread == NULL))
-    {
+    if (stream->skip_data) {
         r->request_body_no_buffering = 0;
         post_handler(r);
         return NGX_OK;
@@ -3642,11 +3640,16 @@
      *     rb->busy = NULL;
      */
 
-    rb->rest = 1;
     rb->post_handler = post_handler;
 
     r->request_body = rb;
 
+    if (r->headers_in.content_length_n < 0 && !r->headers_in.chunked) {
+        r->request_body_no_buffering = 0;
+        post_handler(r);
+        return NGX_OK;
+    }
+
     h2scf = ngx_http_get_module_srv_conf(r, ngx_http_v2_module);
     clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
 
@@ -3696,6 +3699,8 @@
         return NGX_HTTP_INTERNAL_SERVER_ERROR;
     }
 
+    rb->rest = 1;
+
     buf = stream->preread;
 
     if (stream->in_closed) {