1
0
mirror of https://github.com/moparisthebest/wget synced 2024-07-03 16:38:41 -04:00

Transform read_header label and goto into a loop

* src/http.c (gethttp): Replace label and goto statement with a do
loop.
This commit is contained in:
Hubert Tarasiuk 2015-03-27 15:35:57 +01:00 committed by Giuseppe Scrivano
parent 52a7d0ad85
commit 621c313b94

View File

@ -2597,55 +2597,66 @@ gethttp (struct url *u, struct http_stat *hs, int *dt, struct url *proxy,
/* warc_write_request_record has also closed warc_tmp. */ /* warc_write_request_record has also closed warc_tmp. */
} }
/* Repeat while we receive a 10x response code. */
{
bool _repeat;
read_header: do
head = read_http_response_head (sock); {
if (!head) head = read_http_response_head (sock);
{ if (!head)
if (errno == 0) {
{ if (errno == 0)
logputs (LOG_NOTQUIET, _("No data received.\n")); {
CLOSE_INVALIDATE (sock); logputs (LOG_NOTQUIET, _("No data received.\n"));
request_free (req); CLOSE_INVALIDATE (sock);
return HEOF; request_free (req);
} return HEOF;
else }
{ else
logprintf (LOG_NOTQUIET, _("Read error (%s) in headers.\n"), {
fd_errstr (sock)); logprintf (LOG_NOTQUIET, _("Read error (%s) in headers.\n"),
CLOSE_INVALIDATE (sock); fd_errstr (sock));
request_free (req); CLOSE_INVALIDATE (sock);
return HERR; request_free (req);
} return HERR;
} }
DEBUGP (("\n---response begin---\n%s---response end---\n", head)); }
DEBUGP (("\n---response begin---\n%s---response end---\n", head));
resp = resp_new (head); resp = resp_new (head);
/* Check for status line. */ /* Check for status line. */
message = NULL; message = NULL;
statcode = resp_status (resp, &message); statcode = resp_status (resp, &message);
if (statcode < 0) if (statcode < 0)
{ {
char *tms = datetime_str (time (NULL)); char *tms = datetime_str (time (NULL));
logprintf (LOG_VERBOSE, "%d\n", statcode); logprintf (LOG_VERBOSE, "%d\n", statcode);
logprintf (LOG_NOTQUIET, _("%s ERROR %d: %s.\n"), tms, statcode, logprintf (LOG_NOTQUIET, _("%s ERROR %d: %s.\n"), tms, statcode,
quotearg_style (escape_quoting_style, quotearg_style (escape_quoting_style,
_("Malformed status line"))); _("Malformed status line")));
CLOSE_INVALIDATE (sock); CLOSE_INVALIDATE (sock);
resp_free (resp); resp_free (resp);
request_free (req); request_free (req);
xfree (head); xfree (head);
return HERR; return HERR;
} }
if (H_10X (statcode)) if (H_10X (statcode))
{ {
DEBUGP (("Ignoring response\n")); xfree (head);
resp_free (resp); resp_free (resp);
xfree (head); _repeat = true;
goto read_header; DEBUGP (("Ignoring response\n"));
} }
else
{
_repeat = false;
}
}
while (_repeat);
}
xfree(hs->message); xfree(hs->message);
hs->message = xstrdup (message); hs->message = xstrdup (message);