You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by hirthwork <gi...@git.apache.org> on 2014/11/12 18:21:55 UTC

[GitHub] httpcore pull request: Set EmptyInputStream in entity instead of C...

GitHub user hirthwork opened a pull request:

    https://github.com/apache/httpcore/pull/8

    Set EmptyInputStream in entity instead of ContentLengthInputStream(in, 0)

    # Problem description
    1. If HttpClient receives response with `Content-Length: 0` the connection won't be returned to connection pool until `entity.getContent().close()` is called (it is usually done by `EntityUtils.consume()`) or any read operation performed on `entity.getContent()`.
    2. If CloseableHttpResponse.close() is called on such response without entity consuming, the connection will be closed, despite of any keep-alive strategies.
    
    Here the [sample](https://gist.github.com/hirthwork/6f4ebb047e77a61f644e) illustrating first problem. Trying to execute two sequential requests with maxPerRoute set to 1 we will hit TimeoutException because connection from first response (which has empty body) won't be returned to pool.
    
    # Problem analysis
    Current BHttpConnectionBase contract is to set input stream regardless of `Content-Length:` header value. The only way to distinct empty response entities from regular ones is to set entity content to some pre-defined value which can indicate that entity is not streaming, so `MainClientExec.execute()` can return connection to pool immediately.
    
    # Solution
    Introduce `EmptyInputStream` singleton which will be set as BasicHttpEntity content on zero length responses. `isStreaming()` will check content for nullness and equality with `EmptyInputStream.INSTANCE`.
    As alternative, suggested solution can be applied to 4.4.x branch, while for 5.0 branch contract can be broken and `prepareInput()` will return null for zero-length responses.
    
    # Test
    Aforementioned sample can be used for this solution testing.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/hirthwork/httpcore trunk

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/httpcore/pull/8.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #8
    
----
commit f52e25482c1b4d5b518656122188c9cab99ac5ed
Author: Dmitry Potapov <dp...@yandex-team.ru>
Date:   2014-11-12T16:58:45Z

    Set EmptyInputStream in entity instead of ContentLengthInputStream(inbuffer, 0)

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[GitHub] httpcore pull request: Set EmptyInputStream in entity instead of C...

Posted by hirthwork <gi...@git.apache.org>.
Github user hirthwork closed the pull request at:

    https://github.com/apache/httpcore/pull/8


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[GitHub] httpcore pull request: Set EmptyInputStream in entity instead of C...

Posted by hirthwork <gi...@git.apache.org>.
Github user hirthwork commented on the pull request:

    https://github.com/apache/httpcore/pull/8#issuecomment-63104037
  
    Thanks a lot


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[GitHub] httpcore pull request: Set EmptyInputStream in entity instead of C...

Posted by ok2c <gi...@git.apache.org>.
Github user ok2c commented on the pull request:

    https://github.com/apache/httpcore/pull/8#issuecomment-63101614
  
    Patch committed to both SVN trunk and 4.4.x branch. Unfortunately the commit to trunk got botched either due to my mistake or due to some issue with Git-Svn. Most of your changes got folded into my previous, completely unrelated, commit.
    
    Many thanks for contributing the patch.
    
    Oleg


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org