Skip to content

Commit

Permalink
Merge pull request #595 from voxmedia/from-v5.2.1-change-599-to-retur…
Browse files Browse the repository at this point in the history
…n-504

Return a 504 (instead of 404) for 599 timeout (for caching/CDN)
  • Loading branch information
masom committed Nov 6, 2015
2 parents da7c374 + 0e91f2a commit 6885b88
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions thumbor/handlers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ def get_image(self):
# Return a Bad Gateway status if the error came from upstream
self._error(502)
return
elif result.loader_error == LoaderResult.ERROR_TIMEOUT:
# Return a Gateway Timeout status if upstream timed out (i.e. 599)
self._error(504)
return
else:
self._error(500)
return
Expand Down
1 change: 1 addition & 0 deletions thumbor/loaders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class LoaderResult(object):

ERROR_NOT_FOUND = 'not_found'
ERROR_UPSTREAM = 'upstream'
ERROR_TIMEOUT = 'timeout'

def __init__(self, buffer=None, successful=True, error=None, metadata=dict()):
'''
Expand Down
6 changes: 5 additions & 1 deletion thumbor/loaders/http_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ def return_contents(response, url, callback, context):
context.metrics.incr('original_image.status.' + str(response.code))
if response.error:
result.successful = False
result.error = LoaderResult.ERROR_NOT_FOUND
if response.code == 599:
# Return a Gateway Timeout status downstream if upstream times out
result.error = LoaderResult.ERROR_TIMEOUT
else:
result.error = LoaderResult.ERROR_NOT_FOUND

logger.warn("ERROR retrieving image {0}: {1}".format(url, str(response.error)))

Expand Down

0 comments on commit 6885b88

Please sign in to comment.