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:
parent
52a7d0ad85
commit
621c313b94
101
src/http.c
101
src/http.c
@ -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. */
|
||||
}
|
||||
|
||||
/* Repeat while we receive a 10x response code. */
|
||||
{
|
||||
bool _repeat;
|
||||
|
||||
read_header:
|
||||
head = read_http_response_head (sock);
|
||||
if (!head)
|
||||
{
|
||||
if (errno == 0)
|
||||
{
|
||||
logputs (LOG_NOTQUIET, _("No data received.\n"));
|
||||
CLOSE_INVALIDATE (sock);
|
||||
request_free (req);
|
||||
return HEOF;
|
||||
}
|
||||
else
|
||||
{
|
||||
logprintf (LOG_NOTQUIET, _("Read error (%s) in headers.\n"),
|
||||
fd_errstr (sock));
|
||||
CLOSE_INVALIDATE (sock);
|
||||
request_free (req);
|
||||
return HERR;
|
||||
}
|
||||
}
|
||||
DEBUGP (("\n---response begin---\n%s---response end---\n", head));
|
||||
do
|
||||
{
|
||||
head = read_http_response_head (sock);
|
||||
if (!head)
|
||||
{
|
||||
if (errno == 0)
|
||||
{
|
||||
logputs (LOG_NOTQUIET, _("No data received.\n"));
|
||||
CLOSE_INVALIDATE (sock);
|
||||
request_free (req);
|
||||
return HEOF;
|
||||
}
|
||||
else
|
||||
{
|
||||
logprintf (LOG_NOTQUIET, _("Read error (%s) in headers.\n"),
|
||||
fd_errstr (sock));
|
||||
CLOSE_INVALIDATE (sock);
|
||||
request_free (req);
|
||||
return HERR;
|
||||
}
|
||||
}
|
||||
DEBUGP (("\n---response begin---\n%s---response end---\n", head));
|
||||
|
||||
resp = resp_new (head);
|
||||
resp = resp_new (head);
|
||||
|
||||
/* Check for status line. */
|
||||
message = NULL;
|
||||
statcode = resp_status (resp, &message);
|
||||
if (statcode < 0)
|
||||
{
|
||||
char *tms = datetime_str (time (NULL));
|
||||
logprintf (LOG_VERBOSE, "%d\n", statcode);
|
||||
logprintf (LOG_NOTQUIET, _("%s ERROR %d: %s.\n"), tms, statcode,
|
||||
quotearg_style (escape_quoting_style,
|
||||
_("Malformed status line")));
|
||||
CLOSE_INVALIDATE (sock);
|
||||
resp_free (resp);
|
||||
request_free (req);
|
||||
xfree (head);
|
||||
return HERR;
|
||||
}
|
||||
/* Check for status line. */
|
||||
message = NULL;
|
||||
statcode = resp_status (resp, &message);
|
||||
if (statcode < 0)
|
||||
{
|
||||
char *tms = datetime_str (time (NULL));
|
||||
logprintf (LOG_VERBOSE, "%d\n", statcode);
|
||||
logprintf (LOG_NOTQUIET, _("%s ERROR %d: %s.\n"), tms, statcode,
|
||||
quotearg_style (escape_quoting_style,
|
||||
_("Malformed status line")));
|
||||
CLOSE_INVALIDATE (sock);
|
||||
resp_free (resp);
|
||||
request_free (req);
|
||||
xfree (head);
|
||||
return HERR;
|
||||
}
|
||||
|
||||
if (H_10X (statcode))
|
||||
{
|
||||
DEBUGP (("Ignoring response\n"));
|
||||
resp_free (resp);
|
||||
xfree (head);
|
||||
goto read_header;
|
||||
}
|
||||
if (H_10X (statcode))
|
||||
{
|
||||
xfree (head);
|
||||
resp_free (resp);
|
||||
_repeat = true;
|
||||
DEBUGP (("Ignoring response\n"));
|
||||
}
|
||||
else
|
||||
{
|
||||
_repeat = false;
|
||||
}
|
||||
}
|
||||
while (_repeat);
|
||||
}
|
||||
|
||||
xfree(hs->message);
|
||||
hs->message = xstrdup (message);
|
||||
|
Loading…
Reference in New Issue
Block a user