Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove charset from Rails content type

I have a old-stupid service making request to my app that fails when the Content-Type include the charset line

Content-Type    text/html; charset=utf-8

and I don't know how to remove it from my rails response. Every time that I override the headers forcing just the first part (Content-Type text/html) Rails adds the charset to the header...

like image 258
Toño Silva Portell Avatar asked Aug 08 '10 04:08

Toño Silva Portell


1 Answers

For Rails 3/4, the code that handles this is in ActionDispatch::Response.assign_default_content_type_and_charset! in actionpack/lib/action_dispatch/http/response.rb.

Setting response.headers['Content-Type'] instead of response.content_type should eliminate the charset. Chubas' solution does this for all responses.


For Rails 2, the code that handles this is in content_type= and charset= in actionpack/lib/action_controller/response.rb.

As Carson's solution describes, setting ActionController::Base.default_charset = nil should eliminate the charset.

like image 122
Paul Donohue Avatar answered Sep 22 '22 00:09

Paul Donohue