From 2de2c1eea94c40233c75b789864e0cc07e79723a Mon Sep 17 00:00:00 2001 From: Dan O'Neill Date: Mon, 2 Jan 2012 22:34:57 -0800 Subject: [PATCH] Added logic to correctly handle 204 No Content HTTP status --- SRC/http.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/SRC/http.c b/SRC/http.c index 8be54b8..f2bc8d1 100644 --- a/SRC/http.c +++ b/SRC/http.c @@ -61,7 +61,7 @@ read_from_server(CHANNEL fs, short ssl, boolean accept_redirects) { int nr = 0; int total = 0; - char reply_code; + int reply_code; int first_line = TRUE; short body = FALSE; #ifdef OPENSSL @@ -107,8 +107,15 @@ read_from_server(CHANNEL fs, short ssl, boolean accept_redirects) * if ((int) big_recvline[nr-1] == 10) nr--; */ if (first_line) { - reply_code = big_recvline[9]; /* 9 because "HTTP/1.x 200..." */ - if (reply_code != '2' && !(reply_code == '3' && accept_redirects)) + /* sscanf parse "HTTP/1.x 200" */ + sscanf(big_recvline,"%*s %d", &reply_code); + + /* 204 No Content is not an error, message body is empty by definition, see RFC 2616 */ + if (reply_code == 204) + return 0; /* zero bytes is correct */ + + if (! (reply_code >= 200 && reply_code < 300) && + ! ((reply_code >= 300 && reply_code < 400) && accept_redirects)) /* * Status codes beginning with 3 are not * errors See bug #850674 and RFC 2616,