1
0
mirror of https://github.com/mirror/wget.git synced 2025-04-14 21:40:42 +08:00

Add new test for 416 responses

* testenv/server/http/http_server.py: If there are multiple requests in
which the requested range is unsatisfiable, then send a body in the in
the 2nd response onwards
* testenv/Test-416.py: New test to check how Wget handles 416 responses
This commit is contained in:
Darshit Shah 2017-12-08 18:41:07 +01:00
parent 693cee0109
commit 3d2b2231cd
3 changed files with 62 additions and 0 deletions

View File

@ -73,6 +73,7 @@ endif
if HAVE_PYTHON3
TESTS = Test-504.py \
Test-416.py \
Test-auth-basic-fail.py \
Test-auth-basic.py \
Test-auth-basic-netrc.py \

53
testenv/Test-416.py Executable file
View File

@ -0,0 +1,53 @@
#!/usr/bin/env python3
from sys import exit
from test.http_test import HTTPTest
from misc.wget_file import WgetFile
"""
Ensure that Wget behaves well when the server responds with a HTTP 416
status code. This test checks both cases:
1. Server sends no body
2. Server sends a body
"""
############# File Definitions ###############################################
File1 = "abababababababababababababababababababababababababababababababababab"
File2 = "ababababababababababababababababababab"
A_File = WgetFile ("File1", File1)
B_File = WgetFile ("File1", File1)
C_File = WgetFile ("File2", File2)
D_File = WgetFile ("File2", File1)
E_File = WgetFile ("File3", File1)
WGET_OPTIONS = "-c"
WGET_URLS = [["File1", "File2", "File3"]]
Files = [[A_File, C_File, E_File]]
Existing_Files = [B_File, D_File]
ExpectedReturnCode = 0
ExpectedDownloadedFiles = [B_File, D_File, E_File]
################ Pre and Post Test Hooks #####################################
pre_test = {
"ServerFiles" : Files,
"LocalFiles" : Existing_Files
}
test_options = {
"WgetCommands" : WGET_OPTIONS,
"Urls" : WGET_URLS
}
post_test = {
"ExpectedFiles" : ExpectedDownloadedFiles,
"ExpectedRetcode" : ExpectedReturnCode
}
err = HTTPTest (
pre_hook=pre_test,
test_params=test_options,
post_hook=post_test
).begin ()
exit (err)

View File

@ -425,8 +425,16 @@ class _Handler(BaseHTTPRequestHandler):
except ServerError as ae:
# self.log_error("%s", ae.err_message)
if ae.err_message == "Range Overflow":
try:
self.overflows += 1
except AttributeError as s:
self.overflows = 0
self.send_response(416)
if self.overflows > 0:
self.add_header("Content-Length", 17)
self.finish_headers()
if self.overflows > 0:
return("Range Unsatisfied", 0)
return(None, None)
else:
self.range_begin = None