Blame SOURCES/0044-curl-7.61.1-retry-http11.patch

b99ba0
From 78b62ef1206621e8f4f1628ad4eb0a7be877c96f Mon Sep 17 00:00:00 2001
b99ba0
From: Johannes Schindelin <johannes.schindelin@gmx.de>
b99ba0
Date: Fri, 7 Dec 2018 17:04:39 +0100
b99ba0
Subject: [PATCH] Upon HTTP_1_1_REQUIRED, retry the request with HTTP/1.1
b99ba0
b99ba0
This is a companion patch to cbea2fd2c (NTLM: force the connection to
b99ba0
HTTP/1.1, 2018-12-06): with NTLM, we can switch to HTTP/1.1
b99ba0
preemptively. However, with other (Negotiate) authentication it is not
b99ba0
clear to this developer whether there is a way to make it work with
b99ba0
HTTP/2, so let's try HTTP/2 first and fall back in case we encounter the
b99ba0
error HTTP_1_1_REQUIRED.
b99ba0
b99ba0
Note: we will still keep the NTLM workaround, as it avoids an extra
b99ba0
round trip.
b99ba0
b99ba0
Daniel Stenberg helped a lot with this patch, in particular by
b99ba0
suggesting to introduce the Curl_h2_http_1_1_error() function.
b99ba0
b99ba0
Closes #3349
b99ba0
b99ba0
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
b99ba0
b99ba0
Upstream-commit: d997aa0e963c5be5de100dccdc5208d39bd3d62b
b99ba0
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
b99ba0
---
b99ba0
 lib/http2.c |  8 ++++++++
b99ba0
 lib/http2.h |  4 ++++
b99ba0
 lib/multi.c | 20 ++++++++++++++++++++
b99ba0
 3 files changed, 32 insertions(+)
b99ba0
b99ba0
diff --git a/lib/http2.c b/lib/http2.c
b99ba0
index d769193..3071097 100644
b99ba0
--- a/lib/http2.c
b99ba0
+++ b/lib/http2.c
b99ba0
@@ -2300,6 +2300,14 @@ void Curl_http2_cleanup_dependencies(struct Curl_easy *data)
b99ba0
     Curl_http2_remove_child(data->set.stream_depends_on, data);
b99ba0
 }
b99ba0
 
b99ba0
+/* Only call this function for a transfer that already got a HTTP/2
b99ba0
+   CURLE_HTTP2_STREAM error! */
b99ba0
+bool Curl_h2_http_1_1_error(struct connectdata *conn)
b99ba0
+{
b99ba0
+  struct http_conn *httpc = &conn->proto.httpc;
b99ba0
+  return (httpc->error_code == NGHTTP2_HTTP_1_1_REQUIRED);
b99ba0
+}
b99ba0
+
b99ba0
 #else /* !USE_NGHTTP2 */
b99ba0
 
b99ba0
 /* Satisfy external references even if http2 is not compiled in. */
b99ba0
diff --git a/lib/http2.h b/lib/http2.h
b99ba0
index 21cd9b8..91e504c 100644
b99ba0
--- a/lib/http2.h
b99ba0
+++ b/lib/http2.h
b99ba0
@@ -59,6 +59,9 @@ CURLcode Curl_http2_add_child(struct Curl_easy *parent,
b99ba0
 void Curl_http2_remove_child(struct Curl_easy *parent,
b99ba0
                              struct Curl_easy *child);
b99ba0
 void Curl_http2_cleanup_dependencies(struct Curl_easy *data);
b99ba0
+
b99ba0
+/* returns true if the HTTP/2 stream error was HTTP_1_1_REQUIRED */
b99ba0
+bool Curl_h2_http_1_1_error(struct connectdata *conn);
b99ba0
 #else /* USE_NGHTTP2 */
b99ba0
 #define Curl_http2_init(x) CURLE_UNSUPPORTED_PROTOCOL
b99ba0
 #define Curl_http2_send_request(x) CURLE_UNSUPPORTED_PROTOCOL
b99ba0
@@ -74,6 +77,7 @@ void Curl_http2_cleanup_dependencies(struct Curl_easy *data);
b99ba0
 #define Curl_http2_add_child(x, y, z)
b99ba0
 #define Curl_http2_remove_child(x, y)
b99ba0
 #define Curl_http2_cleanup_dependencies(x)
b99ba0
+#define Curl_h2_http_1_1_error(x) 0
b99ba0
 #endif
b99ba0
 
b99ba0
 #endif /* HEADER_CURL_HTTP2_H */
b99ba0
diff --git a/lib/multi.c b/lib/multi.c
b99ba0
index 0f57fd5..d64ba94 100644
b99ba0
--- a/lib/multi.c
b99ba0
+++ b/lib/multi.c
b99ba0
@@ -46,6 +46,7 @@
b99ba0
 #include "vtls/vtls.h"
b99ba0
 #include "connect.h"
b99ba0
 #include "http_proxy.h"
b99ba0
+#include "http2.h"
b99ba0
 /* The last 3 #include files should be in this order */
b99ba0
 #include "curl_printf.h"
b99ba0
 #include "curl_memory.h"
b99ba0
@@ -1943,6 +1944,25 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
b99ba0
           done = TRUE;
b99ba0
         }
b99ba0
       }
b99ba0
+      else if((CURLE_HTTP2_STREAM == result) &&
b99ba0
+                Curl_h2_http_1_1_error(data->easy_conn)) {
b99ba0
+        CURLcode ret = Curl_retry_request(data->easy_conn, &newurl);
b99ba0
+
b99ba0
+        infof(data, "Forcing HTTP/1.1 for NTLM");
b99ba0
+        data->set.httpversion = CURL_HTTP_VERSION_1_1;
b99ba0
+
b99ba0
+        if(!ret)
b99ba0
+          retry = (newurl)?TRUE:FALSE;
b99ba0
+        else
b99ba0
+          result = ret;
b99ba0
+
b99ba0
+        if(retry) {
b99ba0
+          /* if we are to retry, set the result to OK and consider the
b99ba0
+             request as done */
b99ba0
+          result = CURLE_OK;
b99ba0
+          done = TRUE;
b99ba0
+        }
b99ba0
+      }
b99ba0
 
b99ba0
       if(result) {
b99ba0
         /*
b99ba0
-- 
b99ba0
2.37.3
b99ba0