def test_is_five_prime(self): expected = ( r"/fit-in/650x650/raw" r"/4fff89be6cca5cf00afe8062a54796fa.jpg" ) self.assertEqual( match_patterns("/b/4fff89be6cca5cf00afe8062a54796fa-zoom.jpg"), expected )
def test_is_five_prime(self): with self.env: expected = ( r"/fit-in/650x650/raw" r"/4fff89be6cca5cf00afe8062a54796fa.jpg" ) self.assertEqual( match_patterns("/b/4fff89be6cca5cf00afe8062a54796fa-zoom.jpg"), expected )
def call_thumbor(request): if not os.path.exists(thumbor_socket): start_server() session = requests_unixsocket.Session() unix_path = 'http+unix://%2Ftmp%2Fthumbor' http_health = '/healthcheck' retries = 10 while (retries > 0): try: response = session.get(unix_path + http_health) if (response.status_code == 200): break except Exception as error: time.sleep(0.03) retries -= 1 continue if retries <= 0: logging.error('call_thumbor error: tornado server unavailable,\ proceeding with tornado server restart') restart_server() return response_formater(status_code='502') http_path = request['path'] if str(os.environ.get('REWRITE_ENABLED')).upper() == 'YES': http_path = lambda_rewrite.match_patterns(http_path) if config.ALLOW_UNSAFE_URL: http_path = '/unsafe' + http_path else: http_path = http_path response = session.get(unix_path + http_path) if response.status_code != 200: return response_formater(status_code=response.status_code) content_type = response.headers['content-type'] body = gen_body(content_type, response.content) if body is None: return response_formater(status_code='500', cache_control='no-cache,no-store') return response_formater(status_code='200', body=body, cache_control=response.headers['Cache-Control'], content_type=content_type, expires=response.headers['Expires'], etag=response.headers['Etag'], date=response.headers['Date'])
def rewrite(http_path): if str(os.environ.get('REWRITE_ENABLED')).upper() == 'YES': http_path = lambda_rewrite.match_patterns(http_path) return http_path
def rewrite(http_path): if str(os.environ.get('REWRITE_ENABLED')).upper() == 'YES': http_path = lambda_rewrite.match_patterns(http_path) return http_path