mirror of
https://github.com/moparisthebest/wget
synced 2024-07-03 16:38:41 -04:00
Make 504 Gateway Timeout non fatal
This commit is contained in:
parent
0c1bff841b
commit
c6ee033425
@ -1,3 +1,10 @@
|
|||||||
|
2014-11-19 Darshit Shah <darnir@gmail.com>
|
||||||
|
|
||||||
|
* exits.c (get_status_for_err): GATEWAYTIMEOUT is a Server Error and Wget's
|
||||||
|
exit code should reflect that
|
||||||
|
* wget.h: Add GATEWAYTIMEOUT as an error
|
||||||
|
* http.c (http_loop): Gateway timeout errors should be non-fatal
|
||||||
|
|
||||||
2014-11-19 Tim Ruehsen <tim.ruehsen@gmx.de>
|
2014-11-19 Tim Ruehsen <tim.ruehsen@gmx.de>
|
||||||
|
|
||||||
* openssl.c (ssl_check_certificate): Fix memory leak
|
* openssl.c (ssl_check_certificate): Fix memory leak
|
||||||
|
@ -56,7 +56,7 @@ get_status_for_err (uerr_t err)
|
|||||||
case FTPNSFOD: case FTPUNKNOWNTYPE: case FTPSRVERR:
|
case FTPNSFOD: case FTPUNKNOWNTYPE: case FTPSRVERR:
|
||||||
case FTPRETRINT: case FTPRESTFAIL: case FTPNOPASV:
|
case FTPRETRINT: case FTPRESTFAIL: case FTPNOPASV:
|
||||||
case CONTNOTSUPPORTED: case RANGEERR: case RETRBADPATTERN:
|
case CONTNOTSUPPORTED: case RANGEERR: case RETRBADPATTERN:
|
||||||
case PROXERR:
|
case PROXERR: case GATEWAYTIMEOUT:
|
||||||
return WGET_EXIT_SERVER_ERROR;
|
return WGET_EXIT_SERVER_ERROR;
|
||||||
case URLERROR: case QUOTEXC: case SSLINITFAILED: case UNKNOWNATTR:
|
case URLERROR: case QUOTEXC: case SSLINITFAILED: case UNKNOWNATTR:
|
||||||
default:
|
default:
|
||||||
|
21
src/http.c
21
src/http.c
@ -130,6 +130,7 @@ static struct cookie_jar *wget_cookie_jar;
|
|||||||
#define HTTP_STATUS_NOT_IMPLEMENTED 501
|
#define HTTP_STATUS_NOT_IMPLEMENTED 501
|
||||||
#define HTTP_STATUS_BAD_GATEWAY 502
|
#define HTTP_STATUS_BAD_GATEWAY 502
|
||||||
#define HTTP_STATUS_UNAVAILABLE 503
|
#define HTTP_STATUS_UNAVAILABLE 503
|
||||||
|
#define HTTP_STATUS_GATEWAY_TIMEOUT 504
|
||||||
|
|
||||||
enum rp {
|
enum rp {
|
||||||
rel_none, rel_name, rel_value, rel_both
|
rel_none, rel_name, rel_value, rel_both
|
||||||
@ -2461,6 +2462,24 @@ read_header:
|
|||||||
pconn.authorized = true;
|
pconn.authorized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (statcode == HTTP_STATUS_GATEWAY_TIMEOUT)
|
||||||
|
{
|
||||||
|
hs->len = 0;
|
||||||
|
hs->res = 0;
|
||||||
|
hs->restval = 0;
|
||||||
|
|
||||||
|
CLOSE_FINISH (sock);
|
||||||
|
request_free (req);
|
||||||
|
xfree (hs->message);
|
||||||
|
hs->message = NULL;
|
||||||
|
xfree_null (message);
|
||||||
|
resp_free (resp);
|
||||||
|
xfree (head);
|
||||||
|
|
||||||
|
return GATEWAYTIMEOUT;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Determine the local filename if needed. Notice that if -O is used
|
/* Determine the local filename if needed. Notice that if -O is used
|
||||||
* hstat.local_file is set by http_loop to the argument of -O. */
|
* hstat.local_file is set by http_loop to the argument of -O. */
|
||||||
if (!hs->local_file)
|
if (!hs->local_file)
|
||||||
@ -3184,7 +3203,7 @@ Spider mode enabled. Check if remote file exists.\n"));
|
|||||||
{
|
{
|
||||||
case HERR: case HEOF: case CONSOCKERR:
|
case HERR: case HEOF: case CONSOCKERR:
|
||||||
case CONERROR: case READERR: case WRITEFAILED:
|
case CONERROR: case READERR: case WRITEFAILED:
|
||||||
case RANGEERR: case FOPEN_EXCL_ERR:
|
case RANGEERR: case FOPEN_EXCL_ERR: case GATEWAYTIMEOUT:
|
||||||
/* Non-fatal errors continue executing the loop, which will
|
/* Non-fatal errors continue executing the loop, which will
|
||||||
bring them to "while" statement at the end, to judge
|
bring them to "while" statement at the end, to judge
|
||||||
whether the number of tries was exceeded. */
|
whether the number of tries was exceeded. */
|
||||||
|
@ -337,7 +337,7 @@ typedef enum
|
|||||||
FTPOK, FTPLOGINC, FTPLOGREFUSED, FTPPORTERR, FTPSYSERR,
|
FTPOK, FTPLOGINC, FTPLOGREFUSED, FTPPORTERR, FTPSYSERR,
|
||||||
FTPNSFOD, FTPUNKNOWNTYPE, FTPRERR,
|
FTPNSFOD, FTPUNKNOWNTYPE, FTPRERR,
|
||||||
FTPSRVERR, FTPRETRINT, FTPRESTFAIL, URLERROR, FOPENERR,
|
FTPSRVERR, FTPRETRINT, FTPRESTFAIL, URLERROR, FOPENERR,
|
||||||
FOPEN_EXCL_ERR, FWRITEERR, HEOF,
|
FOPEN_EXCL_ERR, FWRITEERR, HEOF, GATEWAYTIMEOUT,
|
||||||
HERR, RETROK, RECLEVELEXC, WRONGCODE,
|
HERR, RETROK, RECLEVELEXC, WRONGCODE,
|
||||||
FTPINVPASV, FTPNOPASV, CONTNOTSUPPORTED, RETRUNNEEDED, RETRFINISHED,
|
FTPINVPASV, FTPNOPASV, CONTNOTSUPPORTED, RETRUNNEEDED, RETRFINISHED,
|
||||||
READERR, TRYLIMEXC, FILEBADFILE, RANGEERR,
|
READERR, TRYLIMEXC, FILEBADFILE, RANGEERR,
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
2014-11-19 Darshit Shah <darnir@gmail.com>
|
||||||
|
|
||||||
|
* Test-504.py: Add new test case to show how Wget handles 504 Gateway
|
||||||
|
Timeouts
|
||||||
|
* Makefile.am: Add Test-504.py to TESTS
|
||||||
|
|
||||||
2014-11-17 Tim Ruehsen <tim.ruehsen@gmx.de>
|
2014-11-17 Tim Ruehsen <tim.ruehsen@gmx.de>
|
||||||
|
|
||||||
* server/http/http_server.py: allow case-insensitive auth-type,
|
* server/http/http_server.py: allow case-insensitive auth-type,
|
||||||
|
@ -50,6 +50,7 @@ if HAVE_PYTHON3
|
|||||||
Test--https-crl.py \
|
Test--https-crl.py \
|
||||||
Test-O.py \
|
Test-O.py \
|
||||||
Test-Post.py \
|
Test-Post.py \
|
||||||
|
Test-504.py \
|
||||||
Test--spider-r.py
|
Test--spider-r.py
|
||||||
|
|
||||||
XFAIL_TESTS = Test-auth-both.py
|
XFAIL_TESTS = Test-auth-both.py
|
||||||
|
72
testenv/Test-504.py
Executable file
72
testenv/Test-504.py
Executable file
@ -0,0 +1,72 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
from sys import exit
|
||||||
|
from test.http_test import HTTPTest
|
||||||
|
from misc.wget_file import WgetFile
|
||||||
|
|
||||||
|
"""
|
||||||
|
This test ensures that Wget handles a 504 Gateway Timeout response
|
||||||
|
correctly.
|
||||||
|
Since, we do not have a direct mechanism for conditionally sending responses
|
||||||
|
via the HTTP Server, I've used a workaround.
|
||||||
|
The server will always respond to a request for File1 with a 504 Gateway
|
||||||
|
Timeout. Using the --tries=2 option, we ensure that Wget attempts the file
|
||||||
|
only twice and then move on to the next file. Finally, check the exact
|
||||||
|
requests that the Server received and compare them, in order, to the
|
||||||
|
expected sequence of requests.
|
||||||
|
|
||||||
|
In this case, we expect Wget to attempt File1 twice and File2 once. If Wget
|
||||||
|
considered 504 as a general Server Error, it would be a fatal failure and
|
||||||
|
Wget would request File1 only once.
|
||||||
|
"""
|
||||||
|
TEST_NAME = "504 Gateway Timeouts"
|
||||||
|
############# File Definitions ###############################################
|
||||||
|
File1 = """All happy families are alike;
|
||||||
|
Each unhappy family is unhappy in its own way"""
|
||||||
|
File2 = "Anyone for chocochip cookies?"
|
||||||
|
|
||||||
|
File1_rules = {
|
||||||
|
"Response" : 504
|
||||||
|
}
|
||||||
|
|
||||||
|
A_File = WgetFile ("File1", File1, rules=File1_rules)
|
||||||
|
B_File = WgetFile ("File2", File2)
|
||||||
|
|
||||||
|
Request_List = [
|
||||||
|
[
|
||||||
|
"GET /File1",
|
||||||
|
"GET /File1",
|
||||||
|
"GET /File2",
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
WGET_OPTIONS = "--tries=2"
|
||||||
|
WGET_URLS = [["File1", "File2"]]
|
||||||
|
|
||||||
|
Files = [[A_File, B_File]]
|
||||||
|
|
||||||
|
ExpectedReturnCode = 4
|
||||||
|
ExpectedDownloadedFiles = [B_File]
|
||||||
|
|
||||||
|
################ Pre and Post Test Hooks #####################################
|
||||||
|
pre_test = {
|
||||||
|
"ServerFiles" : Files
|
||||||
|
}
|
||||||
|
test_options = {
|
||||||
|
"WgetCommands" : WGET_OPTIONS,
|
||||||
|
"Urls" : WGET_URLS
|
||||||
|
}
|
||||||
|
post_test = {
|
||||||
|
"ExpectedFiles" : ExpectedDownloadedFiles,
|
||||||
|
"ExpectedRetcode" : ExpectedReturnCode,
|
||||||
|
"FilesCrawled" : Request_List
|
||||||
|
}
|
||||||
|
|
||||||
|
err = HTTPTest (
|
||||||
|
name=TEST_NAME,
|
||||||
|
pre_hook=pre_test,
|
||||||
|
test_params=test_options,
|
||||||
|
post_hook=post_test
|
||||||
|
).begin ()
|
||||||
|
|
||||||
|
exit (err)
|
Loading…
Reference in New Issue
Block a user