Commit 3771339 1 parent ace86c9 commit 3771339 Copy full SHA for 3771339
File tree 4 files changed +15
-10
lines changed
dubbo-remoting/dubbo-remoting-http12/src
main/java/org/apache/dubbo/remoting/http12
test/java/org/apache/dubbo/remoting/http12/message/codec
4 files changed +15
-10
lines changed Original file line number Diff line number Diff line change 16
16
*/
17
17
package org .apache .dubbo .remoting .http12 ;
18
18
19
+ import org .apache .dubbo .common .constants .CommonConstants ;
19
20
import org .apache .dubbo .common .io .StreamUtils ;
20
21
import org .apache .dubbo .common .utils .StringUtils ;
21
22
import org .apache .dubbo .remoting .http12 .exception .DecodeException ;
@@ -81,7 +82,7 @@ public static List<HttpCookie> decodeCookies(String value) {
81
82
return cookies ;
82
83
}
83
84
84
- public static String getCharsetFromContentType (String contentType ) {
85
+ public static String parseCharset (String contentType ) {
85
86
String charset = null ;
86
87
if (contentType == null ) {
87
88
charset = StringUtils .EMPTY_STRING ;
@@ -91,7 +92,12 @@ public static String getCharsetFromContentType(String contentType) {
91
92
charset = StringUtils .EMPTY_STRING ;
92
93
} else {
93
94
charset = contentType .substring (index + CHARSET_PREFIX .length ()).trim ();
94
- charset = charset .split (";" )[0 ];
95
+ int splits = charset .indexOf (CommonConstants .SEMICOLON_SEPARATOR );
96
+ if (splits == -1 ) {
97
+ return charset ;
98
+ } else {
99
+ return charset .substring (0 , splits ).trim ();
100
+ }
95
101
}
96
102
}
97
103
return charset ;
Original file line number Diff line number Diff line change @@ -243,7 +243,7 @@ public String charset() {
243
243
String charset = this .charset ;
244
244
if (charset == null ) {
245
245
String contentType = contentType ();
246
- charset = HttpUtils .getCharsetFromContentType (contentType );
246
+ charset = HttpUtils .parseCharset (contentType );
247
247
this .charset = charset ;
248
248
}
249
249
return charset .isEmpty () ? null : charset ;
Original file line number Diff line number Diff line change @@ -166,7 +166,7 @@ public String charset() {
166
166
String charset = this .charset ;
167
167
if (charset == null ) {
168
168
String contentType = contentType ();
169
- charset = HttpUtils .getCharsetFromContentType (contentType );
169
+ charset = HttpUtils .parseCharset (contentType );
170
170
this .charset = charset ;
171
171
}
172
172
return charset .isEmpty () ? null : charset ;
Original file line number Diff line number Diff line change 24
24
public class HttpUtilsTest {
25
25
26
26
@ Test
27
- void testGetCharsetFromContentType () {
28
- String charset = HttpUtils .getCharsetFromContentType ("text/html;charset=utf-8" );
27
+ void testParseCharset () {
28
+ String charset = HttpUtils .parseCharset ("text/html;charset=utf-8" );
29
29
Assertions .assertEquals ("utf-8" , charset );
30
- charset = HttpUtils .getCharsetFromContentType ("text/html" );
30
+ charset = HttpUtils .parseCharset ("text/html" );
31
31
Assertions .assertEquals ("" , charset );
32
- charset = HttpUtils .getCharsetFromContentType ("application/json;charset=utf-8; boundary=__X_PAW_BOUNDARY__" );
32
+ charset = HttpUtils .parseCharset ("application/json;charset=utf-8; boundary=__X_PAW_BOUNDARY__" );
33
33
Assertions .assertEquals ("utf-8" , charset );
34
- charset =
35
- HttpUtils .getCharsetFromContentType ("multipart/form-data; charset=utf-8; boundary=__X_PAW_BOUNDARY__" );
34
+ charset = HttpUtils .parseCharset ("multipart/form-data; charset=utf-8; boundary=__X_PAW_BOUNDARY__" );
36
35
Assertions .assertEquals ("utf-8" , charset );
37
36
}
38
37
}
You can’t perform that action at this time.
0 commit comments