]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: proto_htx: Add function to handle the header "Expect: 100-continue"
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 1 Mar 2019 10:19:40 +0000 (11:19 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 19 Mar 2019 08:51:38 +0000 (09:51 +0100)
The function htx_handle_expect_hdr() is now responsible to search the header
"Expect" and send the corresponding response if necessary.

src/proto_htx.c

index 05a7fb19ec42f4897f3b32814322cd70a6a9830b..22ad491fe71b365c61c027b34acbea6d743f5f96 100644 (file)
@@ -60,6 +60,7 @@ static void htx_manage_server_side_cookies(struct stream *s, struct channel *res
 static int htx_stats_check_uri(struct stream *s, struct http_txn *txn, struct proxy *backend);
 static int htx_handle_stats(struct stream *s, struct channel *req);
 
+static int htx_handle_expect_hdr(struct stream *s, struct htx *htx, struct http_msg *msg);
 static int htx_reply_100_continue(struct stream *s);
 static int htx_reply_40x_unauthorized(struct stream *s, const char *auth_realm);
 
@@ -1075,22 +1076,8 @@ int htx_wait_for_request_body(struct stream *s, struct channel *req, int an_bit)
         */
 
        if (msg->msg_state < HTTP_MSG_DATA) {
-               /* If we have HTTP/1.1 and Expect: 100-continue, then we must
-                * send an HTTP/1.1 100 Continue intermediate response.
-                */
-               if (msg->flags & HTTP_MSGF_VER_11) {
-                       struct ist hdr = { .ptr = "Expect", .len = 6 };
-                       struct http_hdr_ctx ctx;
-
-                       ctx.blk = NULL;
-                       /* Expect is allowed in 1.1, look for it */
-                       if (http_find_header(htx, hdr, &ctx, 0) &&
-                           unlikely(isteqi(ctx.value, ist2("100-continue", 12)))) {
-                               if (htx_reply_100_continue(s) == -1)
-                                       goto return_bad_req;
-                               http_remove_header(htx, &ctx);
-                       }
-               }
+               if (htx_handle_expect_hdr(s, htx, msg) == -1)
+                       goto return_bad_req;
        }
 
        msg->msg_state = HTTP_MSG_DATA;
@@ -5361,6 +5348,31 @@ struct buffer *htx_error_message(struct stream *s)
 }
 
 
+/* Handle Expect: 100-continue for HTTP/1.1 messages if necessary. It returns 0
+ * on success and -1 on error.
+ */
+static int htx_handle_expect_hdr(struct stream *s, struct htx *htx, struct http_msg *msg)
+{
+       /* If we have HTTP/1.1 message with a body and Expect: 100-continue,
+        * then we must send an HTTP/1.1 100 Continue intermediate response.
+        */
+       if (msg->msg_state == HTTP_MSG_BODY && (msg->flags & HTTP_MSGF_VER_11) &&
+           (msg->flags & (HTTP_MSGF_CNT_LEN|HTTP_MSGF_TE_CHNK))) {
+               struct ist hdr = { .ptr = "Expect", .len = 6 };
+               struct http_hdr_ctx ctx;
+
+               ctx.blk = NULL;
+               /* Expect is allowed in 1.1, look for it */
+               if (http_find_header(htx, hdr, &ctx, 0) &&
+                   unlikely(isteqi(ctx.value, ist2("100-continue", 12)))) {
+                       if (htx_reply_100_continue(s) == -1)
+                               return -1;
+                       http_remove_header(htx, &ctx);
+               }
+       }
+       return 0;
+}
+
 /* Send a 100-Continue response to the client. It returns 0 on success and -1
  * on error. The response channel is updated accordingly.
  */