Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 67310200B13 for ; Wed, 15 Jun 2016 19:20:11 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 65AD3160A4D; Wed, 15 Jun 2016 17:20:11 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id B2050160A57 for ; Wed, 15 Jun 2016 19:20:10 +0200 (CEST) Received: (qmail 94189 invoked by uid 500); 15 Jun 2016 17:20:09 -0000 Mailing-List: contact dev-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list dev@hc.apache.org Received: (qmail 93923 invoked by uid 99); 15 Jun 2016 17:20:09 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Jun 2016 17:20:09 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id 623C22C1F5D for ; Wed, 15 Jun 2016 17:20:09 +0000 (UTC) Date: Wed, 15 Jun 2016 17:20:09 +0000 (UTC) From: "Tom Fitzhenry (JIRA)" To: dev@hc.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (HTTPCORE-422) HttpAsyncRequestExecutor#responseReceived calls HttpAsyncResponseConsumer#responseReceived(HttpResponse), even for HEAD requests MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Wed, 15 Jun 2016 17:20:11 -0000 [ https://issues.apache.org/jira/browse/HTTPCORE-422?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15332127#comment-15332127 ] Tom Fitzhenry commented on HTTPCORE-422: ---------------------------------------- {{#onEntityEnclosed}} *is* triggered for HEAD requests. {code} import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpHead; import org.apache.http.entity.ContentType; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; import org.apache.http.impl.nio.client.HttpAsyncClients; import org.apache.http.nio.client.methods.HttpAsyncMethods; import org.apache.http.nio.protocol.BasicAsyncResponseConsumer; import org.apache.http.nio.protocol.HttpAsyncRequestProducer; import java.io.IOException; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; public class Main { public static void main(String[] args) throws IOException, ExecutionException, InterruptedException { try (CloseableHttpAsyncClient foo = HttpAsyncClients.createDefault()) { foo.start(); HttpHead request = new HttpHead("http://httpbin.org"); Future response; try (HttpAsyncRequestProducer httpHead = HttpAsyncMethods.create(request)) { response = foo.execute(httpHead, new BasicAsyncResponseConsumer() { @Override protected void onEntityEnclosed(HttpEntity entity, ContentType contentType) throws IOException { System.out.println("onEntityEnclosed!"); System.out.println(entity); super.onEntityEnclosed(entity, contentType); } }, null); } System.out.println(response.get()); } } } {code} When the above is executed, it prints: {code} onEntityEnclosed! [Content-Type: text/html; charset=utf-8,Content-Length: 12150,Chunked: false] HTTP/1.1 200 OK [Server: nginx, Date: Wed, 15 Jun 2016 17:16:34 GMT, Content-Type: text/html; charset=utf-8, Content-Length: 12150, Connection: keep-alive, Access-Control-Allow-Origin: *, Access-Control-Allow-Credentials: true] {code} It sounds like that is a bug, but once resolved will remove the need for a NoopResponseConsumer. > HttpAsyncRequestExecutor#responseReceived calls HttpAsyncResponseConsumer#responseReceived(HttpResponse), even for HEAD requests > -------------------------------------------------------------------------------------------------------------------------------- > > Key: HTTPCORE-422 > URL: https://issues.apache.org/jira/browse/HTTPCORE-422 > Project: HttpComponents HttpCore > Issue Type: Improvement > Components: HttpCore NIO > Affects Versions: 4.4.4 > Reporter: Tom Fitzhenry > Assignee: Oleg Kalnichevski > Priority: Minor > > HttpAsyncRequestExecutor#responseReceived(NHttpClientConnection) calls HttpAsyncResponseConsumer#responseReceived(HttpResponse) via HttpAsyncClientExchangeHandler#responseReceived(HttpResponse). > See https://github.com/apache/httpcore/blob/4.4.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java#L302 . > It does this even if the request is a HEAD request. If your HttpAsyncResponseConsumer is a BasicAsyncResponseConsumer, then this will allocate a buffer of size content-length kB (or 4kB, if content-length does not exist). > For a simple proxying Java app, profiling revealed this the allocation due to this was a bottleneck. > It'd be nice if > Are there use cases for calling HttpAsyncResponseConsumer#responseReceived(HttpResponse) on HEAD requests? If not, perhaps it could not be called. > FWIW, it looks like httpclient doe not call the corresponding method for HEAD requests: https://github.com/apache/httpcore/blob/4.4.x/httpcore/src/main/java/org/apache/http/protocol/HttpRequestExecutor.java#L273-L275 -- This message was sent by Atlassian JIRA (v6.3.4#6332) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org For additional commands, e-mail: dev-help@hc.apache.org