@Override public Response.Builder readResponseHeaders(boolean expectContinue) throws IOException { if (state != STATE_OPEN_REQUEST_BODY && state != STATE_READ_RESPONSE_HEADERS) { throw new IllegalStateException("state: " + state); } try { StatusLine statusLine = StatusLine.parse(readHeaderLine()); Response.Builder responseBuilder = new Response.Builder() .protocol(statusLine.protocol) .code(statusLine.code) .message(statusLine.message) .headers(readHeaders()); if (expectContinue && statusLine.code == HTTP_CONTINUE) { return null; } else if (statusLine.code == HTTP_CONTINUE) { state = STATE_READ_RESPONSE_HEADERS; return responseBuilder; } state = STATE_OPEN_RESPONSE_BODY; return responseBuilder; } catch (EOFException e) { // Provide more context if the server ends the stream before sending a response. throw new IOException("unexpected end of stream on " + streamAllocation, e); } }
/** Returns headers for a name value block containing an HTTP/2 response. */ public static Response.Builder readHttp2HeadersList(Headers headerBlock, Protocol protocol) throws IOException { StatusLine statusLine = null; Headers.Builder headersBuilder = new Headers.Builder(); for (int i = 0, size = headerBlock.size(); i < size; i++) { String name = headerBlock.name(i); String value = headerBlock.value(i); if (name.equals(RESPONSE_STATUS_UTF8)) { statusLine = StatusLine.parse("HTTP/1.1 " + value); } else if (!HTTP_2_SKIPPED_RESPONSE_HEADERS.contains(name)) { Internal.instance.addLenient(headersBuilder, name, value); } } if (statusLine == null) throw new ProtocolException("Expected ':status' header not present"); return new Response.Builder() .protocol(protocol) .code(statusLine.code) .message(statusLine.message) .headers(headersBuilder.build()); }
StatusLine statusLine = StatusLine.parse(extractStatusLine(javaResponse)); okResponseBuilder.protocol(statusLine.protocol); okResponseBuilder.code(statusLine.code);
@Override public Response.Builder readResponseHeaders(boolean expectContinue) throws IOException { if (state != STATE_OPEN_REQUEST_BODY && state != STATE_READ_RESPONSE_HEADERS) { throw new IllegalStateException("state: " + state); } try { StatusLine statusLine = StatusLine.parse(readHeaderLine()); Response.Builder responseBuilder = new Response.Builder() .protocol(statusLine.protocol) .code(statusLine.code) .message(statusLine.message) .headers(readHeaders()); if (expectContinue && statusLine.code == HTTP_CONTINUE) { return null; } else if (statusLine.code == HTTP_CONTINUE) { state = STATE_READ_RESPONSE_HEADERS; return responseBuilder; } state = STATE_OPEN_RESPONSE_BODY; return responseBuilder; } catch (EOFException e) { // Provide more context if the server ends the stream before sending a response. throw new IOException("unexpected end of stream on " + streamAllocation, e); } }
StatusLine statusLine = StatusLine.parse(extractStatusLine(httpUrlConnection)); okResponseBuilder.protocol(statusLine.protocol); okResponseBuilder.code(statusLine.code);
/** Returns headers for a name value block containing an HTTP/2 response. */ public static Response.Builder readHttp2HeadersList(Headers headerBlock, Protocol protocol) throws IOException { StatusLine statusLine = null; Headers.Builder headersBuilder = new Headers.Builder(); for (int i = 0, size = headerBlock.size(); i < size; i++) { String name = headerBlock.name(i); String value = headerBlock.value(i); if (name.equals(RESPONSE_STATUS_UTF8)) { statusLine = StatusLine.parse("HTTP/1.1 " + value); } else if (!HTTP_2_SKIPPED_RESPONSE_HEADERS.contains(name)) { Internal.instance.addLenient(headersBuilder, name, value); } } if (statusLine == null) throw new ProtocolException("Expected ':status' header not present"); return new Response.Builder() .protocol(protocol) .code(statusLine.code) .message(statusLine.message) .headers(headersBuilder.build()); }
StatusLine statusLine = StatusLine.parse(source.readUtf8LineStrict()); protocol = statusLine.protocol; code = statusLine.code;
StatusLine statusLine = StatusLine.parse(source.readUtf8LineStrict()); protocol = statusLine.protocol; code = statusLine.code;
StatusLine statusLine = StatusLine.parse(source.readUtf8LineStrict()); protocol = statusLine.protocol; code = statusLine.code;
/** * Retrieves the status code portion of the Response's <CODE>status</CODE> element. * If it is not present, returns {@link #DEFAULT_STATUS_CODE} (a.k.a. <CODE>200</CODE>). * * @param response The response complex type of the multistatus * @return DEFAULT_STATUS_CODE if not found in response; -1 if status line was malformed */ private int getStatusCode(Response response) { String status = response.getStatus(); if (status == null || status.isEmpty()) { return DEFAULT_STATUS_CODE; } try { return StatusLine.parse(response.getStatus()).code; } catch (IOException e) { log.warning(String.format("Failed to parse status line: %s", status)); return -1; } }
@Override public Response.Builder readResponseHeaders(boolean expectContinue) throws IOException { if (state != STATE_OPEN_REQUEST_BODY && state != STATE_READ_RESPONSE_HEADERS) { throw new IllegalStateException("state: " + state); } try { StatusLine statusLine = StatusLine.parse(readHeaderLine()); Response.Builder responseBuilder = new Response.Builder() .protocol(statusLine.protocol) .code(statusLine.code) .message(statusLine.message) .headers(readHeaders()); if (expectContinue && statusLine.code == HTTP_CONTINUE) { return null; } state = STATE_OPEN_RESPONSE_BODY; return responseBuilder; } catch (EOFException e) { // Provide more context if the server ends the stream before sending a response. IOException exception = new IOException("unexpected end of stream on " + streamAllocation); exception.initCause(e); throw exception; } }
/** Parses bytes of a response header from an HTTP transport. */ public Response.Builder readResponse() throws IOException { if (state != STATE_OPEN_REQUEST_BODY && state != STATE_READ_RESPONSE_HEADERS) { throw new IllegalStateException("state: " + state); } try { while (true) { StatusLine statusLine = StatusLine.parse(source.readUtf8LineStrict()); Response.Builder responseBuilder = new Response.Builder() .protocol(statusLine.protocol) .code(statusLine.code) .message(statusLine.message) .headers(readHeaders()); if (statusLine.code != HTTP_CONTINUE) { state = STATE_OPEN_RESPONSE_BODY; return responseBuilder; } } } catch (EOFException e) { // Provide more context if the server ends the stream before sending a response. IOException exception = new IOException("unexpected end of stream on " + streamAllocation); exception.initCause(e); throw exception; } }
/** Parses bytes of a response header from an HTTP transport. */ public Response.Builder readResponse() throws IOException { if (state != STATE_OPEN_REQUEST_BODY && state != STATE_READ_RESPONSE_HEADERS) { throw new IllegalStateException("state: " + state); } try { while (true) { StatusLine statusLine = StatusLine.parse(source.readUtf8LineStrict()); Response.Builder responseBuilder = new Response.Builder() .protocol(statusLine.protocol) .code(statusLine.code) .message(statusLine.message) .headers(readHeaders()); if (statusLine.code != HTTP_CONTINUE) { state = STATE_OPEN_RESPONSE_BODY; return responseBuilder; } } } catch (EOFException e) { // Provide more context if the server ends the stream before sending a response. IOException exception = new IOException("unexpected end of stream on " + streamAllocation); exception.initCause(e); throw exception; } }
@Override public Response.Builder readResponseHeaders(boolean expectContinue) throws IOException { if (state != STATE_OPEN_REQUEST_BODY && state != STATE_READ_RESPONSE_HEADERS) { throw new IllegalStateException("state: " + state); } try { StatusLine statusLine = StatusLine.parse(readHeaderLine()); Response.Builder responseBuilder = new Response.Builder() .protocol(statusLine.protocol) .code(statusLine.code) .message(statusLine.message) .headers(readHeaders()); if (expectContinue && statusLine.code == HTTP_CONTINUE) { return null; } else if (statusLine.code == HTTP_CONTINUE) { state = STATE_READ_RESPONSE_HEADERS; return responseBuilder; } state = STATE_OPEN_RESPONSE_BODY; return responseBuilder; } catch (EOFException e) { // Provide more context if the server ends the stream before sending a response. IOException exception = new IOException("unexpected end of stream on " + streamAllocation); exception.initCause(e); throw exception; } }
/** Parses bytes of a response header from an HTTP transport. */ public Response.Builder readResponse() throws IOException { if (state != STATE_OPEN_REQUEST_BODY && state != STATE_READ_RESPONSE_HEADERS) { throw new IllegalStateException("state: " + state); } try { while (true) { StatusLine statusLine = StatusLine.parse(source.readUtf8LineStrict()); Response.Builder responseBuilder = new Response.Builder() .protocol(statusLine.protocol) .code(statusLine.code) .message(statusLine.message) .headers(readHeaders()); if (statusLine.code != HTTP_CONTINUE) { state = STATE_OPEN_RESPONSE_BODY; return responseBuilder; } } } catch (EOFException e) { // Provide more context if the server ends the stream before sending a response. IOException exception = new IOException("unexpected end of stream on " + streamAllocation); exception.initCause(e); throw exception; } }
/** Returns headers for a name value block containing an HTTP/2 response. */ public static Response.Builder readHttp2HeadersList(List<Header> headerBlock) throws IOException { String status = null; Headers.Builder headersBuilder = new Headers.Builder(); for (int i = 0, size = headerBlock.size(); i < size; i++) { ByteString name = headerBlock.get(i).name; String value = headerBlock.get(i).value.utf8(); if (name.equals(RESPONSE_STATUS)) { status = value; } else if (!HTTP_2_SKIPPED_RESPONSE_HEADERS.contains(name)) { headersBuilder.add(name.utf8(), value); } } if (status == null) throw new ProtocolException("Expected ':status' header not present"); StatusLine statusLine = StatusLine.parse("HTTP/1.1 " + status); return new Response.Builder() .protocol(Protocol.HTTP_2) .code(statusLine.code) .message(statusLine.message) .headers(headersBuilder.build()); }
/** Returns headers for a name value block containing an HTTP/2 response. */ public static Response.Builder readHttp2HeadersList(List<Header> headerBlock) throws IOException { String status = null; Headers.Builder headersBuilder = new Headers.Builder(); for (int i = 0, size = headerBlock.size(); i < size; i++) { ByteString name = headerBlock.get(i).name; String value = headerBlock.get(i).value.utf8(); if (name.equals(RESPONSE_STATUS)) { status = value; } else if (!HTTP_2_SKIPPED_RESPONSE_HEADERS.contains(name)) { headersBuilder.add(name.utf8(), value); } } if (status == null) throw new ProtocolException("Expected ':status' header not present"); StatusLine statusLine = StatusLine.parse("HTTP/1.1 " + status); return new Response.Builder() .protocol(Protocol.HTTP_2) .code(statusLine.code) .message(statusLine.message) .headers(headersBuilder.build()); }
/** Returns headers for a name value block containing an HTTP/2 response. */ public static Response.Builder readHttp2HeadersList(List<Header> headerBlock) throws IOException { String status = null; Headers.Builder headersBuilder = new Headers.Builder(); for (int i = 0, size = headerBlock.size(); i < size; i++) { ByteString name = headerBlock.get(i).name; String value = headerBlock.get(i).value.utf8(); if (name.equals(RESPONSE_STATUS)) { status = value; } else if (!HTTP_2_SKIPPED_RESPONSE_HEADERS.contains(name)) { headersBuilder.add(name.utf8(), value); } } if (status == null) throw new ProtocolException("Expected ':status' header not present"); StatusLine statusLine = StatusLine.parse("HTTP/1.1 " + status); return new Response.Builder() .protocol(Protocol.HTTP_2) .code(statusLine.code) .message(statusLine.message) .headers(headersBuilder.build()); }
/** Returns headers for a name value block containing an HTTP/2 response. */ public static Response.Builder readHttp2HeadersList(List<Header> headerBlock) throws IOException { StatusLine statusLine = null; Headers.Builder headersBuilder = new Headers.Builder(); for (int i = 0, size = headerBlock.size(); i < size; i++) { Header header = headerBlock.get(i); // If there were multiple header blocks they will be delimited by nulls. Discard existing // header blocks if the existing header block is a '100 Continue' intermediate response. if (header == null) { if (statusLine != null && statusLine.code == HTTP_CONTINUE) { statusLine = null; headersBuilder = new Headers.Builder(); } continue; } ByteString name = header.name; String value = header.value.utf8(); if (name.equals(RESPONSE_STATUS)) { statusLine = StatusLine.parse("HTTP/1.1 " + value); } else if (!HTTP_2_SKIPPED_RESPONSE_HEADERS.contains(name)) { Internal.instance.addLenient(headersBuilder, name.utf8(), value); } } if (statusLine == null) throw new ProtocolException("Expected ':status' header not present"); return new Response.Builder() .protocol(Protocol.HTTP_2) .code(statusLine.code) .message(statusLine.message) .headers(headersBuilder.build()); }
/** Returns headers for a name value block containing an HTTP/2 response. */ public static Response.Builder readHttp2HeadersList(Headers headerBlock, Protocol protocol) throws IOException { StatusLine statusLine = null; Headers.Builder headersBuilder = new Headers.Builder(); for (int i = 0, size = headerBlock.size(); i < size; i++) { String name = headerBlock.name(i); String value = headerBlock.value(i); if (name.equals(RESPONSE_STATUS_UTF8)) { statusLine = StatusLine.parse("HTTP/1.1 " + value); } else if (!HTTP_2_SKIPPED_RESPONSE_HEADERS.contains(name)) { Internal.instance.addLenient(headersBuilder, name, value); } } if (statusLine == null) throw new ProtocolException("Expected ':status' header not present"); return new Response.Builder() .protocol(protocol) .code(statusLine.code) .message(statusLine.message) .headers(headersBuilder.build()); }