@Test public void testChunked() throws Exception { byte[] buf = new byte[300]; Arrays.fill(buf, (byte) ' '); HttpExtensionMethod base = new HttpExtensionMethod("POST", "http: ApacheHttpRequest request = new ApacheHttpRequest(new MockHttpClient(), base); HttpContent content = new InputStreamContent("text/plain", new ByteArrayInputStream(buf)); request.setStreamingContent(content); request.execute(); assertTrue(base.getEntity().isChunked()); assertEquals(-1, base.getEntity().getContentLength()); }
@Override public LowLevelHttpResponse execute() throws IOException { if (getStreamingContent() != null) { Preconditions.checkState( request instanceof HttpEntityEnclosingRequest, "Apache HTTP client does not support %s requests with content.", request.getRequestLine().getMethod()); ContentEntity entity = new ContentEntity(getContentLength(), getStreamingContent()); entity.setContentEncoding(getContentEncoding()); entity.setContentType(getContentType()); if (getContentLength() == -1) { entity.setChunked(true); } ((HttpEntityEnclosingRequest) request).setEntity(entity); } request.setConfig(requestConfig.build()); return new ApacheHttpResponse(request, httpClient.execute(request)); }
ApacheHttpRequest extends LowLevelHttpRequest { @Override public LowLevelHttpResponse execute() throws IOException { if (getStreamingContent() != null) { Preconditions.checkState( request instanceof HttpEntityEnclosingRequest, "Apache HTTP client does not support %s requests with content.", request.getRequestLine().getMethod()); ContentEntity entity = new ContentEntity(getContentLength(), getStreamingContent()); entity.setContentEncoding(getContentEncoding()); entity.setContentType(getContentType()); if (getContentLength() == -1) { entity.setChunked(true); } ((HttpEntityEnclosingRequest) request).setEntity(entity); } request.setConfig(requestConfig.build()); return new ApacheHttpResponse(request, httpClient.execute(request)); } }
ApacheHttpRequest extends LowLevelHttpRequest { @Override public LowLevelHttpResponse execute() throws IOException { if (getStreamingContent() != null) { Preconditions.checkState( request instanceof HttpEntityEnclosingRequest, "Apache HTTP client does not support %s requests with content.", request.getRequestLine().getMethod()); ContentEntity entity = new ContentEntity(getContentLength(), getStreamingContent()); entity.setContentEncoding(getContentEncoding()); entity.setContentType(getContentType()); if (getContentLength() == -1) { entity.setChunked(true); } ((HttpEntityEnclosingRequest) request).setEntity(entity); } request.setConfig(requestConfig.build()); return new ApacheHttpResponse(request, httpClient.execute(request)); } @SuppressWarnings("deprecation")  ApacheHttpRequest(HttpClient httpClient, HttpRequestBase request); }
ApacheHttpRequest extends LowLevelHttpRequest { @Override public LowLevelHttpResponse execute() throws IOException { if (getStreamingContent() != null) { Preconditions.checkState( request instanceof HttpEntityEnclosingRequest, "Apache HTTP client does not support %s requests with content.", request.getRequestLine().getMethod()); ContentEntity entity = new ContentEntity(getContentLength(), getStreamingContent()); entity.setContentEncoding(getContentEncoding()); entity.setContentType(getContentType()); if (getContentLength() == -1) { entity.setChunked(true); } ((HttpEntityEnclosingRequest) request).setEntity(entity); } request.setConfig(requestConfig.build()); return new ApacheHttpResponse(request, httpClient.execute(request)); } @SuppressWarnings("deprecation")  ApacheHttpRequest(HttpClient httpClient, HttpRequestBase request); @Override void addHeader(String name, String value); @Override void setTimeout(int connectTimeout, int readTimeout); @Override LowLevelHttpResponse execute(); }
ApacheHttpRequest extends LowLevelHttpRequest { @Override public LowLevelHttpResponse execute() throws IOException { if (getStreamingContent() != null) { Preconditions.checkState( request instanceof HttpEntityEnclosingRequest, "Apache HTTP client does not support %s requests with content.", request.getRequestLine().getMethod()); ContentEntity entity = new ContentEntity(getContentLength(), getStreamingContent()); entity.setContentEncoding(getContentEncoding()); entity.setContentType(getContentType()); if (getContentLength() == -1) { entity.setChunked(true); } ((HttpEntityEnclosingRequest) request).setEntity(entity); } request.setConfig(requestConfig.build()); return new ApacheHttpResponse(request, httpClient.execute(request)); } @SuppressWarnings("deprecation")  ApacheHttpRequest(HttpClient httpClient, HttpRequestBase request); @Override void addHeader(String name, String value); @Override void setTimeout(int connectTimeout, int readTimeout); @Override LowLevelHttpResponse execute();  }