Skip to content

Commit bc6618e

Browse files
committed
lib/libfetch: Accept all HTTP 2xx (Successful) status codes
Some HTTP 2xx (Successful) class status codes were being treated as errors. Add a definition for the full range of successful status codes and use it to test for a success response. This allows libfetch and fetch to receive the response body from more practical requests, such as POST responding 201 Created with content. Signed-off-by: Ryan Moeller <[email protected]>
1 parent 75dbbcb commit bc6618e

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/libfetch/http.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@
114114
#define HTTP_BAD_RANGE 416
115115
#define HTTP_PROTOCOL_ERROR 999
116116

117+
#define HTTP_SUCCESS(xyz) ((xyz) >= 200 && (xyz) <= 299)
118+
117119
#define HTTP_REDIRECT(xyz) ((xyz) == HTTP_MOVED_PERM \
118120
|| (xyz) == HTTP_MOVED_TEMP \
119121
|| (xyz) == HTTP_TEMP_REDIRECT \
@@ -1959,8 +1961,6 @@ http_request_body(struct url *URL, const char *op, struct url_stat *us,
19591961

19601962
/* get reply */
19611963
switch (http_get_reply(conn)) {
1962-
case HTTP_OK:
1963-
case HTTP_PARTIAL:
19641964
case HTTP_NOT_MODIFIED:
19651965
/* fine */
19661966
break;
@@ -2015,6 +2015,8 @@ http_request_body(struct url *URL, const char *op, struct url_stat *us,
20152015
goto ouch;
20162016
default:
20172017
http_seterr(conn->err);
2018+
if (HTTP_SUCCESS(conn->err))
2019+
break;
20182020
if (!verbose)
20192021
goto ouch;
20202022
/* fall through so we can get the full error message */
@@ -2163,9 +2165,8 @@ http_request_body(struct url *URL, const char *op, struct url_stat *us,
21632165
}
21642166

21652167
/* we have a hit or an error */
2166-
if (conn->err == HTTP_OK
2168+
if (HTTP_SUCCESS(conn->err)
21672169
|| conn->err == HTTP_NOT_MODIFIED
2168-
|| conn->err == HTTP_PARTIAL
21692170
|| HTTP_ERROR(conn->err))
21702171
break;
21712172

0 commit comments

Comments
 (0)