From b6b6500a852d437ec52c8e49a600511723f32ab4 Mon Sep 17 00:00:00 2001 From: Hubert Tarasiuk Date: Fri, 27 Mar 2015 15:35:57 +0100 Subject: [PATCH 2/2] Transform read_header label and goto into a loop * src/http.c (gethttp): Replace label and goto statement with a do loop. --- src/http.c | 101 ++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 56 insertions(+), 45 deletions(-) diff --git a/src/http.c b/src/http.c index a127733..69c5cf5 100644 --- a/src/http.c +++ b/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); -- 2.3.4