]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: http-client-connection - Move handling of 100 response to http-client-request
authorStephan Bosch <stephan.bosch@open-xchange.com>
Thu, 20 May 2021 21:54:24 +0000 (23:54 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Fri, 7 Mar 2025 14:56:56 +0000 (14:56 +0000)
src/lib-http/http-client-connection.c
src/lib-http/http-client-private.h
src/lib-http/http-client-request.c

index 4f860625ebbe4bc2a90212eb09eee5ffb981304e..41d4d01d01f7b58bfe9ab4eb90326e42d9ec4ee1 100644 (file)
@@ -1009,7 +1009,6 @@ http_client_connection_process_response(struct http_client_connection *conn,
                                        struct http_client_request *req,
                                        struct http_response *resp)
 {
-       struct http_client_peer_shared *pshared = conn->ppool->peer;
        struct http_client_request *req_ref;
        bool aborted, early = FALSE;
 
@@ -1040,42 +1039,8 @@ http_client_connection_process_response(struct http_client_connection *conn,
        /* Got some response; cancel response timeout */
        timeout_remove(&conn->to_response);
 
-       /* RFC 7231, Section 6.2:
-
-          A client MUST be able to parse one or more 1xx responses received
-          prior to a final response, even if the client does not expect one.
-          A user agent MAY ignore unexpected 1xx responses.
-        */
-       if (req->payload_sync && resp->status == 100) {
-               if (req->payload_sync_continue) {
-                       e_debug(conn->event,
-                               "Got 100-continue response after timeout");
-                       return 0;
-               }
-
-               pshared->no_payload_sync = FALSE;
-               pshared->seen_100_response = TRUE;
-               req->payload_sync_continue = TRUE;
-
-               e_debug(conn->event,
-                       "Got expected 100-continue response");
-
-               if (req->state == HTTP_REQUEST_STATE_ABORTED) {
-                       e_debug(conn->event,
-                               "Request aborted before sending payload was complete.");
-                       http_client_connection_close(&conn);
-                       return -1;
-               }
-
-               if (conn->conn.output != NULL)
-                       o_stream_set_flush_pending(conn->conn.output, TRUE);
-               return -1;
-       } else if (resp->status / 100 == 1) {
-               /* Ignore other 1xx for now */
-               e_debug(conn->event,
-                       "Got unexpected %u response; ignoring",
-                       resp->status);
-               return 0;
+       if (resp->status / 100 == 1) {
+               return http_client_request_1xx_response(req, resp);
        } else if ((!req->payload_sync || req->payload_sync_continue) &&
                   !req->payload_finished &&
                   req->state == HTTP_REQUEST_STATE_PAYLOAD_OUT) {
index db9829445a2c618b13a0a614c7d6f136bf29a3a8..d83bea5ce78c407210795f7dbf8241fff5d0c913 100644 (file)
@@ -501,6 +501,8 @@ int http_client_request_send(struct http_client_request *req, bool pipelined);
 int http_client_request_send_more(struct http_client_request *req,
                                  bool pipelined);
 
+int http_client_request_1xx_response(struct http_client_request *req,
+                                    struct http_response *resp);
 bool http_client_request_callback(struct http_client_request *req,
                                  struct http_response *response);
 void http_client_request_connect_callback(
index d640978c50654c9c5311be0efc2bfb8cbfab2510..b78134899cf747d9a6080e58f6caeb2f695b4c0e 100644 (file)
@@ -1561,6 +1561,52 @@ int http_client_request_send(struct http_client_request *req, bool pipelined)
        return ret;
 }
 
+int http_client_request_1xx_response(struct http_client_request *req,
+                                    struct http_response *resp)
+{
+       struct http_client_connection *conn = req->conn;
+
+       /* RFC 7231, Section 6.2:
+
+          A client MUST be able to parse one or more 1xx responses received
+          prior to a final response, even if the client does not expect one.
+          A user agent MAY ignore unexpected 1xx responses.
+        */
+
+       if (req->payload_sync && resp->status == 100) {
+               struct http_client_peer_shared *pshared = conn->ppool->peer;
+
+               if (req->payload_sync_continue) {
+                       e_debug(req->event,
+                               "Got 100-continue response after timeout");
+                       return 0;
+               }
+
+               pshared->no_payload_sync = FALSE;
+               pshared->seen_100_response = TRUE;
+               req->payload_sync_continue = TRUE;
+
+               e_debug(req->event,
+                       "Got expected 100-continue response");
+
+               if (req->state == HTTP_REQUEST_STATE_ABORTED) {
+                       e_debug(req->event,
+                               "Request aborted before sending payload was complete.");
+                       http_client_connection_close(&conn);
+                       return -1;
+               }
+
+               if (conn->conn.output != NULL)
+                       o_stream_set_flush_pending(conn->conn.output, TRUE);
+               return -1;
+       }
+
+       /* Ignore other 1xx for now */
+       e_debug(req->event,
+               "Got unexpected %u response; ignoring", resp->status);
+       return 0;
+}
+
 bool http_client_request_callback(struct http_client_request *req,
                                  struct http_response *response)
 {