Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace CurlError with HTTPClientError #1572

Merged
merged 2 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 34 additions & 0 deletions tests/loaders/test_http_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,19 @@ async def test_load_with_callback(self):
expect(result.buffer).to_equal("Hello")
expect(result.successful).to_be_true()

@gen_test
async def test_load_not_found(self):
url = self.get_url("/not-found.jpg")
config = Config()
config.HTTP_LOADER_CURL_ASYNC_HTTP_CLIENT = False
ctx = Context(None, config, None)

result = await loader.load(ctx, url)
expect(result).to_be_instance_of(LoaderResult)
expect(result.buffer).to_be_null()
expect(result.successful).to_be_false()
expect(result.error).to_equal(LoaderResult.ERROR_NOT_FOUND)

@gen_test
async def test_load_with_utf8_url(self):
url = self.get_url(quote("/maracujá.jpg".encode("utf-8")))
Expand Down Expand Up @@ -338,6 +351,27 @@ async def test_load_with_default_user_agent(self):
expect(result.buffer).to_equal("DEFAULT_USER_AGENT")


class HttpCurlNotFoundLoaderTestCase(DummyAsyncHttpClientTestCase):
def get_app(self):
application = tornado.web.Application([(r"/", TimeoutHandler)])

return application

@gen_test
async def test_load_not_found(self):
url = self.get_url("/not-found.jpg")
config = Config()
config.HTTP_LOADER_CURL_ASYNC_HTTP_CLIENT = True
config.HTTP_LOADER_REQUEST_TIMEOUT = 1
ctx = Context(None, config, None)

result = await loader.load(ctx, url)
expect(result).to_be_instance_of(LoaderResult)
expect(result.buffer).to_be_null()
expect(result.successful).to_be_false()
expect(result.error).to_equal(LoaderResult.ERROR_NOT_FOUND)


class HttpCurlTimeoutLoaderTestCase(DummyAsyncHttpClientTestCase):
def get_app(self):
application = tornado.web.Application([(r"/", TimeoutHandler)])
Expand Down
4 changes: 1 addition & 3 deletions thumbor/loaders/http_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,9 @@ async def load(
"tornado.curl_httpclient.CurlAsyncHTTPClient"
)
prepare_curl_callback = _get_prepare_curl_callback(context.config)
exc_type = tornado.curl_httpclient.CurlError
else:
http_client_implementation = None # default
prepare_curl_callback = None
exc_type = tornado.httpclient.HTTPClientError

tornado.httpclient.AsyncHTTPClient.configure(
http_client_implementation,
Expand Down Expand Up @@ -200,7 +198,7 @@ async def load(
start = datetime.datetime.now()
try:
response = await client.fetch(req, raise_error=True)
except exc_type as err:
except tornado.httpclient.HTTPClientError as err:
response = tornado.httpclient.HTTPResponse(
req, err.code, reason=err.message, start_time=start
)
Expand Down