static void addEncoding ( final Request . Builder builder , final HttpExchange httpExchange ) { final String contentType = httpExchange . getRequestHeaders ( ) . getFirst ( "Content-Type" ) ; if ( contentType != null ) { final Matcher matcher = CHARSET_PATTERN . matcher ( contentType ) ; if ( matcher . matches ( ) ) { try { builder . encoding ( Charset . forName ( matcher . group ( 1 ) ) ) ; } catch ( UnsupportedCharsetException e ) { //just ignore, fallback encoding will be used instead } } } }
package protected for testing purposes