Returns a charset object based on the requests content type. Defaults to UTF-8 See rfc7231 - Accept-Charset See rfc7231 - Media Type
()
| 209 | * Type</a> |
| 210 | */ |
| 211 | public Charset charset() { |
| 212 | |
| 213 | Collection<String> contentTypeHeaders = headers().get("Content-Type"); |
| 214 | |
| 215 | if (contentTypeHeaders != null) { |
| 216 | for (String contentTypeHeader : contentTypeHeaders) { |
| 217 | String[] contentTypeParmeters = contentTypeHeader.split(";"); |
| 218 | if (contentTypeParmeters.length > 1) { |
| 219 | String[] charsetParts = contentTypeParmeters[1].split("="); |
| 220 | if (charsetParts.length == 2 && "charset".equalsIgnoreCase(charsetParts[0].trim())) { |
| 221 | String charsetString = charsetParts[1].replaceAll("\"", ""); |
| 222 | return Charset.forName(charsetString); |
| 223 | } |
| 224 | } |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | return Util.UTF_8; |
| 229 | } |
| 230 | |
| 231 | @Override |
| 232 | public String toString() { |