Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8a5ada3

Browse files
committed
Merge pull requestAsyncHttpClient#540 from kelvl/content-type-body-charset-sync
Propagate charset from Content-Type into Request's bodyEncoding
2 parents8a7328c +d6b992a commit8a5ada3

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

‎src/main/java/com/ning/http/client/RequestBuilderBase.java‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,9 +612,22 @@ public T setConnectionPoolKeyStrategy(ConnectionPoolKeyStrategy connectionPoolKe
612612
}
613613

614614
publicRequestbuild() {
615+
try {
616+
finalStringcontentType =request.headers.getFirstValue("Content-Type");
617+
if (contentType !=null) {
618+
finalStringcharset =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 (Throwablee) {
626+
// NoOp -- we can't fix the Content-Type or charset from here
627+
}
615628
if (request.length <0 &&request.streamData ==null) {
616629
// can't concatenate content-length
617-
StringcontentLength =request.headers.getFirstValue("Content-Length");
630+
finalStringcontentLength =request.headers.getFirstValue("Content-Length");
618631

619632
if (contentLength !=null) {
620633
try {

‎src/test/java/com/ning/http/client/async/RequestBuilderTest.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,12 @@ public void testUserProvidedRequestMethod() {
105105
assertEquals(req.getMethod(),"ABC");
106106
assertEquals(req.getUrl(),"http://foo.com");
107107
}
108+
109+
@Test(groups = {"standalone","default_provider"})
110+
publicvoidtestContentTypeCharsetToBodyEncoding() {
111+
finalRequestreq =newRequestBuilder("GET").setHeader("Content-Type","application/json; charset=utf-8").build();
112+
assertEquals(req.getBodyEncoding(),"utf-8");
113+
finalRequestreq2 =newRequestBuilder("GET").setHeader("Content-Type","application/json; charset=\"utf-8\"").build();
114+
assertEquals(req2.getBodyEncoding(),"utf-8");
115+
}
108116
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp