Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sinatra middleware breaks downstream Rack::Builder apps #239

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

Sinatra middleware breaks downstream Rack::Builder apps #239

paulhammond opened this issue Apr 11, 2011 · 2 comments
Assignees
Labels

Comments

@paulhammond
Copy link

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'].

@rkh
Copy link
Member

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.

@ghost ghost assigned rkh Apr 12, 2011
@rkh rkh closed this as completed in c7601fc Apr 14, 2011
@paulhammond
Copy link
Author

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

sefton-ntech pushed a commit to sefton-ntech/sinatra that referenced this issue Apr 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants