File tree 2 files changed +22
-1
lines changed
main/java/com/ning/http/client
test/java/com/ning/http/client/async
2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -612,9 +612,22 @@ public T setConnectionPoolKeyStrategy(ConnectionPoolKeyStrategy connectionPoolKe
612
612
}
613
613
614
614
public Request build () {
615
+ try {
616
+ final String contentType = request .headers .getFirstValue ("Content-Type" );
617
+ if (contentType != null ) {
618
+ final String charset = AsyncHttpProviderUtils .parseCharset (contentType );
619
+ if (charset != null ) {
620
+ // ensure that if charset is provided with the Content-Type header,
621
+ // we propagate that down to the charset of the Request object
622
+ request .charset = charset ;
623
+ }
624
+ }
625
+ } catch (Throwable e ) {
626
+ // NoOp -- we can't fix the Content-Type or charset from here
627
+ }
615
628
if (request .length < 0 && request .streamData == null ) {
616
629
// can't concatenate content-length
617
- String contentLength = request .headers .getFirstValue ("Content-Length" );
630
+ final String contentLength = request .headers .getFirstValue ("Content-Length" );
618
631
619
632
if (contentLength != null ) {
620
633
try {
Original file line number Diff line number Diff line change @@ -105,4 +105,12 @@ public void testUserProvidedRequestMethod() {
105
105
assertEquals (req .getMethod (), "ABC" );
106
106
assertEquals (req .getUrl (), "http://foo.com" );
107
107
}
108
+
109
+ @ Test (groups = {"standalone" , "default_provider" })
110
+ public void testContentTypeCharsetToBodyEncoding () {
111
+ final Request req = new RequestBuilder ("GET" ).setHeader ("Content-Type" , "application/json; charset=utf-8" ).build ();
112
+ assertEquals (req .getBodyEncoding (), "utf-8" );
113
+ final Request req2 = new RequestBuilder ("GET" ).setHeader ("Content-Type" , "application/json; charset=\" utf-8\" " ).build ();
114
+ assertEquals (req2 .getBodyEncoding (), "utf-8" );
115
+ }
108
116
}
You can’t perform that action at this time.
0 commit comments