square / retrofit

A type-safe HTTP client for Android and the JVM
https://square.github.io/retrofit/
Apache License 2.0
42.99k stars 7.3k forks source link

header encoding issues #516

Closed cmorin6 closed 10 years ago

cmorin6 commented 10 years ago

Hi,

When passing headers parameters containing a 'é' it is received on server side as 'é'. It might seem wird to pass such chars as arguments but I can't modify server side. I know this behaviour is specific to retrofit because it worked with the old client using HttpUrlConnection and it also works with Postman chrome plugin.

I don't know if this bug comes from retrofit itself or from the underlying okhttpClient i'm using.

I've tried with the folowing versions retrofit : 1.5.0 & 1.5.1 okhttp : 1.5.4 , 1.6.0 & 2.0.0-RC1

I hope this might help.

artworkad commented 10 years ago

@JakeWharton https://github.com/square/retrofit/issues/513 may be related?

JakeWharton commented 10 years ago

Reproduced this. Investigating now.

JakeWharton commented 10 years ago

According to RFC 2616 (HTTP) headers use the ISO-8859-1 character set. Alternate character sets can be used if they are encoded using RFC 2047. When using the Apache client it seems to be working (using MockWebServer) but both OkHttp and UrlConnection clients get the garbled characters like you saw.

We need to figure out the right owner of handling the encoding here. Since the Apache client already supports it I'm inclined to say that we should add it to OkHttp. I need to have a chat with some people internally before we can move forward.

You can see the code I was playing with here: https://github.com/square/retrofit/compare/jw;broken-header-encoding

JakeWharton commented 10 years ago

Moved to OkHttp.