summaryrefslogtreecommitdiffstats
path: root/lib/libfetch/http.c
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2002-01-01 16:25:29 +0000
committerdes <des@FreeBSD.org>2002-01-01 16:25:29 +0000
commit99683cbbd444705e73126e8b12880b897fdb0a18 (patch)
tree77a05c96b676e18db2704d00cc28d3acae505968 /lib/libfetch/http.c
parent4f087f57b5e65433d303208d211c2445fd080030 (diff)
downloadFreeBSD-src-99683cbbd444705e73126e8b12880b897fdb0a18.zip
FreeBSD-src-99683cbbd444705e73126e8b12880b897fdb0a18.tar.gz
In verbose mode, display the full error message from the server, stripping
it of HTML tags and comments. PR: bin/32989 MFC after: 1 week
Diffstat (limited to 'lib/libfetch/http.c')
-rw-r--r--lib/libfetch/http.c51
1 files changed, 48 insertions, 3 deletions
diff --git a/lib/libfetch/http.c b/lib/libfetch/http.c
index 0cd1186..6158968 100644
--- a/lib/libfetch/http.c
+++ b/lib/libfetch/http.c
@@ -99,6 +99,7 @@ extern char *__progname; /* XXX not portable */
|| (xyz) == HTTP_MOVED_TEMP \
|| (xyz) == HTTP_SEE_OTHER)
+#define HTTP_ERROR(xyz) ((xyz) > 400 && (xyz) < 599)
/*****************************************************************************
@@ -675,6 +676,42 @@ _http_get_proxy(void)
return NULL;
}
+static void
+_http_print_html(FILE *out, FILE *in)
+{
+ size_t len;
+ char *line, *p, *q;
+ int comment, tag;
+
+ comment = tag = 0;
+ while ((line = fgetln(in, &len)) != NULL) {
+ while (len && isspace(line[len - 1]))
+ --len;
+ for (p = q = line; q < line + len; ++q) {
+ if (comment && *q == '-') {
+ if (q + 2 < line + len && strcmp(q, "-->") == 0) {
+ tag = comment = 0;
+ q += 2;
+ }
+ } if (tag && !comment && *q == '>') {
+ p = q + 1;
+ tag = 0;
+ } else if (!tag && *q == '<') {
+ if (q > p)
+ fwrite(p, q - p, 1, out);
+ tag = 1;
+ if (q + 3 < line + len && strcmp(q, "<!--") == 0) {
+ comment = 1;
+ q += 3;
+ }
+ }
+ }
+ if (!tag && q > p)
+ fwrite(p, q - p, 1, out);
+ fputc('\n', out);
+ }
+}
+
/*****************************************************************************
* Core
@@ -842,7 +879,9 @@ _http_request(struct url *URL, const char *op, struct url_stat *us,
goto ouch;
default:
_http_seterr(code);
- goto ouch;
+ if (!verbose)
+ goto ouch;
+ /* fall through so we can get the full error message */
}
/* get headers */
@@ -905,8 +944,8 @@ _http_request(struct url *URL, const char *op, struct url_stat *us,
}
} while (h > hdr_end);
- /* we have a hit */
- if (code == HTTP_OK || code == HTTP_PARTIAL)
+ /* we have a hit or an error */
+ if (code == HTTP_OK || code == HTTP_PARTIAL || HTTP_ERROR(code))
break;
/* we need to provide authentication */
@@ -983,6 +1022,12 @@ _http_request(struct url *URL, const char *op, struct url_stat *us,
fetchFreeURL(url);
if (purl)
fetchFreeURL(purl);
+
+ if (HTTP_ERROR(code)) {
+ _http_print_html(stderr, f);
+ fclose(f);
+ f = NULL;
+ }
return f;
OpenPOWER on IntegriCloud