aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKamil Dudka <kdudka@redhat.com>2012-07-20 13:33:58 +0200
committerKamil Dudka <kdudka@redhat.com>2012-07-22 02:12:43 +0200
commitd317ca50ae7d8bb250431f86709e53b94f7f6ddf (patch)
treeb29f3c366ecb508c78ce928ea238fff7d828a04f /lib
parent487406c3c0d86c5ef3fd323df35db71467b02a92 (diff)
http: print reason phrase from HTTP status line on error
Bug: https://bugzilla.redhat.com/676596
Diffstat (limited to 'lib')
-rw-r--r--lib/http.c39
1 files changed, 37 insertions, 2 deletions
diff --git a/lib/http.c b/lib/http.c
index b421a2c73..06bdf610c 100644
--- a/lib/http.c
+++ b/lib/http.c
@@ -2726,6 +2726,42 @@ static CURLcode header_append(struct SessionHandle *data,
return CURLE_OK;
}
+static void print_http_error(struct SessionHandle *data)
+{
+ struct SingleRequest *k = &data->req;
+ char *beg = k->p;
+
+ /* make sure that data->req.p points to the HTTP status line */
+ if(!strncmp(beg, "HTTP", 4)) {
+
+ /* skip to HTTP status code */
+ beg = strchr(beg, ' ');
+ if(beg && *++beg) {
+
+ /* find trailing CR */
+ char end_char = '\r';
+ char *end = strchr(beg, end_char);
+ if(!end) {
+ /* try to find LF (workaround for non-compliant HTTP servers) */
+ end_char = '\n';
+ end = strchr(beg, end_char);
+ }
+
+ if(end) {
+ /* temporarily replace CR or LF by NUL and print the error message */
+ *end = '\0';
+ failf(data, "The requested URL returned error: %s", beg);
+
+ /* restore the previously replaced CR or LF */
+ *end = end_char;
+ return;
+ }
+ }
+ }
+
+ /* fall-back to printing the HTTP status code only */
+ failf(data, "The requested URL returned error: %d", k->httpcode);
+}
/*
* Read any HTTP header lines from the server and pass them to the client app.
@@ -3114,8 +3150,7 @@ CURLcode Curl_http_readwrite_headers(struct SessionHandle *data,
}
else {
/* serious error, go home! */
- failf (data, "The requested URL returned error: %d",
- k->httpcode);
+ print_http_error(data);
return CURLE_HTTP_RETURNED_ERROR;
}
}