]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
urldata: move authneg bit from conn to Curl_easy
authorStefan Eissing <stefan@eissing.org>
Fri, 16 Feb 2024 11:15:10 +0000 (12:15 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 26 Feb 2024 09:30:52 +0000 (10:30 +0100)
- from `conn->bits.authneg` to `data->req.authneg`
- this is a property of the request about to be made
  and not a property of the connection
- in multiuse connections, transfer could step on each others
  toes here potentially.

Closes #12949

lib/c-hyper.c
lib/http.c
lib/urldata.h

index 845c179392a30042e0a72374cc69ca1b451d2c43..f07dd6c0b19694dc4ed12e0d08ab813458d5612b 100644 (file)
@@ -696,7 +696,6 @@ static int uploadstreamed(void *userdata, hyper_context *ctx,
 {
   size_t fillcount;
   struct Curl_easy *data = (struct Curl_easy *)userdata;
-  struct connectdata *conn = (struct connectdata *)data->conn;
   CURLcode result;
   (void)ctx;
 
@@ -711,7 +710,7 @@ static int uploadstreamed(void *userdata, hyper_context *ctx,
     return HYPER_POLL_PENDING;
   }
 
-  if(data->req.upload_chunky && conn->bits.authneg) {
+  if(data->req.upload_chunky && data->req.authneg) {
     fillcount = 0;
     data->req.upload_chunky = FALSE;
     result = CURLE_OK;
@@ -1174,7 +1173,7 @@ CURLcode Curl_http(struct Curl_easy *data, bool *done)
 
   Curl_debug(data, CURLINFO_HEADER_OUT, (char *)"\r\n", 2);
 
-  if(data->req.upload_chunky && conn->bits.authneg) {
+  if(data->req.upload_chunky && data->req.authneg) {
     data->req.upload_chunky = TRUE;
   }
   else {
index 5b4814cf8b4620ab6fcad7ffd85a9f51d6322b87..dd1fc4ffa0ef963872403924018a4a60dd42a8d3 100644 (file)
@@ -447,7 +447,7 @@ static CURLcode http_perhapsrewind(struct Curl_easy *data,
 
   bytessent = data->req.writebytecount;
 
-  if(conn->bits.authneg) {
+  if(data->req.authneg) {
     /* This is a state where we are known to be negotiating and we don't send
        any data then. */
     expectsend = 0;
@@ -489,7 +489,7 @@ static CURLcode http_perhapsrewind(struct Curl_easy *data,
            data left to send, keep on sending. */
 
         /* rewind data when completely done sending! */
-        if(!conn->bits.authneg && (conn->writesockfd != CURL_SOCKET_BAD)) {
+        if(!data->req.authneg && (conn->writesockfd != CURL_SOCKET_BAD)) {
           data->state.rewindbeforesend = TRUE;
           infof(data, "Rewind stream before next send");
         }
@@ -517,7 +517,7 @@ static CURLcode http_perhapsrewind(struct Curl_easy *data,
         there is just a little (<2K) data left to send, keep on sending. */
 
         /* rewind data when completely done sending! */
-        if(!conn->bits.authneg && (conn->writesockfd != CURL_SOCKET_BAD)) {
+        if(!data->req.authneg && (conn->writesockfd != CURL_SOCKET_BAD)) {
           data->state.rewindbeforesend = TRUE;
           infof(data, "Rewind stream before next send");
         }
@@ -579,7 +579,7 @@ CURLcode Curl_http_auth_act(struct Curl_easy *data)
 
   if((data->state.aptr.user || data->set.str[STRING_BEARER]) &&
      ((data->req.httpcode == 401) ||
-      (conn->bits.authneg && data->req.httpcode < 300))) {
+      (data->req.authneg && data->req.httpcode < 300))) {
     pickhost = pickoneauth(&data->state.authhost, authmask);
     if(!pickhost)
       data->state.authproblem = TRUE;
@@ -593,7 +593,7 @@ CURLcode Curl_http_auth_act(struct Curl_easy *data)
 #ifndef CURL_DISABLE_PROXY
   if(conn->bits.proxy_user_passwd &&
      ((data->req.httpcode == 407) ||
-      (conn->bits.authneg && data->req.httpcode < 300))) {
+      (data->req.authneg && data->req.httpcode < 300))) {
     pickproxy = pickoneauth(&data->state.authproxy,
                             authmask & ~CURLAUTH_BEARER);
     if(!pickproxy)
@@ -619,7 +619,7 @@ CURLcode Curl_http_auth_act(struct Curl_easy *data)
   }
   else if((data->req.httpcode < 300) &&
           (!data->state.authhost.done) &&
-          conn->bits.authneg) {
+          data->req.authneg) {
     /* no (known) authentication available,
        authentication is not "done" yet and
        no authentication seems to be required and
@@ -864,10 +864,10 @@ Curl_http_output_auth(struct Curl_easy *data,
      (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;
+    data->req.authneg = TRUE;
   }
   else
-    conn->bits.authneg = FALSE;
+    data->req.authneg = FALSE;
 
   return result;
 }
@@ -1809,7 +1809,7 @@ CURLcode Curl_dynhds_add_custom(struct Curl_easy *data,
               /* this header is sent later */
               hd_name_eq(name, namelen, STRCONST("Content-Type:")))
         ;
-      else if(conn->bits.authneg &&
+      else if(data->req.authneg &&
               /* while doing auth neg, don't allow the custom length since
                  we will force length zero then */
               hd_name_eq(name, namelen, STRCONST("Content-Length:")))
@@ -1955,7 +1955,7 @@ CURLcode Curl_add_custom_headers(struct Curl_easy *data,
                   /* this header is sent later */
                   checkprefix("Content-Type:", compare))
             ;
-          else if(conn->bits.authneg &&
+          else if(data->req.authneg &&
                   /* while doing auth neg, don't allow the custom length since
                      we will force length zero then */
                   checkprefix("Content-Length:", compare))
@@ -2413,7 +2413,7 @@ CURLcode Curl_http_body(struct Curl_easy *data, struct connectdata *conn,
          http->postsize < 0) ||
         ((data->state.upload || httpreq == HTTPREQ_POST) &&
          data->state.infilesize == -1))) {
-      if(conn->bits.authneg)
+      if(data->req.authneg)
         /* don't enable chunked during auth neg */
         ;
       else if(Curl_use_http_1_1plus(data, conn)) {
@@ -2476,13 +2476,13 @@ CURLcode Curl_http_bodysend(struct Curl_easy *data, struct connectdata *conn,
   switch(httpreq) {
   case HTTPREQ_PUT: /* Let's PUT the data to the server! */
 
-    if(conn->bits.authneg)
+    if(data->req.authneg)
       http->postsize = 0;
     else
       http->postsize = data->state.infilesize;
 
     if((http->postsize != -1) && !data->req.upload_chunky &&
-       (conn->bits.authneg ||
+       (data->req.authneg ||
         !Curl_checkheaders(data, STRCONST("Content-Length")))) {
       /* only add Content-Length if not uploading chunked */
       result = Curl_dyn_addf(r, "Content-Length: %" CURL_FORMAT_CURL_OFF_T
@@ -2521,7 +2521,7 @@ CURLcode Curl_http_bodysend(struct Curl_easy *data, struct connectdata *conn,
   case HTTPREQ_POST_FORM:
   case HTTPREQ_POST_MIME:
     /* This is form posting using mime data. */
-    if(conn->bits.authneg) {
+    if(data->req.authneg) {
       /* nothing to post! */
       result = Curl_dyn_addn(r, STRCONST("Content-Length: 0\r\n\r\n"));
       if(result)
@@ -2602,7 +2602,7 @@ CURLcode Curl_http_bodysend(struct Curl_easy *data, struct connectdata *conn,
   case HTTPREQ_POST:
     /* this is the simple POST, using x-www-form-urlencoded style */
 
-    if(conn->bits.authneg)
+    if(data->req.authneg)
       http->postsize = 0;
     else
       /* the size of the post body */
@@ -2612,7 +2612,7 @@ CURLcode Curl_http_bodysend(struct Curl_easy *data, struct connectdata *conn,
        we don't upload data chunked, as RFC2616 forbids us to set both
        kinds of headers (Transfer-Encoding: chunked and Content-Length) */
     if((http->postsize != -1) && !data->req.upload_chunky &&
-       (conn->bits.authneg ||
+       (data->req.authneg ||
         !Curl_checkheaders(data, STRCONST("Content-Length")))) {
       /* we allow replacing this header if not during auth negotiation,
          although it isn't very wise to actually set your own */
@@ -2708,7 +2708,7 @@ CURLcode Curl_http_bodysend(struct Curl_easy *data, struct connectdata *conn,
       if(result)
         return result;
 
-      if(data->req.upload_chunky && conn->bits.authneg) {
+      if(data->req.upload_chunky && data->req.authneg) {
         /* Chunky upload is selected and we're negotiating auth still, send
            end-of-data only */
         result = Curl_dyn_addn(r, (char *)STRCONST("\x30\x0d\x0a\x0d\x0a"));
@@ -2723,7 +2723,7 @@ CURLcode Curl_http_bodysend(struct Curl_easy *data, struct connectdata *conn,
 
         /* set the pointer to mark that we will send the post body using the
            read callback, but only if we're not in authenticate negotiation */
-        if(!conn->bits.authneg)
+        if(!data->req.authneg)
           http->postdata = (char *)&http->postdata;
       }
     }
@@ -4199,7 +4199,7 @@ static CURLcode http_rw_headers(struct Curl_easy *data,
         return result;
 
       if(k->httpcode >= 300) {
-        if((!conn->bits.authneg) && !conn->bits.close &&
+        if((!data->req.authneg) && !conn->bits.close &&
            !data->state.rewindbeforesend) {
           /*
            * General treatment of errors when about to send data. Including :
index 53d7709525d539882c88fe03b88016c6f892bde6..9955ab5ce035191fbf5d5dc488db9e3d99173cd3 100644 (file)
@@ -527,10 +527,6 @@ struct ConnectBits {
                          the TCP layer connect */
   BIT(retry);         /* this connection is about to get closed and then
                          re-attempted at another connection. */
-  BIT(authneg);       /* TRUE when the auth phase has started, which means
-                         that we are creating a request with an auth header,
-                         but it is not the final request in the auth
-                         negotiation. */
 #ifndef CURL_DISABLE_FTP
   BIT(ftp_use_epsv);  /* As set with CURLOPT_FTP_USE_EPSV, but if we find out
                          EPSV doesn't work we disable it for the forthcoming
@@ -753,6 +749,10 @@ struct SingleRequest {
                         specific upload buffers. See readmoredata() in http.c
                         for details. */
   BIT(no_body);      /* the response has no body */
+  BIT(authneg);      /* TRUE when the auth phase has started, which means
+                        that we are creating a request with an auth header,
+                        but it is not the final request in the auth
+                        negotiation. */
 };
 
 /*