Merge pull request #23844 from excitoon-favorites/s3morecorrectclient

Better handling of HTTP errors in `PocoHTTPClient`
This commit is contained in:
alexey-milovidov 2021-05-13 19:21:09 +03:00 committed by GitHub
commit d340e33e2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 25 deletions

View File

@ -289,29 +289,16 @@ void PocoHTTPClient::makeRequestInternal(
}
LOG_DEBUG(log, "Received headers: {}", headers_ss.str());
if (status_code >= 300)
{
String error_message;
Poco::StreamCopier::copyToString(response_body_stream, error_message);
if (Aws::Http::IsRetryableHttpResponseCode(response->GetResponseCode()))
response->SetClientErrorType(Aws::Client::CoreErrors::NETWORK_CONNECTION);
else
response->SetClientErrorType(Aws::Client::CoreErrors::USER_CANCELLED);
response->SetClientErrorMessage(error_message);
if (status_code == 429 || status_code == 503)
{ // API throttling
ProfileEvents::increment(select_metric(S3MetricType::Throttling));
}
else
{
ProfileEvents::increment(select_metric(S3MetricType::Errors));
}
if (status_code == 429 || status_code == 503)
{ // API throttling
ProfileEvents::increment(select_metric(S3MetricType::Throttling));
}
else
response->SetResponseBody(response_body_stream, session);
else if (status_code >= 300)
{
ProfileEvents::increment(select_metric(S3MetricType::Errors));
}
response->SetResponseBody(response_body_stream, session);
return;
}

View File

@ -34,7 +34,8 @@ def server(_bucket, _path):
cache['request_number'] = request_number
else:
response.status = 500
return 'Expected Error'
response.content_type = 'text/xml'
return '<?xml version="1.0" encoding="UTF-8"?><Error><Code>ExpectedError</Code><Message>Expected Error</Message><RequestId>txfbd566d03042474888193-00608d7537</RequestId></Error>'
response.set_header("Location", "http://minio1:9001/" + _bucket + '/' + _path)
response.status = 307

View File

@ -15,7 +15,9 @@ def server(_bucket, _path):
for name in request.headers:
if name == 'Authorization' and request.headers[name] == 'Bearer TOKEN':
return '1, 2, 3'
abort(403)
response.status = 403
response.content_type = 'text/xml'
return '<?xml version="1.0" encoding="UTF-8"?><Error><Code>ForbiddenError</Code><Message>Forbidden Error</Message><RequestId>txfbd566d03042474888193-00608d7537</RequestId></Error>'
@route('/')

View File

@ -504,7 +504,7 @@ def test_custom_auth_headers_exclusion(cluster):
print(result)
assert ei.value.returncode == 243
assert '403 Forbidden' in ei.value.stderr
assert 'Forbidden Error' in ei.value.stderr
def test_infinite_redirect(cluster):