-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Content-Type forced for all responses #1238
Comments
Simply extracting this "default" Currently I ended up reimplementing the whole |
Can you instead use a middleware which removes the content type or any other information that needs to be removed? For instance: class MyMiddleware
def initialize(app)
@app = app
end
def call(env)
status, headers, response = @app.call(env)
headers.delete('Content-Type')
[status, headers, response]
end
end And in require './middleware.rb'
use MyMiddleware
run MyApp This way you can customise all the routes according to your use case, and avoid overriding any internal method of the library itself. This will save you from unexpected issues if and when this |
If you |
For example |
Unfortunately, it looks like Rack::Protection requires that a Content-Type be set most of the time, so it fails with weird errors if we try to work around Sinatra by setting it to nil or anything like that. Quite frankly, I don't understand why it's so important to you to remove the Content-Type header in these cases. My understanding is that browsers and other user-agents expect this header to be present on most responses, even on 404. The Content-Length and Transfer-Encoding headers are intended to be used to determine whether or not there is content. Just set it to some appropriate default for your intended audience(s) and forget about it. If you're still determined to do this, I think @kgrz's idea is best. |
Best is to reimplement The current implementation is based on an assumption that My actual goal is to implement the API spec that I have as strict as possible. |
I opened #1239 to address this. We'll see what the higher-ups have to say! |
It's been a long time now... I wonder if it's still relevant. If the issue is still there - the PR solves it, so why don't we merge it? |
Fixed by #1239. |
From
Sinatra::Base
@ https://github.com/sinatra/sinatra/blob/master/lib/sinatra/base.rb#L915:Code
is problematic, because it forces response to have a
Content-Type
header. In some cases we don't want that. Can we make a setting to allow disabling this behavior?My usecase is not limited to 204 response. I have some error codes that should have no content as well.
The text was updated successfully, but these errors were encountered: