Sinatra middleware breaks downstream Rack::Builder apps #239

Closed
paulhammond opened this Issue Apr 11, 2011 · 2 comments

Comments

Projects
None yet
2 participants

Commit ef69971 introduced caching of the Sinatra request object. Unfortunately this has the side effect of breaking routing when you have a setup consisting of sinatra middleware -> rack::builder -> sinatra application. For example, assume the following two classes:

class MyMiddleware < Sinatra::Base
end

class MyApp < Sinatra::Base
  get "/foo" do
    "hello"
  end
end

If we have the following config.ru then a request to /test/foo works as expected:

builder = Rack::Builder.new do
  map "/test" do
    run MyApp
  end
end
run builder

However, if we introduce the middleware, then a request to /test/foo generates a 404:

builder = Rack::Builder.new do
  use MyMiddleware
  map "/test" do
    run MyApp
  end
end
run builder

This is because MyMiddleware creates a cached copy of the Sinatra request in env['sinatra.request'] with the PATH_INFO set to /test/foo. Rack builder modifies the PATH_INFO and SCRIPT_NAME before MyApp runs, but MyApp uses the cached information from env['sinatra.request'].

Owner

rkh commented Apr 12, 2011

Oh, wow, yeah, will write a test, fix and prep a bug fix release later today. Thanks for looking already into what's causing the issue.

rkh was assigned Apr 12, 2011

rkh closed this in c7601fc Apr 14, 2011

Thank you for the quick response, and for all your work on Sinatra. It's awesome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment