Skip to content

Loading…

Charset coercion enhancements #51

Open
toland opened this Issue · 2 comments

2 participants

@toland
Owner

The current charset coercion code, while nice, can be a bit heavy handed and is just wrong in certain circumstances. In order to get ready for 1.0 I would like to add the following enhancements:

  • Make coercion optional and off by default
  • Allow the user to set a list of Content-Types that should be coerced (default to "text/*")
  • Allow the user to set a fallback charset if the charset provided by the server is unknown or none is provided
@toland toland was assigned
@Paxa

I make some hacks that make patron more stable

class Patron::Response
  def determine_charset(header_data, body)
    header_data.match(charset_regex) || (body && body.match(charset_regex))
    if $1
      $1
    else
      encoding = CharDet.detect(body)
      encoding[:encoding].name.upcase rescue nil
    end
  end

  def convert_to_default_encoding!(str)
    super(str) rescue nil
  end
end
@toland
Owner

I am in the process of rewriting the charset coercion code and will probably use this or something very like it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.