/** * @return the status code of this HTTP response. * @see #getStartLine() */ public int getStatusCode() { return statusLine.getStatusCode(); }
@Override public void writeTo(OutputStream outputStream) throws IOException { byte[] bytes = toString().getBytes(StandardCharsets.US_ASCII); outputStream.write(bytes); outputStream.write('\r'); outputStream.write('\n'); }
private StatusLine adaptStatus(org.apache.http.StatusLine statusLine) { return new StatusLine( HttpVersion.parse(statusLine.getProtocolVersion().toString()), statusLine.getStatusCode(), statusLine.getReasonPhrase()); }
@Override public RawHttpResponse<Void> onResponse(Socket socket, URI uri, RawHttpResponse<Void> httpResponse) throws IOException { if (httpResponse.getHeaders() .getFirst("Connection") .orElse("") .equalsIgnoreCase("close") || httpResponse.getStartLine().getHttpVersion().isOlderThan(HttpVersion.HTTP_1_1)) { socketByHost.remove(uri.getHost()); // resolve the full response before closing the socket return httpResponse.eagerly(false); } return httpResponse; }
return new StatusLine(version, Integer.parseInt(statusCode), reason);
@Override public RawHttpResponse<Void> onResponse(Socket socket, URI uri, RawHttpResponse<Void> httpResponse) throws IOException { if (httpResponse.getHeaders() .getFirst("Connection") .orElse("") .equalsIgnoreCase("close") || httpResponse.getStartLine().getHttpVersion().isOlderThan(HttpVersion.HTTP_1_1)) { socketByHost.remove(uri.getHost()); // resolve the full response before closing the socket return httpResponse.eagerly(false); } return httpResponse; }
return new StatusLine(version, Integer.parseInt(statusCode), reason);
/** * @return the status code of this HTTP response. * @see #getStartLine() */ public int getStatusCode() { return statusLine.getStatusCode(); }
@Override public void writeTo(OutputStream outputStream) throws IOException { byte[] bytes = toString().getBytes(StandardCharsets.US_ASCII); outputStream.write(bytes); outputStream.write('\r'); outputStream.write('\n'); }
/** * Determines whether a response with the given status-line should have a body. * <p> * If provided, the request-line of the request which produced such response is taken into * consideration. See <a href="https://tools.ietf.org/html/rfc7230#section-3.3">Section 3.3</a> * of RFC-7230 for details. * * @param statusLine status-line of response * @param requestLine request-line of request, if any * @return true if such response has a body, false otherwise */ public static boolean responseHasBody(StatusLine statusLine, @Nullable RequestLine requestLine) { if (requestLine != null) { if (requestLine.getMethod().equalsIgnoreCase("HEAD")) { return false; // HEAD response must never have a body } if (requestLine.getMethod().equalsIgnoreCase("CONNECT") && startsWith(2, statusLine.getStatusCode())) { return false; // CONNECT successful means start tunelling } } int statusCode = statusLine.getStatusCode(); // All 1xx (Informational), 204 (No Content), and 304 (Not Modified) // responses do not include a message body. boolean hasNoBody = startsWith(1, statusCode) || statusCode == 204 || statusCode == 304; return !hasNoBody; }
/** * Determines whether a response with the given status-line should have a body. * <p> * If provided, the request-line of the request which produced such response is taken into * consideration. See <a href="https://tools.ietf.org/html/rfc7230#section-3.3">Section 3.3</a> * of RFC-7230 for details. * * @param statusLine status-line of response * @param requestLine request-line of request, if any * @return true if such response has a body, false otherwise */ public static boolean responseHasBody(StatusLine statusLine, @Nullable RequestLine requestLine) { if (requestLine != null) { if (requestLine.getMethod().equalsIgnoreCase("HEAD")) { return false; // HEAD response must never have a body } if (requestLine.getMethod().equalsIgnoreCase("CONNECT") && startsWith(2, statusLine.getStatusCode())) { return false; // CONNECT successful means start tunelling } } int statusCode = statusLine.getStatusCode(); // All 1xx (Informational), 204 (No Content), and 304 (Not Modified) // responses do not include a message body. boolean hasNoBody = startsWith(1, statusCode) || statusCode == 204 || statusCode == 304; return !hasNoBody; }