mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-20 16:50:48 +00:00
Merge pull request #23844 from excitoon-favorites/s3morecorrectclient
Better handling of HTTP errors in `PocoHTTPClient`
This commit is contained in:
commit
d340e33e2b
@ -289,28 +289,15 @@ void PocoHTTPClient::makeRequestInternal(
|
|||||||
}
|
}
|
||||||
LOG_DEBUG(log, "Received headers: {}", headers_ss.str());
|
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)
|
if (status_code == 429 || status_code == 503)
|
||||||
{ // API throttling
|
{ // API throttling
|
||||||
ProfileEvents::increment(select_metric(S3MetricType::Throttling));
|
ProfileEvents::increment(select_metric(S3MetricType::Throttling));
|
||||||
}
|
}
|
||||||
else
|
else if (status_code >= 300)
|
||||||
{
|
{
|
||||||
ProfileEvents::increment(select_metric(S3MetricType::Errors));
|
ProfileEvents::increment(select_metric(S3MetricType::Errors));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
response->SetResponseBody(response_body_stream, session);
|
response->SetResponseBody(response_body_stream, session);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -34,7 +34,8 @@ def server(_bucket, _path):
|
|||||||
cache['request_number'] = request_number
|
cache['request_number'] = request_number
|
||||||
else:
|
else:
|
||||||
response.status = 500
|
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.set_header("Location", "http://minio1:9001/" + _bucket + '/' + _path)
|
||||||
response.status = 307
|
response.status = 307
|
||||||
|
@ -15,7 +15,9 @@ def server(_bucket, _path):
|
|||||||
for name in request.headers:
|
for name in request.headers:
|
||||||
if name == 'Authorization' and request.headers[name] == 'Bearer TOKEN':
|
if name == 'Authorization' and request.headers[name] == 'Bearer TOKEN':
|
||||||
return '1, 2, 3'
|
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('/')
|
@route('/')
|
||||||
|
@ -504,7 +504,7 @@ def test_custom_auth_headers_exclusion(cluster):
|
|||||||
print(result)
|
print(result)
|
||||||
|
|
||||||
assert ei.value.returncode == 243
|
assert ei.value.returncode == 243
|
||||||
assert '403 Forbidden' in ei.value.stderr
|
assert 'Forbidden Error' in ei.value.stderr
|
||||||
|
|
||||||
|
|
||||||
def test_infinite_redirect(cluster):
|
def test_infinite_redirect(cluster):
|
||||||
|
Loading…
Reference in New Issue
Block a user