]> granicus.if.org Git - curl/commitdiff
http2: Return error if stream was closed with other than NO_ERROR
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>
Thu, 26 Feb 2015 14:28:30 +0000 (23:28 +0900)
committerSteve Holme <steve_holme@hotmail.com>
Fri, 27 Feb 2015 21:17:27 +0000 (21:17 +0000)
Previously, we just ignored error code passed to
on_stream_close_callback and just return 0 (success) after stream
closure even if stream was reset with error.  This patch records error
code in on_stream_close_callback, and return -1 and use CURLE_HTTP2
error code on abnormal stream closure.

lib/http.h
lib/http2.c

index 907755a8ad737beff9ad5432cbfada58b44d4154..f7d64e8c4354b7ea67c32fade988fbd4cdaeb681 100644 (file)
@@ -7,7 +7,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -169,6 +169,7 @@ struct http_conn {
   sending send_underlying; /* underlying send Curl_send callback */
   recving recv_underlying; /* underlying recv Curl_recv callback */
   bool closed; /* TRUE on HTTP2 stream close */
+  uint32_t error_code; /* HTTP/2 error code */
   Curl_send_buffer *header_recvbuf; /* store response headers.  We
                                        store non-final and final
                                        response headers into it. */
index 8cde9101ce3e8ae1201ad7277472ee4bef7cef2f..d1f42942e914e3427751ad732393beb846e554ae 100644 (file)
@@ -365,6 +365,7 @@ static int on_stream_close(nghttp2_session *session, int32_t stream_id,
     return 0;
   }
 
+  c->error_code = error_code;
   c->closed = TRUE;
 
   return 0;
@@ -783,6 +784,13 @@ static ssize_t http2_recv(struct connectdata *conn, int sockindex,
     /* Reset to FALSE to prevent infinite loop in readwrite_data
        function. */
     httpc->closed = FALSE;
+    if(httpc->error_code != NGHTTP2_NO_ERROR) {
+      failf(conn->data,
+            "HTTP/2 stream = %x was not closed cleanly: error_code = %d",
+            httpc->stream_id, httpc->error_code);
+      *err = CURLE_HTTP2;
+      return -1;
+    }
     return 0;
   }
   *err = CURLE_AGAIN;
@@ -980,6 +988,7 @@ CURLcode Curl_http2_setup(struct connectdata *conn)
 
   infof(conn->data, "Using HTTP2\n");
   httpc->bodystarted = FALSE;
+  httpc->error_code = NGHTTP2_NO_ERROR;
   httpc->closed = FALSE;
   httpc->header_recvbuf = Curl_add_buffer_init();
   httpc->nread_header_recvbuf = 0;