Ask the dispatcher to send a response without a Content-Type header

I installed a Rails 3 proxy inside the controller to use Nginx X-Accel-Redirect to deliver a specific URI from a remote server, if the user is allowed.

Unfortunately, Rails always sends some Content-Type header, which takes precedence over the one returned from the upstream server. I tried various ways to “convince” the answer not to include the Content-Type header at all, but they either do not affect or throw an exception. The body of the answer, of course, is empty, since it is ignored in any case.

The obvious ones I tried do not work as the value remains "text / html; charset ...":

response.headers['Content-type'] = ''
response.headers['Content-Type'] = nil
response.headers['Content-Type'] = ''
response.content_type = ''
response.content_type = nil

Of course, installing a certain type of content, such as "image / gif", works as intended, but the controller cannot tell exactly what content will be delivered, unlike a remote server.

What would be the best (cleanest?) Way to send a response without this header?

+2
source share
1 answer

It is not Rails, but Rack, which adds the text/htmldefault content type :

http://rack.rubyforge.org/doc/Rack/ContentType.html

Your best bet is to write your own rack middleware (or the monkey fix panel itself) so you don’t have to send a content type field at all.

0
source

Source: https://habr.com/ru/post/1527522/


All Articles