Merge pull request #12256 from ianton-ru/redirect_limit_exception

throw exception on redirect limit in S3 request
This commit is contained in:
alesapin 2020-07-08 10:33:42 +03:00 committed by GitHub
commit f04a49a114
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 2 deletions

View File

@ -14,6 +14,11 @@
#include <Poco/Net/HTTPResponse.h>
#include <common/logger_useful.h>
namespace DB::ErrorCodes
{
extern const int TOO_MANY_REDIRECTS;
}
namespace DB::S3
{
PocoHTTPClient::PocoHTTPClient(const Aws::Client::ClientConfiguration & clientConfiguration)
@ -153,8 +158,10 @@ void PocoHTTPClient::MakeRequestInternal(
else
response->GetResponseStream().SetUnderlyingStream(std::make_shared<PocoHTTPResponseStream>(session, response_body_stream));
break;
return;
}
throw Exception(String("Too many redirects while trying to access ") + request.GetUri().GetURIString(),
ErrorCodes::TOO_MANY_REDIRECTS);
}
catch (...)
{

View File

@ -1,4 +1,11 @@
from bottle import abort, route, run, request
from bottle import abort, route, run, request, response
@route('/redirected/<_path>')
def infinite_redirect(_path):
response.set_header("Location", request.url)
response.status = 307
return 'Redirected'
@route('/<_bucket>/<_path>')

View File

@ -336,3 +336,19 @@ def test_get_csv_default(cluster):
instance = cluster.instances["dummy"] # type: ClickHouseInstance
result = run_query(instance, get_query)
assert result == '1\t2\t3\n'
def test_infinite_redirect(cluster):
bucket = "redirected"
table_format = "column1 UInt32, column2 UInt32, column3 UInt32"
filename = "test.csv"
get_query = "select * from s3('http://resolver:8080/{bucket}/{file}', 'CSV', '{table_format}')".format(
bucket="redirected",
file=filename,
table_format=table_format)
instance = cluster.instances["dummy"] # type: ClickHouseInstance
try:
result = run_query(instance, get_query)
except Exception as e:
assert str(e).find("Too many redirects while trying to access") != -1