@Override protected String parse(Http.RequestHeader request, ByteString bytes) throws Exception { // Per RFC 7231: // The default charset of ISO-8859-1 for text media types has been removed; the default is now // whatever the media type definition says. // Per RFC 6657: // The default "charset" parameter value for "text/plain" is unchanged from [RFC2046] and remains as "US-ASCII". // https://tools.ietf.org/html/rfc6657#section-4 Charset charset = request.charset().map(Charset::forName).orElse(US_ASCII); try { CharsetDecoder decoder = charset.newDecoder().onMalformedInput(CodingErrorAction.REPORT); return decoder.decode(bytes.toByteBuffer()).toString(); } catch (CharacterCodingException e) { String msg = String.format("Parser tried to parse request %s as text body with charset %s, but it contains invalid characters!", request.id(), charset); logger.warn(msg); return bytes.decodeString(charset); // parse and return with unmappable characters. } catch (Exception e) { String msg = "Unexpected exception while parsing text/plain body"; logger.error(msg, e); return bytes.decodeString(charset); } } }
@Override protected String parse(Http.RequestHeader request, ByteString bytes) throws Exception { // Per RFC 7231: // The default charset of ISO-8859-1 for text media types has been removed; the default is now // whatever the media type definition says. // Per RFC 6657: // The default "charset" parameter value for "text/plain" is unchanged from [RFC2046] and remains as "US-ASCII". // https://tools.ietf.org/html/rfc6657#section-4 Charset charset = request.charset().map(Charset::forName).orElse(US_ASCII); try { CharsetDecoder decoder = charset.newDecoder().onMalformedInput(CodingErrorAction.REPORT); return decoder.decode(bytes.toByteBuffer()).toString(); } catch (CharacterCodingException e) { String msg = String.format("Parser tried to parse request %s as text body with charset %s, but it contains invalid characters!", request.id(), charset); logger.warn(msg); return bytes.decodeString(charset); // parse and return with unmappable characters. } catch (Exception e) { String msg = "Unexpected exception while parsing text/plain body"; logger.error(msg, e); return bytes.decodeString(charset); } } }
@Override protected String parse(Http.RequestHeader request, ByteString bytes) throws Exception { // Per RFC 7231: // The default charset of ISO-8859-1 for text media types has been removed; the default is now // whatever the media type definition says. // Per RFC 6657: // The default "charset" parameter value for "text/plain" is unchanged from [RFC2046] and remains as "US-ASCII". // https://tools.ietf.org/html/rfc6657#section-4 Charset charset = request.charset().map(Charset::forName).orElse(US_ASCII); try { CharsetDecoder decoder = charset.newDecoder().onMalformedInput(CodingErrorAction.REPORT); return decoder.decode(bytes.toByteBuffer()).toString(); } catch (CharacterCodingException e) { String msg = String.format("Parser tried to parse request %s as text body with charset %s, but it contains invalid characters!", request.id(), charset); logger.warn(msg); return bytes.decodeString(charset); // parse and return with unmappable characters. } catch (Exception e) { String msg = "Unexpected exception while parsing text/plain body"; logger.error(msg, e); return bytes.decodeString(charset); } } }
return F.Either.Right(decoder.decode(byteBuffer).toString()); } catch (CharacterCodingException e) { String msg = String.format("Parser tried to parse request %s as text body with charset %s, but it contains invalid characters!", request.id(), encodingToTry); logger.warn(msg); return F.Either.Left(e);
return F.Either.Right(decoder.decode(byteBuffer).toString()); } catch (CharacterCodingException e) { String msg = String.format("Parser tried to parse request %s as text body with charset %s, but it contains invalid characters!", request.id(), encodingToTry); logger.warn(msg); return F.Either.Left(e);
return F.Either.Right(decoder.decode(byteBuffer).toString()); } catch (CharacterCodingException e) { String msg = String.format("Parser tried to parse request %s as text body with charset %s, but it contains invalid characters!", request.id(), encodingToTry); logger.warn(msg); return F.Either.Left(e);