curl/0005-curl-7.24.0-d317ca50.patch

96 lines
2.6 KiB
Diff

From 9381e20457e3c7ff9da306fae60dc91e76526ce0 Mon Sep 17 00:00:00 2001
From: Kamil Dudka <kdudka@redhat.com>
Date: Fri, 20 Jul 2012 13:33:58 +0200
Subject: [PATCH] http: print reason phrase from HTTP status line on error
[upstream commit d317ca50ae7d8bb250431f86709e53b94f7f6ddf]
Bug: https://bugzilla.redhat.com/676596
---
lib/http.c | 39 +++++++++++++++++++++++++++++++++++++--
tests/data/test24 | 5 ++++-
2 files changed, 41 insertions(+), 3 deletions(-)
diff --git a/lib/http.c b/lib/http.c
index fe1c7fd..310e584 100644
--- a/lib/http.c
+++ b/lib/http.c
@@ -2721,6 +2721,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.
@@ -3108,8 +3144,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;
}
}
diff --git a/tests/data/test24 b/tests/data/test24
index 7985f43..18e7d5b 100644
--- a/tests/data/test24
+++ b/tests/data/test24
@@ -24,7 +24,7 @@ http
HTTP GET fail silently on HTTP error return
</name>
<command>
-http://%HOSTIP:%HTTPPORT/24 --fail
+http://%HOSTIP:%HTTPPORT/24 --fail --silent --show-error
</command>
</client>
@@ -43,5 +43,8 @@ Accept: */*
<errorcode>
22
</errorcode>
+<file2 name="log/stderr24">
+curl: (22) The requested URL returned error: 404 BAD BOY
+</file2>
</verify>
</testcase>
--
1.7.1