private BodyReader createBodyReader(InputStream inputStream, StartLine startLine, RawHttpHeaders headers) { return new LazyBodyReader(getFramedBody(startLine, headers), inputStream); }
@Override public EagerBodyReader eager() throws IOException { markConsumed(); try { return new EagerBodyReader(getFramedBody(), inputStream); } catch (IOException e) { // error while trying to read message body, we cannot keep the connection alive try { inputStream.close(); } catch (IOException e2) { // ignore } throw e; } }
@Override public void writeTo(OutputStream out, int bufferSize) throws IOException { markConsumed(); super.writeTo(out, bufferSize); }
@Override public OptionalLong getLengthIfKnown() { try { return getFramedBody().use( cl -> OptionalLong.of(cl.getBodyLength()), chunked -> OptionalLong.empty(), ct -> OptionalLong.empty()); } catch (IOException e) { return OptionalLong.empty(); } }
@Override public Optional<ChunkedBodyContents> asChunkedBodyContents() throws IOException { markConsumed(); return super.asChunkedBodyContents(); }
@Override public OptionalLong getLengthIfKnown() { try { return getFramedBody().use( cl -> OptionalLong.of(cl.getBodyLength()), chunked -> OptionalLong.empty(), ct -> OptionalLong.empty()); } catch (IOException e) { return OptionalLong.empty(); } }
private BodyReader createBodyReader(InputStream inputStream, StartLine startLine, RawHttpHeaders headers) { return new LazyBodyReader(getFramedBody(startLine, headers), inputStream); }
@Override public EagerBodyReader eager() throws IOException { markConsumed(); try { return new EagerBodyReader(getFramedBody(), inputStream); } catch (IOException e) { // error while trying to read message body, we cannot keep the connection alive try { inputStream.close(); } catch (IOException e2) { // ignore } throw e; } }
@Override public byte[] asRawBytes() throws IOException { markConsumed(); return super.asRawBytes(); }
@Override public LazyBodyReader toBodyReader() { try { return new LazyBodyReader( new FramedBody.ContentLength(getBodyDecoder(), file.length()), new BufferedInputStream(Files.newInputStream(file.toPath()))); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public Optional<ChunkedBodyContents> asChunkedBodyContents() throws IOException { markConsumed(); return super.asChunkedBodyContents(); }
@Override public LazyBodyReader toBodyReader() { try { return new LazyBodyReader( new FramedBody.ContentLength(getBodyDecoder(), file.length()), new BufferedInputStream(Files.newInputStream(file.toPath()))); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public byte[] asRawBytes() throws IOException { markConsumed(); return super.asRawBytes(); }
@Override public LazyBodyReader toBodyReader() { return new LazyBodyReader( new FramedBody.ContentLength(getBodyDecoder(), (long) bytes.length), new ByteArrayInputStream(bytes)); }
@Override public void writeTo(OutputStream out, int bufferSize) throws IOException { markConsumed(); super.writeTo(out, bufferSize); }
@Override public LazyBodyReader toBodyReader() { return new LazyBodyReader( new FramedBody.ContentLength(getBodyDecoder(), (long) bytes.length), new ByteArrayInputStream(bytes)); }
@Override public LazyBodyReader toBodyReader() { return new LazyBodyReader( new FramedBody.Chunked(getBodyDecoder(), createStrictHttpMetadataParser()), stream); }
@Override public LazyBodyReader toBodyReader() { return new LazyBodyReader(new FramedBody.Chunked(getBodyDecoder(), metadataParser), new InputStreamChunkEncoder(stream, chunkLength)); }
@Override public LazyBodyReader toBodyReader() { return new LazyBodyReader(new FramedBody.Chunked(getBodyDecoder(), metadataParser), new InputStreamChunkEncoder(stream, chunkLength)); }
public RawHttpResponse<CloseableHttpResponse> send(RawHttpRequest request) throws IOException { RequestBuilder builder = RequestBuilder.create(request.getMethod()); builder.setUri(request.getUri()); builder.setVersion(toProtocolVersion(request.getStartLine().getHttpVersion())); request.getHeaders().getHeaderNames().forEach((name) -> request.getHeaders().get(name).forEach(value -> builder.addHeader(new BasicHeader(name, value)))); request.getBody().ifPresent(b -> builder.setEntity(new InputStreamEntity(b.asRawStream()))); CloseableHttpResponse response = httpClient.execute(builder.build()); RawHttpHeaders headers = readHeaders(response); StatusLine statusLine = adaptStatus(response.getStatusLine()); @Nullable LazyBodyReader body; if (response.getEntity() != null) { FramedBody framedBody = http.getFramedBody(statusLine, headers); body = new LazyBodyReader(framedBody, response.getEntity().getContent()); } else { body = null; } return new RawHttpResponse<>(response, request, statusLine, headers, body); }