@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); } }
public static StatusLine get(Response response) { return new StatusLine(response.protocol(), response.code(), response.message()); }
sink.writeUtf8(new StatusLine(protocol, code, message).toString()) .writeByte('\n'); sink.writeDecimalLong(responseHeaders.size() + 2)
Response response = client.newCall(request).execute(); if (showHeaders) { System.out.println(StatusLine.get(response)); Headers headers = response.headers(); for (int i = 0, size = headers.size(); i < size; i++) {
sink.writeUtf8(new StatusLine(protocol, code, message).toString()) .writeByte('\n'); sink.writeDecimalLong(responseHeaders.size() + 2)
Response response = client.newCall(request).execute(); if (showHeaders) { System.out.println(StatusLine.get(response)); Headers headers = response.headers(); for (int i = 0, size = headers.size(); i < size; i++) {
/** 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()); }
bufferedSink.writeUtf8(new StatusLine(protocol, code, message).toString()) .writeByte('\n'); bufferedSink.writeDecimalLong(responseHeaders.size() + 2)
public static StatusLine get(Response response) { return new StatusLine(response.protocol(), response.code(), response.message()); }
StatusLine statusLine = StatusLine.parse(extractStatusLine(javaResponse)); okResponseBuilder.protocol(statusLine.protocol); okResponseBuilder.code(statusLine.code);
sink.writeUtf8(new StatusLine(protocol, code, message).toString()); sink.writeByte('\n'); sink.writeDecimalLong(responseHeaders.size());
return new StatusLine(protocol, code, message);
@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); } }
sink.writeUtf8(new StatusLine(protocol, code, message).toString()); sink.writeByte('\n'); sink.writeDecimalLong(responseHeaders.size());
return new StatusLine(protocol, code, message);
@Override public String getHeaderField(int position) { // Deal with index 0 meaning "status line" if (position < 0) { throw new IllegalArgumentException("Invalid header index: " + position); } if (position == 0) { return StatusLine.get(response).toString(); } if (position > response.headers().size()) { return null; } return response.headers().value(position - 1); }