<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class="">I have encountered a bug in ngx_http_image_filter_module when used in conjunction with ngx_http_proxy_module ; the configuration is as following:</div><div class=""><br class=""></div><div class="">location /img/ {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>proxy_pass <a href="http://mybucket.s3.amazonaws.com" class="">http://mybucket.s3.amazonaws.com</a>;</div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>image_filter resize 150 100;</div><div class="">}</div><div class=""><br class=""></div><div class="">The steps to reproduce are rather complicated as they depend on how TCP fragments the response coming from the proxy:</div><div class=""><br class=""></div><div class="">- If <a href="http://mybucket.s3.amazonaws.com" class="">http://mybucket.s3.amazonaws.com</a> returns, in the first TCP packet, a sizable amount of data (1-2k), the image is resized correctly.</div><div class=""><br class=""></div><div class="">- If <a href="http://mybucket.s3.amazonaws.com" class="">http://mybucket.s3.amazonaws.com</a> returns, in the first TCP packet, a small amount of data (HTTP header, or HTTP header + a few bytes), the content is marked as not an image and NGX_HTTP_UNSUPPORTED_MEDIA_TYPE is returned (disconnecting the client), irrespective on whether or not subsequent data would complete the response to a valid image.</div><div class=""><br class=""></div><div class="">Nginx appears to give up right away on waiting for data if the contents of the first TCP packet received from the proxy does not contain a valid image header- i.e. ngx_http_image_test() will return NGX_HTTP_IMAGE_SIZE, etc.</div><div class=""><br class=""></div><div class="">In my experience this was triggered by a subtle change in AWS S3 that fragments the TCP header more.</div><div class=""><br class=""></div><div class="">Versions affected: 1.6.2, 1.6.3, 1.7.2, 1.8.0, etc.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Attaching a patch which fixes it for my use case (1.6.2) below; the other versions can be fixed similarly:</div><div class=""><br class=""></div><div class="">————————————————————————</div><div class="">diff -ruN nginx-1.6.2.orig/src/http/modules/ngx_http_image_filter_module.c nginx-1.6.2/src/http/modules/ngx_http_image_filter_module.c<br class="">--- nginx-1.6.2.orig/src/http/modules/ngx_http_image_filter_module.c<span class="Apple-tab-span" style="white-space:pre">      </span>2014-09-16 19:23:19.000000000 +0700<br class="">+++ nginx-1.6.2/src/http/modules/ngx_http_image_filter_module.c<span class="Apple-tab-span" style="white-space:pre">        </span>2015-04-28 16:25:47.000000000 +0700<br class="">@@ -317,9 +317,8 @@<br class="">                 }<br class="">             }<br class=""> <br class="">-            return ngx_http_filter_finalize_request(r,<br class="">-                                              &ngx_http_image_filter_module,<br class="">-                                              NGX_HTTP_UNSUPPORTED_MEDIA_TYPE);<br class="">+            /* wait to consume more data, do not give up on the request right away */<br class="">+            return NGX_OK;<br class="">         }<br class=""> <br class="">         /* override content type */<br class="">————————————————————————</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Thoughts ? Is this the right fix ? Should I also post on the nginx Trac ?</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Thank you,</div><div class="">Dan</div></body></html>