Rack provides a minimal, modular, and adaptable interface for developing web applications in Ruby.
Questions tagged [rack-middleware]
66 questions
6
votes
1 answer
What's the variable HTTP_X_FORWARDED_HOST in the @env hash in middleware?
In a Rack middleware filter, I know the call method takes an env hash variable. I'm looking through someone's Rack middleware code and I see
env['HTTP_X_FORWARDED_HOST']
Can someone explain what HTTP_X_FORWARDED_HOST means? Is it the host where…

User314159
- 7,733
- 9
- 39
- 63
5
votes
3 answers
Where to put Rack Middleware in Rails4.1
I looked at some of the answers 1] Include in qoutes, 2] Dont use require etc but neither of them works. Its possible the solution has changed in Rails4
I am trying to follow the tutorial here…

codeObserver
- 6,521
- 16
- 76
- 121
5
votes
2 answers
How to add rack middleware to rails app from gem
I am working on a event handler to report exceptions to a remote api (similar to newrelic agent) and I can not find a way to add my middleware to the rack without doing it in the environment.rb file.
I do not want to do it in the environment.rb…

Jessiah
- 1,464
- 2
- 9
- 9
4
votes
4 answers
How to access params variable in a middleware rails 5
I am having a problem working with middleware in rails 5, I am trying to manipulate the parameters sent in a POST http by using Rack::Request in a middleware, but the parameters sent are not ejected until the function @app.call(env) is called.
Using…

Miguel Rodriguez
- 41
- 1
- 8
4
votes
1 answer
Assets not working in isolated engine endpoint
I'm getting Not Found errors when trying to access assets inside an isolated engine mounted as an endpoint in a middleware. I'm trying to access the assets from within the engine, so they should be able to be found.
My suspicion is that asset…

Brendon Muir
- 4,540
- 2
- 33
- 55
4
votes
2 answers
How to Block Requests at the Rack Level?
When running a Rails4 app, I often see bots probing to see whether I'm running a Wordpress site. I expect that they are looking to either create comment spam or looking for Wordpress security vulnerabilities.
Here's an example error from the…

user1515295
- 1,181
- 11
- 28
4
votes
2 answers
Thread running in Middleware is using old version of parent's instance variable
I've used Heroku tutorial to implement websockets.
It works properly with Thin, but does not work with Unicorn and Puma.
Also there's an echo message implemented, which responds to client's message. It works properly on each server, so there are no…

Felix Borzik
- 1,230
- 12
- 19
4
votes
1 answer
Rails 4 multitencancy with subdomain login management
Scenario: Multi-tenant rails app that uses subdomains and devise
Problem: I want the user to be able to log into mydomain.com then be forwarded to their own subdomain1.mydomain.com address as a logged-in user. Right now they can only log directly…

mrc
- 101
- 5
3
votes
1 answer
What are my storage options when writing Rack middleware for Rails applications?
Assuming my Rack middleware is designed specifically for Rails applications, what storage options do I have? For instance, is there a way for me to read from / write to the Rails cache?

Kevin Pang
- 41,172
- 38
- 121
- 173
3
votes
1 answer
How to enable middlewares in integration tests for a rack-app?
When writing integration tests for a Rack app, I would like to test the app with all the middlewares that are enabled in runtime environment through classic config.ru file.
Using rack-app, I can instantiate the Rack app with:
describe App do
…

Qortex
- 7,087
- 3
- 42
- 59
3
votes
1 answer
How to authenticate users using devise in rails middleware?
config/application.rb
config.middleware.insert_before(Rack::Runtime, Rack::ReverseProxy) do
reverse_proxy_options preserve_host: false
reverse_proxy '/external/app', 'https://runalong.com:64167/app'
end
I'm using rack-reverse-proxy to forward…

Aravind Raju
- 61
- 1
- 5
3
votes
0 answers
Rails - render static html page from middleware
Yesterday my application was visited by yandex bot with an invalid URL
/restday?biG%D9%02
and for this application is throwing an error
ArgumentError: invalid byte sequence in UTF-8
I need to render 400.html static page with status 400 instead of…

anil.n
- 509
- 2
- 5
- 17
3
votes
0 answers
Are there benefits to ActionController::API unless our Rails app is exclusively an API?
I'm not 100% if my Rails app will always just be an API.
With that in mind, I have keep ActionController:
class ApplicationController < ActionController::Base
and opted to create an api controller,
class ApiController < ActionController::API.
Now, I…

David
- 7,028
- 10
- 48
- 95
3
votes
2 answers
What is ActiveSupport::Cache::Strategy::LocalCache used for?
In my production middleware stack in all environments I see this one-off instance:
use #
I've experimented by removing everything I can think of related to caching, but I'm unable…

John Bachir
- 22,495
- 29
- 154
- 227
3
votes
1 answer
Why does rspec-rails skip the middleware?
I have a Rails app (3.2.12) that I wanted to add locale switching via HTTP Accept-Language header.
What I did to achieve that:
I added rack-contrib to my Gemfile:
gem 'rack-contrib', require: 'rack/contrib'
ran bundle install, added the middleware…

awendt
- 13,195
- 5
- 48
- 66