]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
http: make 'authneg' also work for Hyper
authorDaniel Stenberg <daniel@haxx.se>
Fri, 8 Jan 2021 15:17:12 +0000 (16:17 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Sun, 10 Jan 2021 13:51:33 +0000 (14:51 +0100)
When doing a request with a request body expecting a 401/407 back, that
initial request is sent with a zero content-length. Test 177 and more.

Closes #6424

lib/c-hyper.c
lib/http.c
lib/http.h
lib/http_proxy.c
lib/rtsp.c

index 19ba8d9b84c71b427a88576dc3b20cd6b1c5f6f8..4a68ffba02dd787710e7277496946c95200ba0c2 100644 (file)
@@ -670,7 +670,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
       if(!pq)
         return CURLE_OUT_OF_MEMORY;
     }
-    result = Curl_http_output_auth(conn, method,
+    result = Curl_http_output_auth(conn, method, httpreq,
                                    (pq ? pq : data->state.up.path), FALSE);
     free(pq);
     if(result)
index 42aa84ec02d26685b61fa4d401c50458391ff301..8bee326f4b09a3b21f0d5de176663ecc2b65407d 100644 (file)
@@ -784,6 +784,7 @@ output_auth_headers(struct connectdata *conn,
 CURLcode
 Curl_http_output_auth(struct connectdata *conn,
                       const char *request,
+                      Curl_HttpReq httpreq,
                       const char *path,
                       bool proxytunnel) /* TRUE if this is the request setting
                                            up the proxy tunnel */
@@ -850,6 +851,17 @@ Curl_http_output_auth(struct connectdata *conn,
   else
     authhost->done = TRUE;
 
+  if(((authhost->multipass && !authhost->done) ||
+      (authproxy->multipass && !authproxy->done)) &&
+     (httpreq != HTTPREQ_GET) &&
+     (httpreq != HTTPREQ_HEAD)) {
+    /* Auth is required and we are not authenticated yet. Make a PUT or POST
+       with content-length zero as a "probe". */
+    conn->bits.authneg = TRUE;
+  }
+  else
+    conn->bits.authneg = FALSE;
+
   return result;
 }
 
@@ -1962,7 +1974,7 @@ void Curl_http_method(struct Curl_easy *data, struct connectdata *conn,
     if(data->set.opt_no_body)
       request = "HEAD";
     else {
-      DEBUGASSERT((httpreq > HTTPREQ_NONE) && (httpreq < HTTPREQ_LAST));
+      DEBUGASSERT((httpreq >= HTTPREQ_GET) && (httpreq <= HTTPREQ_HEAD));
       switch(httpreq) {
       case HTTPREQ_POST:
       case HTTPREQ_POST_FORM:
@@ -2972,24 +2984,13 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
       if(!pq)
         return CURLE_OUT_OF_MEMORY;
     }
-    result = Curl_http_output_auth(conn, request,
+    result = Curl_http_output_auth(conn, request, httpreq,
                                    (pq ? pq : data->state.up.path), FALSE);
     free(pq);
     if(result)
       return result;
   }
 
-  if(((data->state.authhost.multipass && !data->state.authhost.done)
-      || (data->state.authproxy.multipass && !data->state.authproxy.done)) &&
-     (httpreq != HTTPREQ_GET) &&
-     (httpreq != HTTPREQ_HEAD)) {
-    /* Auth is required and we are not authenticated yet. Make a PUT or POST
-       with content-length zero as a "probe". */
-    conn->bits.authneg = TRUE;
-  }
-  else
-    conn->bits.authneg = FALSE;
-
   Curl_safefree(data->state.aptr.ref);
   if(data->change.referer && !Curl_checkheaders(conn, "Referer")) {
     data->state.aptr.ref = aprintf("Referer: %s\r\n", data->change.referer);
index b5e6ae915772d1b3a640a119f22f1cde1155acd5..23add25dd54e3e01a7b2562fb575771ee398bc44 100644 (file)
 #include "curl_setup.h"
 
 typedef enum {
-  HTTPREQ_NONE, /* first in list */
   HTTPREQ_GET,
   HTTPREQ_POST,
   HTTPREQ_POST_FORM, /* we make a difference internally */
   HTTPREQ_POST_MIME, /* we make a difference internally */
   HTTPREQ_PUT,
-  HTTPREQ_HEAD,
-  HTTPREQ_LAST /* last in list */
+  HTTPREQ_HEAD
 } Curl_HttpReq;
 
 #ifndef CURL_DISABLE_HTTP
@@ -295,6 +293,7 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
  *
  * @param conn all information about the current connection
  * @param request pointer to the request keyword
+ * @param httpreq is the request type
  * @param path pointer to the requested path
  * @param proxytunnel boolean if this is the request setting up a "proxy
  * tunnel"
@@ -304,6 +303,7 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
 CURLcode
 Curl_http_output_auth(struct connectdata *conn,
                       const char *request,
+                      Curl_HttpReq httpreq,
                       const char *path,
                       bool proxytunnel); /* TRUE if this is the request setting
                                             up the proxy tunnel */
index b7827860c37727209211cfe7543be5e3063e3db4..43bbe73d54ec8647ab30cc36f3fa858ce8bcbe77 100644 (file)
@@ -263,7 +263,8 @@ static CURLcode CONNECT(struct connectdata *conn,
         return result;
 
       /* Setup the proxy-authorization header, if any */
-      result = Curl_http_output_auth(conn, "CONNECT", hostheader, TRUE);
+      result = Curl_http_output_auth(conn, "CONNECT", HTTPREQ_GET,
+                                     hostheader, TRUE);
 
       if(!result) {
         const char *proxyconn = "";
@@ -739,7 +740,8 @@ static CURLcode CONNECT(struct connectdata *conn,
         result = CURLE_OUT_OF_MEMORY;
       }
       /* Setup the proxy-authorization header, if any */
-      result = Curl_http_output_auth(conn, "CONNECT", hostheader, TRUE);
+      result = Curl_http_output_auth(conn, "CONNECT", HTTPREQ_GET,
+                                     hostheader, TRUE);
       if(result)
         goto error;
       Curl_safefree(hostheader);
index e9ee2b36b50e29752aa91d93d81168b0b25fb153..a7299e12ba9de27b7a8608afb705b104c13f90c7 100644 (file)
@@ -5,7 +5,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2021, 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
@@ -385,7 +385,8 @@ static CURLcode rtsp_do(struct connectdata *conn, bool *done)
   }
 
   /* setup the authentication headers */
-  result = Curl_http_output_auth(conn, p_request, p_stream_uri, FALSE);
+  result = Curl_http_output_auth(conn, p_request, HTTPREQ_GET,
+                                 p_stream_uri, FALSE);
   if(result)
     return result;