MINOR: proto_htx: Add function to handle the header "Expect: 100-continue"

The function htx_handle_expect_hdr() is now responsible to search the header
"Expect" and send the corresponding response if necessary.
diff --git a/src/proto_htx.c b/src/proto_htx.c
index 05a7fb1..22ad491 100644
--- a/src/proto_htx.c
+++ b/src/proto_htx.c
@@ -60,6 +60,7 @@
 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 @@
 	 */
 
 	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 @@
 }
 
 
+/* 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.
  */