views:

22

answers:

1

I've set up a Rails 3 proxy method inside a controller to use Nginx' X-Accel-Redirect to deliver a specific URI from a remote server if the user is allowed to.

Unfortunately, Rails always sends some kind of Content-Type header, which takes precedence over the one returned from the upstream server. I've tried various ways of "convincing" the response not to include any Content-Type header at all, but they have either no effect or raise an exception. The response body is of course empty, as it's ignored anyways.

The obvious ones I tried didn't 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, setting a specific Content-type, like "image/gif" works as intended, but the controller can't tell for sure what content is going to be delivered, unlike the remote server.

What would be the best (cleanest?) way for sending a response without that header?

A: 

It's not Rails, but Rack that adds the default text/html content-type:

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

Your best option is to write your own Rack Middleware (or monkey-patch Rack itself) to not send the content-type field at all.

Ariejan
I was hoping there'd be an easier way. After refactoring the controller method into a Rack application, the content is delivered as expected.
icanhasserver