rack/rack-contrib — pull request #75 by DWvanGeest (2013-08-22 21:48:59+00:00)
Title: TryStatic should treat HTTP 405 as an error

Rack::TryStatic calls Rack::Static, which calls Rack::File. Rack::File returns an HTTP 405 if the HTTP method is something other than GET or HEAD (https://github.com/rack/rack/blob/master/lib/rack/file.rb#L38). The 405 gets returned up the stack to TryStatic.

However, TryStatic only looks for 404 as an error, not 405. So it thinks the static request has succeeded and does not proceed to call the app.

So, if you attempt to POST, PUT, DELETE, etc. with TryStatic in your middleware stack, it will always fail with HTTP 405.

This PR changes TryStatic to look for HTTP 405 as well, and treat it the same way as HTTP 404 (i.e. pass the request to the app).

I can't get the tests for this gem to run, so I have not run them or added a test for this case. I would like to have test coverage, but digging into the testing is not the best use of my time right now. The modified gem works as expected in my app.