diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2022-03-10 15:43:25 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2022-03-10 16:53:19 +0300 |
commit | b9743114cf6d4584968cfbfd3fdac95c14c1c692 (patch) | |
tree | d6f2691a2550c729d202b4b67bdf40dc562489e6 /src/microhttpd/connection.c | |
parent | b26d68a71c1e001383d35bdfbc958d7caa2aedde (diff) | |
download | libmicrohttpd-b9743114cf6d4584968cfbfd3fdac95c14c1c692.tar.gz libmicrohttpd-b9743114cf6d4584968cfbfd3fdac95c14c1c692.zip |
Added separate internal "responseIcy" flag.
This simplified the code.
Also fixed some incorrect responseCode processing without ICY mask.
Diffstat (limited to 'src/microhttpd/connection.c')
-rw-r--r-- | src/microhttpd/connection.c | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c index 3a1c3c43..9611e0a7 100644 --- a/src/microhttpd/connection.c +++ b/src/microhttpd/connection.c | |||
@@ -1693,10 +1693,10 @@ is_reply_body_headers_needed (struct MHD_Connection *connection) | |||
1693 | struct MHD_Connection *const c = connection; /**< a short alias */ | 1693 | struct MHD_Connection *const c = connection; /**< a short alias */ |
1694 | unsigned rcode; /**< the response code */ | 1694 | unsigned rcode; /**< the response code */ |
1695 | 1695 | ||
1696 | mhd_assert (100 <= (c->responseCode & (~MHD_ICY_FLAG)) && \ | 1696 | mhd_assert (100 <= c->responseCode); |
1697 | 999 >= (c->responseCode & (~MHD_ICY_FLAG))); | 1697 | mhd_assert (999 >= c->responseCode); |
1698 | 1698 | ||
1699 | rcode = (unsigned) (c->responseCode & (~MHD_ICY_FLAG)); | 1699 | rcode = (unsigned) c->responseCode; |
1700 | 1700 | ||
1701 | if (199 >= rcode) | 1701 | if (199 >= rcode) |
1702 | return false; | 1702 | return false; |
@@ -1733,8 +1733,8 @@ is_reply_body_needed (struct MHD_Connection *connection) | |||
1733 | struct MHD_Connection *const c = connection; /**< a short alias */ | 1733 | struct MHD_Connection *const c = connection; /**< a short alias */ |
1734 | unsigned rcode; /**< the response code */ | 1734 | unsigned rcode; /**< the response code */ |
1735 | 1735 | ||
1736 | mhd_assert (100 <= (c->responseCode & (~MHD_ICY_FLAG)) && \ | 1736 | mhd_assert (100 <= c->responseCode); |
1737 | 999 >= (c->responseCode & (~MHD_ICY_FLAG))); | 1737 | mhd_assert (999 >= c->responseCode); |
1738 | 1738 | ||
1739 | if (! is_reply_body_headers_needed (c)) | 1739 | if (! is_reply_body_headers_needed (c)) |
1740 | return false; | 1740 | return false; |
@@ -1742,7 +1742,7 @@ is_reply_body_needed (struct MHD_Connection *connection) | |||
1742 | if (MHD_HTTP_MTHD_HEAD == c->http_mthd) | 1742 | if (MHD_HTTP_MTHD_HEAD == c->http_mthd) |
1743 | return false; | 1743 | return false; |
1744 | 1744 | ||
1745 | rcode = (unsigned) (c->responseCode & (~MHD_ICY_FLAG)); | 1745 | rcode = (unsigned) c->responseCode; |
1746 | if (MHD_HTTP_NOT_MODIFIED == rcode) | 1746 | if (MHD_HTTP_NOT_MODIFIED == rcode) |
1747 | return false; | 1747 | return false; |
1748 | 1748 | ||
@@ -1831,7 +1831,7 @@ check_connection_reply (struct MHD_Connection *connection) | |||
1831 | MHD_DLOG (c->daemon, | 1831 | MHD_DLOG (c->daemon, |
1832 | _ ("This reply with response code %u cannot use reply body. " | 1832 | _ ("This reply with response code %u cannot use reply body. " |
1833 | "Non-empty response body is ignored and not used.\n"), | 1833 | "Non-empty response body is ignored and not used.\n"), |
1834 | (unsigned) (c->responseCode & (~MHD_ICY_FLAG))); | 1834 | (unsigned) (c->responseCode)); |
1835 | } | 1835 | } |
1836 | if ( (! c->rp_props.use_reply_body_headers) && | 1836 | if ( (! c->rp_props.use_reply_body_headers) && |
1837 | (0 != (r->flags_auto & MHD_RAF_HAS_CONTENT_LENGTH)) ) | 1837 | (0 != (r->flags_auto & MHD_RAF_HAS_CONTENT_LENGTH)) ) |
@@ -1840,7 +1840,7 @@ check_connection_reply (struct MHD_Connection *connection) | |||
1840 | _ ("This reply with response code %u cannot use reply body. " | 1840 | _ ("This reply with response code %u cannot use reply body. " |
1841 | "Application defined \"Content-Length\" header violates" | 1841 | "Application defined \"Content-Length\" header violates" |
1842 | "HTTP specification.\n"), | 1842 | "HTTP specification.\n"), |
1843 | (unsigned) (c->responseCode & (~MHD_ICY_FLAG))); | 1843 | (unsigned) (c->responseCode)); |
1844 | } | 1844 | } |
1845 | #else | 1845 | #else |
1846 | (void) c; /* Mute compiler warning */ | 1846 | (void) c; /* Mute compiler warning */ |
@@ -2049,7 +2049,7 @@ build_header_response (struct MHD_Connection *connection) | |||
2049 | 2049 | ||
2050 | check_connection_reply (c); | 2050 | check_connection_reply (c); |
2051 | 2051 | ||
2052 | rcode = (unsigned) (c->responseCode & (~MHD_ICY_FLAG)); | 2052 | rcode = (unsigned) c->responseCode; |
2053 | if (MHD_CONN_MUST_CLOSE == c->keepalive) | 2053 | if (MHD_CONN_MUST_CLOSE == c->keepalive) |
2054 | { | 2054 | { |
2055 | /* The closure of connection must be always indicated by header | 2055 | /* The closure of connection must be always indicated by header |
@@ -2091,7 +2091,7 @@ build_header_response (struct MHD_Connection *connection) | |||
2091 | /* * The status line * */ | 2091 | /* * The status line * */ |
2092 | 2092 | ||
2093 | /* The HTTP version */ | 2093 | /* The HTTP version */ |
2094 | if (0 == (c->responseCode & MHD_ICY_FLAG)) | 2094 | if (! c->responseIcy) |
2095 | { /* HTTP reply */ | 2095 | { /* HTTP reply */ |
2096 | if (0 == (r->flags & MHD_RF_HTTP_1_0_SERVER)) | 2096 | if (0 == (r->flags & MHD_RF_HTTP_1_0_SERVER)) |
2097 | { /* HTTP/1.1 reply */ | 2097 | { /* HTTP/1.1 reply */ |
@@ -4412,6 +4412,7 @@ connection_reset (struct MHD_Connection *connection, | |||
4412 | c->current_chunk_size = 0; | 4412 | c->current_chunk_size = 0; |
4413 | c->current_chunk_offset = 0; | 4413 | c->current_chunk_offset = 0; |
4414 | c->responseCode = 0; | 4414 | c->responseCode = 0; |
4415 | c->responseIcy = false; | ||
4415 | c->response_write_position = 0; | 4416 | c->response_write_position = 0; |
4416 | c->method = NULL; | 4417 | c->method = NULL; |
4417 | c->http_mthd = MHD_HTTP_MTHD_NO_METHOD; | 4418 | c->http_mthd = MHD_HTTP_MTHD_NO_METHOD; |
@@ -5140,7 +5141,10 @@ MHD_queue_response (struct MHD_Connection *connection, | |||
5140 | struct MHD_Response *response) | 5141 | struct MHD_Response *response) |
5141 | { | 5142 | { |
5142 | struct MHD_Daemon *daemon; | 5143 | struct MHD_Daemon *daemon; |
5144 | bool reply_icy; | ||
5143 | 5145 | ||
5146 | reply_icy = (0 != (status_code & MHD_ICY_FLAG)); | ||
5147 | status_code &= ~MHD_ICY_FLAG; | ||
5144 | if ((NULL == connection) || (NULL == response)) | 5148 | if ((NULL == connection) || (NULL == response)) |
5145 | return MHD_NO; | 5149 | return MHD_NO; |
5146 | 5150 | ||
@@ -5225,18 +5229,18 @@ MHD_queue_response (struct MHD_Connection *connection, | |||
5225 | } | 5229 | } |
5226 | } | 5230 | } |
5227 | #endif /* UPGRADE_SUPPORT */ | 5231 | #endif /* UPGRADE_SUPPORT */ |
5228 | if ( (100 > (status_code & (~MHD_ICY_FLAG))) || | 5232 | if ( (100 > status_code) || |
5229 | (999 < (status_code & (~MHD_ICY_FLAG))) ) | 5233 | (999 < status_code) ) |
5230 | { | 5234 | { |
5231 | #ifdef HAVE_MESSAGES | 5235 | #ifdef HAVE_MESSAGES |
5232 | MHD_DLOG (daemon, | 5236 | MHD_DLOG (daemon, |
5233 | _ ("Refused wrong status code (%u). " \ | 5237 | _ ("Refused wrong status code (%u). " \ |
5234 | "HTTP requires three digits status code!\n"), | 5238 | "HTTP requires three digits status code!\n"), |
5235 | (status_code & (~MHD_ICY_FLAG))); | 5239 | status_code); |
5236 | #endif | 5240 | #endif |
5237 | return MHD_NO; | 5241 | return MHD_NO; |
5238 | } | 5242 | } |
5239 | if (200 > (status_code & (~MHD_ICY_FLAG))) | 5243 | if (200 > status_code) |
5240 | { | 5244 | { |
5241 | if (MHD_HTTP_VER_1_0 == connection->http_ver) | 5245 | if (MHD_HTTP_VER_1_0 == connection->http_ver) |
5242 | { | 5246 | { |
@@ -5244,7 +5248,7 @@ MHD_queue_response (struct MHD_Connection *connection, | |||
5244 | MHD_DLOG (daemon, | 5248 | MHD_DLOG (daemon, |
5245 | _ ("Wrong status code (%u) refused. " \ | 5249 | _ ("Wrong status code (%u) refused. " \ |
5246 | "HTTP/1.0 clients do not support 1xx status codes!\n"), | 5250 | "HTTP/1.0 clients do not support 1xx status codes!\n"), |
5247 | (status_code & (~MHD_ICY_FLAG))); | 5251 | (status_code)); |
5248 | #endif | 5252 | #endif |
5249 | return MHD_NO; | 5253 | return MHD_NO; |
5250 | } | 5254 | } |
@@ -5255,7 +5259,7 @@ MHD_queue_response (struct MHD_Connection *connection, | |||
5255 | MHD_DLOG (daemon, | 5259 | MHD_DLOG (daemon, |
5256 | _ ("Wrong status code (%u) refused. " \ | 5260 | _ ("Wrong status code (%u) refused. " \ |
5257 | "HTTP/1.0 reply mode does not support 1xx status codes!\n"), | 5261 | "HTTP/1.0 reply mode does not support 1xx status codes!\n"), |
5258 | (status_code & (~MHD_ICY_FLAG))); | 5262 | (status_code)); |
5259 | #endif | 5263 | #endif |
5260 | return MHD_NO; | 5264 | return MHD_NO; |
5261 | } | 5265 | } |
@@ -5264,6 +5268,7 @@ MHD_queue_response (struct MHD_Connection *connection, | |||
5264 | MHD_increment_response_rc (response); | 5268 | MHD_increment_response_rc (response); |
5265 | connection->response = response; | 5269 | connection->response = response; |
5266 | connection->responseCode = status_code; | 5270 | connection->responseCode = status_code; |
5271 | connection->responseIcy = reply_icy; | ||
5267 | #if defined(_MHD_HAVE_SENDFILE) | 5272 | #if defined(_MHD_HAVE_SENDFILE) |
5268 | if ( (response->fd == -1) || | 5273 | if ( (response->fd == -1) || |
5269 | (response->is_pipe) || | 5274 | (response->is_pipe) || |