private static RawHttpHeaders withPlainTextExtension(RawHttpHeaders extensions) { RawHttpHeaders result = extensions.and(PLAIN_TEXT_HEADER); Optional<String> charset = result.getFirst("Charset"); if (!charset.isPresent() || !Charset.isSupported(charset.get())) { result = result.and(UTF8_HEADER); } return result; }
/** * Callback that will be called every time the server receives a HTTP request, but before it sends out a * HTTP response. * <p> * The actual response the client will see is the one returned by this method. * <p> * By default, this method adds "Date" and "Server" headers (the latter with the value of "RawHTTP"). * * @param request received by the server * @param response the server routed to. Normally, this callback should return this response with possibly * minor alterations. * @return the response the client should receive. Must not be null. * @throws IOException if an error occurs reading/writing HTTP messages */ default RawHttpResponse<Void> onResponse(RawHttpRequest request, RawHttpResponse<Void> response) throws IOException { return response.withHeaders(getCurrentDateHeader().and(SERVER_HEADER)); }
/** * Callback that will be called every time the server receives a HTTP request, but before it sends out a * HTTP response. * <p> * The actual response the client will see is the one returned by this method. * <p> * By default, this method adds "Date" and "Server" headers (the latter with the value of "RawHTTP"). * * @param request received by the server * @param response the server routed to. Normally, this callback should return this response with possibly * minor alterations. * @return the response the client should receive. Must not be null. * @throws IOException if an error occurs reading/writing HTTP messages */ default RawHttpResponse<Void> onResponse(RawHttpRequest request, RawHttpResponse<Void> response) throws IOException { return response.withHeaders(getCurrentDateHeader().and(SERVER_HEADER)); }