From 54d23dfc07123acffbcd36b8aa1c1f8f3f94fda7 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 25 Oct 2012 19:04:45 +0200 Subject: [PATCH] CLEANUP: http: rename HTTP_MSG_DATA_CRLF state This state's name is confusing as it is only used with chunked encoding and makes newcomers think it's also related to the content-length. Let's call it CHUNK_CRLF to clear any doubt on this. --- include/types/proto_http.h | 2 +- src/proto_http.c | 34 ++++++++++++++-------------------- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/include/types/proto_http.h b/include/types/proto_http.h index 2e3b80be1c..4db7882e01 100644 --- a/include/types/proto_http.h +++ b/include/types/proto_http.h @@ -166,7 +166,7 @@ #define HTTP_MSG_100_SENT 28 // parsing body after a 100-Continue was sent #define HTTP_MSG_CHUNK_SIZE 29 // parsing the chunk size (RFC2616 #3.6.1) #define HTTP_MSG_DATA 30 // skipping data chunk / content-length data -#define HTTP_MSG_DATA_CRLF 31 // skipping CRLF after data chunk +#define HTTP_MSG_CHUNK_CRLF 31 // skipping CRLF after data chunk #define HTTP_MSG_TRAILERS 32 // trailers (post-data entity headers) /* we enter this state when we've received the end of the current message */ diff --git a/src/proto_http.c b/src/proto_http.c index 0c812d9e86..4377573d91 100644 --- a/src/proto_http.c +++ b/src/proto_http.c @@ -1919,7 +1919,7 @@ static int http_forward_trailers(struct http_msg *msg) } } -/* This function may be called only in HTTP_MSG_DATA_CRLF. It reads the CRLF or +/* This function may be called only in HTTP_MSG_CHUNK_CRLF. It reads the CRLF or * a possible LF alone at the end of a chunk. It automatically adjusts msg->sov, * ->sol, ->next in order to include this part into the next forwarding phase. * Note that the caller must ensure that ->p points to the first byte to parse. @@ -4318,9 +4318,8 @@ int http_request_forward_body(struct session *s, struct channel *req, int an_bit if (msg->flags & HTTP_MSGF_TE_CHNK) msg->msg_state = HTTP_MSG_CHUNK_SIZE; - else { + else msg->msg_state = HTTP_MSG_DATA; - } } while (1) { @@ -4343,7 +4342,7 @@ int http_request_forward_body(struct session *s, struct channel *req, int an_bit /* nothing left to forward */ if (msg->flags & HTTP_MSGF_TE_CHNK) - msg->msg_state = HTTP_MSG_DATA_CRLF; + msg->msg_state = HTTP_MSG_CHUNK_CRLF; else msg->msg_state = HTTP_MSG_DONE; } @@ -4354,7 +4353,7 @@ int http_request_forward_body(struct session *s, struct channel *req, int an_bit */ int ret = http_parse_chunk_size(msg); - if (!ret) + if (ret == 0) goto missing_data; else if (ret < 0) { session_inc_http_err_ctr(s); @@ -4364,18 +4363,16 @@ int http_request_forward_body(struct session *s, struct channel *req, int an_bit } /* otherwise we're in HTTP_MSG_DATA or HTTP_MSG_TRAILERS state */ } - else if (msg->msg_state == HTTP_MSG_DATA_CRLF) { + else if (msg->msg_state == HTTP_MSG_CHUNK_CRLF) { /* we want the CRLF after the data */ - int ret; - - ret = http_skip_chunk_crlf(msg); + int ret = http_skip_chunk_crlf(msg); if (ret == 0) goto missing_data; else if (ret < 0) { session_inc_http_err_ctr(s); if (msg->err_pos >= 0) - http_capture_bad_message(&s->fe->invalid_req, s, msg, HTTP_MSG_DATA_CRLF, s->be); + http_capture_bad_message(&s->fe->invalid_req, s, msg, HTTP_MSG_CHUNK_CRLF, s->be); goto return_bad_req; } /* we're in MSG_CHUNK_SIZE now */ @@ -5381,9 +5378,8 @@ int http_response_forward_body(struct session *s, struct channel *res, int an_bi if (msg->flags & HTTP_MSGF_TE_CHNK) msg->msg_state = HTTP_MSG_CHUNK_SIZE; - else { + else msg->msg_state = HTTP_MSG_DATA; - } } while (1) { @@ -5404,7 +5400,7 @@ int http_response_forward_body(struct session *s, struct channel *res, int an_bi /* nothing left to forward */ if (msg->flags & HTTP_MSGF_TE_CHNK) - msg->msg_state = HTTP_MSG_DATA_CRLF; + msg->msg_state = HTTP_MSG_CHUNK_CRLF; else msg->msg_state = HTTP_MSG_DONE; } @@ -5415,7 +5411,7 @@ int http_response_forward_body(struct session *s, struct channel *res, int an_bi */ int ret = http_parse_chunk_size(msg); - if (!ret) + if (ret == 0) goto missing_data; else if (ret < 0) { if (msg->err_pos >= 0) @@ -5424,17 +5420,15 @@ int http_response_forward_body(struct session *s, struct channel *res, int an_bi } /* otherwise we're in HTTP_MSG_DATA or HTTP_MSG_TRAILERS state */ } - else if (msg->msg_state == HTTP_MSG_DATA_CRLF) { + else if (msg->msg_state == HTTP_MSG_CHUNK_CRLF) { /* we want the CRLF after the data */ - int ret; + int ret = http_skip_chunk_crlf(msg); - ret = http_skip_chunk_crlf(msg); - - if (!ret) + if (ret == 0) goto missing_data; else if (ret < 0) { if (msg->err_pos >= 0) - http_capture_bad_message(&s->be->invalid_rep, s, msg, HTTP_MSG_DATA_CRLF, s->fe); + http_capture_bad_message(&s->be->invalid_rep, s, msg, HTTP_MSG_CHUNK_CRLF, s->fe); goto return_bad_res; } /* we're in MSG_CHUNK_SIZE now */