Comments (3)
Note that Roda never uses any existing response headers, since it creates a new response for every request. So what I'm guessing is happening is your middleware is setting content-type
in the response even if Content-Type
is already set by Roda (as opposed to to Roda setting Content-Type
when content-type
is already set).
On Rack 2, Roda uses a plain hash for headers, so headers are case sensitive. On Rack 3, Roda uses Rack::Headers (a hash subclass which will automatically downcase header keys). For backwards compatibility, Roda uses mixed-case header keys. So this behavior is currently expected on Rack 2 if your middleware is not handling response header keys in a case-insensitive manner (such middleware is considered broken on Rack 2).
One solution is to fix your middleware to operate properly on Rack 2 by treating response header keys in a case insensitive manner (usually done with Rack::Utils::HeaderHash
in Rack 2). Another solution would be to switch to Rack 3. Alternatively, you could do the following in your Roda app:
opts[:default_headers] = {}
plugin :default_headers, 'content-type'=>'text/html'
which will change Roda to use content-type
instead of Content-Type
In an upcoming release, I plan to add a plugin that will make Roda use downcased header keys by default, which will become the default behavior in Roda 4.
from roda.
This behavior surprised me as well. Does this really relate to middleware?
In the following, I'm using puma-6.2.2, rack-2.2.6.3, and roda-3.71.0.
--- config.ru ---
require 'roda'
class App < Roda
route do |r|
r.get do
response['content-type'] = 'text/plain'
'hi'
end
end
end
run App
--- config.ru ---
$ rackup
$ curl -D - http://localhost:9292/
HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 2
hi
Also surprising is that if one sets response['Content-Type'] first, then the lowercase version works:
--- config.ru ---
require 'roda'
class App < Roda
route do |r|
r.get do
response['Content-Type'] = 'text/html' # a strange band-aid
response['content-type'] = 'text/plain'
'hi'
end
end
end
run App
--- config.ru ---
$ curl -D - http://localhost:9292/
HTTP/1.1 200 OK
content-type: text/plain
Content-Length: 2
hi
from roda.
As stated above, Roda uses and expects mixed case response headers if using Rack < 3. So you shouldn't use lower case response headers in your Roda app unless you have already upgraded to Rack 3. If you are using Rack 3, either case will work, since headers will be implicitly lowercased.
from roda.
Related Issues (20)
- Roda in production HOT 1
- opts[:root] not be set after start server. HOT 3
- Envrionments plugin: provide instance methods too? HOT 1
- How can i load coffeescript in roda HOT 2
- How to use common_logger plugin to log information in routes implementation or in specs or other place in the application? HOT 6
- [feature request] Make the view method (from the render plugin) accept a block like the render method does HOT 1
- route_csrf incompatible with rack-protection authenticity token checks HOT 5
- Unfork HOT 3
- env['rack.errors'] parsed as a link in common_logger plugin documentation HOT 2
- String matcher in hash_routes combined with unescape_path does not match non-ascii strings HOT 1
- [Documentation / Question] Request for a FAQ for experienced sinatra users HOT 1
- Raises "Unsupported block result" when using Unreloader and json plugin HOT 2
- On app startup. Getting message > Rack::Handler is deprecated and replaced by Rackup::Handler HOT 2
- Not compatible with Haml >= 6 HOT 2
- URI Unicode handling HOT 6
- json plugin does not support FalseClass and String anymore HOT 1
- Can gRPC services and clients be integrated?
- Unicode escapes not decoded in path HOT 3
- Sanitize params when using plugin `error_mail` HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from roda.