diff --git a/Readme.md b/Readme.md index db6dcb3..b7c5c6a 100644 --- a/Readme.md +++ b/Readme.md @@ -44,8 +44,7 @@ HMAC result is truncated to 12 bytes, producing a 16 characters encoded signatur `ext_url` is the result of `urlsafe-base64(image_url)`. Trailing `=` may be stripped. `extension` is either the empty string or the string `/proxy` which instructs -the imageproxy server to not permanently store the source image. Resizing is -not supported in proxy-only mode. +the imageproxy server to not permanently store the source image. ## Signature test vector diff --git a/main.py b/main.py index b8e93a9..1b22efd 100644 --- a/main.py +++ b/main.py @@ -145,15 +145,16 @@ async def handle_signed_request(request: Request) -> Response: is_proxy = len(url) == 4 and url[3] == 'proxy' try: - imgproxy_opts = [] if is_proxy else parse_imgproxy_params(url[0]) + imgproxy_opts = parse_imgproxy_params(url[0]) except BadOptions: logger.debug("invalid resize options: %s", url[0]) return bad_request() is_resize = bool(imgproxy_opts) + if not is_proxy: + imgproxy_opts.append(b'fn:' + img_url) img_path = create_filename(bucket, img_url) - imgproxy_opts.append(b'fn:' + img_url) # download and perma-store image through imgproxy base_path = request.get_first_header(b'root_dir').decode('ascii') diff --git a/nginx/imgproxy.conf b/nginx/imgproxy.conf index 8eff8ad..a0d6f0a 100644 --- a/nginx/imgproxy.conf +++ b/nginx/imgproxy.conf @@ -53,15 +53,16 @@ server { set $img_url $upstream_http_imgproxy_url; add_header Content-Type ""; add_header x-original-url $upstream_http_x_original_url; - rewrite .* /$loc_prefix/${imgproxy_opts}plain/local:///${img_path}; + rewrite .* /${loc_prefix}/${imgproxy_opts}plain/local:///${img_path}; } location @serve-imgproxy-remote { # for non-cached images + set $imgproxy_opts $imgproxy_opts/$upstream_http_imgproxy_opts; set $img_url $upstream_http_imgproxy_url; add_header Content-Type ""; add_header x-original-url $upstream_http_x_original_url; - rewrite .* /$loc_prefix/${img_url}; + rewrite .* /${loc_prefix}/${imgproxy_opts}/${img_url}; } location @serve-proxy {