This is an automated email from the ASF dual-hosted git repository. zwoop pushed a commit to branch 7.1.x in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit 2fb61f6d304fda1d475e9dd283482349e218372c Author: Derek Dagit <der...@oath.com> AuthorDate: Fri Aug 18 15:14:24 2017 +0000 corrects HTTP status 0 to 302 on redirect (cherry picked from commit a4cae55139bb48432ba4e8b832118a0d05d2c3d6) --- proxy/http/HttpTransact.cc | 7 ++++++- .../headers/data/www.redirect0.test_get.txt | 2 ++ .../headers/domain-blacklist-30x.test.py | 19 +++++++++++++++---- tests/gold_tests/headers/redirect0_get.gold | 22 ++++++++++++++++++++++ 4 files changed, 45 insertions(+), 5 deletions(-) diff --git a/proxy/http/HttpTransact.cc b/proxy/http/HttpTransact.cc index b47cae7..acdda6f 100644 --- a/proxy/http/HttpTransact.cc +++ b/proxy/http/HttpTransact.cc @@ -773,7 +773,12 @@ HttpTransact::EndRemapRequest(State *s) error_body_type = "redirect#moved_temporarily"; break; default: - Warning("Invalid status code for redirect '%d'. Building a response for a temporary redirect.", s->http_return_code); + if (HTTP_STATUS_NONE == s->http_return_code) { + s->http_return_code = HTTP_STATUS_MOVED_TEMPORARILY; + Warning("Changed status code from '0' to '%d'.", s->http_return_code); + } else { + Warning("Using invalid status code for redirect '%d'. Building a response for a temporary redirect.", s->http_return_code); + } error_body_type = "redirect#moved_temporarily"; } build_error_response(s, s->http_return_code, "Redirect", error_body_type, nullptr); diff --git a/tests/gold_tests/headers/data/www.redirect0.test_get.txt b/tests/gold_tests/headers/data/www.redirect0.test_get.txt new file mode 100644 index 0000000..40fce98 --- /dev/null +++ b/tests/gold_tests/headers/data/www.redirect0.test_get.txt @@ -0,0 +1,2 @@ +GET http://www.redirect0.test/ HTTP/1.1 + diff --git a/tests/gold_tests/headers/domain-blacklist-30x.test.py b/tests/gold_tests/headers/domain-blacklist-30x.test.py index aef08d6..172ccf4 100644 --- a/tests/gold_tests/headers/domain-blacklist-30x.test.py +++ b/tests/gold_tests/headers/domain-blacklist-30x.test.py @@ -32,6 +32,7 @@ REDIRECT_301_HOST='www.redirect301.test' REDIRECT_302_HOST='www.redirect302.test' REDIRECT_307_HOST='www.redirect307.test' REDIRECT_308_HOST='www.redirect308.test' +REDIRECT_0_HOST='www.redirect0.test' PASSTHRU_HOST='www.passthrough.test' ts.Disk.records_config.update({ @@ -45,12 +46,13 @@ regex_map http://{0}/ http://{0}/ @plugin=header_rewrite.so @pparam=header_rewri regex_map http://{1}/ http://{1}/ @plugin=header_rewrite.so @pparam=header_rewrite_rules_302.conf regex_map http://{2}/ http://{2}/ @plugin=header_rewrite.so @pparam=header_rewrite_rules_307.conf regex_map http://{3}/ http://{3}/ @plugin=header_rewrite.so @pparam=header_rewrite_rules_308.conf -""".format(REDIRECT_301_HOST, REDIRECT_302_HOST, REDIRECT_307_HOST, REDIRECT_308_HOST) +regex_map http://{4}/ http://{4}/ @plugin=header_rewrite.so @pparam=header_rewrite_rules_0.conf +""".format(REDIRECT_301_HOST, REDIRECT_302_HOST, REDIRECT_307_HOST, REDIRECT_308_HOST, REDIRECT_0_HOST) ) -for x in (1,2,7,8): - ts.Disk.MakeConfigFile("header_rewrite_rules_30{0}.conf".format(x)).AddLine("""\ -set-redirect 30{0} "%<cque>" +for x in (0,301,302,307,308): + ts.Disk.MakeConfigFile("header_rewrite_rules_{0}.conf".format(x)).AddLine("""\ +set-redirect {0} "%<cque>" """.format(x)) Test.Setup.Copy(os.path.join(os.pardir,os.pardir,'tools','tcp_client.py')) @@ -93,6 +95,15 @@ redirect308tr.Processes.Default.TimeOut=5 # seconds redirect308tr.Processes.Default.ReturnCode=0 redirect308tr.Processes.Default.Streams.stdout="redirect308_get.gold" +redirect0tr=Test.AddTestRun("Test domain {0}".format(REDIRECT_0_HOST)) +redirect0tr.StillRunningBefore = ts +redirect0tr.StillRunningAfter = ts +redirect0tr.Processes.Default.Command="python tcp_client.py 127.0.0.1 {0} {1} | grep -v '^Date: '| grep -v '^Server: ATS/'".\ + format(ts.Variables.port, 'data/{0}_get.txt'.format(REDIRECT_0_HOST)) +redirect0tr.Processes.Default.TimeOut=5 # seconds +redirect0tr.Processes.Default.ReturnCode=0 +redirect0tr.Processes.Default.Streams.stdout="redirect0_get.gold" + passthroughtr=Test.AddTestRun("Test domain {0}".format(PASSTHRU_HOST)) passthroughtr.StillRunningBefore = ts passthroughtr.StillRunningAfter = ts diff --git a/tests/gold_tests/headers/redirect0_get.gold b/tests/gold_tests/headers/redirect0_get.gold new file mode 100644 index 0000000..b9e828d --- /dev/null +++ b/tests/gold_tests/headers/redirect0_get.gold @@ -0,0 +1,22 @@ +HTTP/1.1 302 Redirect +Connection: keep-alive +Cache-Control: no-store +Location: http://www.redirect0.test/ +Content-Type: text/html +Content-Language: en +Content-Length: 308 + +<HTML> +<HEAD> +<TITLE>Document Has Moved</TITLE> +</HEAD> + +<BODY BGCOLOR="white" FGCOLOR="black"> +<H1>Document Has Moved</H1> +<HR> + +<FONT FACE="Helvetica,Arial"><B> +Description: The document you requested has moved to a new location. The new location is "http://www.redirect0.test/". +</B></FONT> +<HR> +</BODY> -- To stop receiving notification emails like this one, please contact "commits@trafficserver.apache.org" <commits@trafficserver.apache.org>.