You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by agherardi <gi...@git.apache.org> on 2018/01/19 18:44:31 UTC

[GitHub] httpcomponents-core pull request #57: Workaround for misbehaved servers that...

GitHub user agherardi opened a pull request:

    https://github.com/apache/httpcomponents-core/pull/57

    Workaround for misbehaved servers that return HTTP 204 responses with a content

    I have encountered a server that incorrectly returns a content on a HTTP 204 response. The server also returns a Content-length header with the response.
    
    httpclient assumes that HTTP 204 responses have no content, so it doesn't consume the content.
    
    If the connection is reused, this causes httpclient to hang when looking for the status line of the next response.
    
    This patch attempts to prevent the issue by allowing HTTP 204 responses with Content-length or Transfer-encoding: Chunked as responses to have a content.

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

    $ git pull https://github.com/agherardi/httpcomponents-core nocontent

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

    https://github.com/apache/httpcomponents-core/pull/57.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 #57
    
----
commit c4780e32c3a67fe7fd82da8fd9bc2d2d4b240876
Author: alessandro.gherardi <al...@...>
Date:   2018-01-19T18:39:27Z

    Workaround for misbehaved servers that return HTTP 204 responses with a content

----


---

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


[GitHub] httpcomponents-core issue #57: Workaround for misbehaved servers that return...

Posted by agherardi <gi...@git.apache.org>.
Github user agherardi commented on the issue:

    https://github.com/apache/httpcomponents-core/pull/57
  
    One possibility would be to modify DefaultClientConnectionReuseStrategy.keepAlive() as follows: If the response is a HTTP 204 and contains either content-length or transfer-encoding, return FALSE - i.e., do NOT reuse the connection.
    
    Sounds acceptable? Any better alternatives?


---

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


[GitHub] httpcomponents-core issue #57: Workaround for misbehaved servers that return...

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

    https://github.com/apache/httpcomponents-core/pull/57
  
    @agherardi An alternative would be to throw a `ProtocolException` from a response interceptor, however the solution you have proposed looks better to me.


---

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


[GitHub] httpcomponents-core pull request #57: Workaround for misbehaved servers that...

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

    https://github.com/apache/httpcomponents-core/pull/57


---

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


[GitHub] httpcomponents-core pull request #57: Workaround for misbehaved servers that...

Posted by agherardi <gi...@git.apache.org>.
GitHub user agherardi reopened a pull request:

    https://github.com/apache/httpcomponents-core/pull/57

    Workaround for misbehaved servers that return HTTP 204 responses with a content

    I have encountered a server that incorrectly returns a content on a HTTP 204 response. The server also returns a Content-length header with the response.
    
    httpclient assumes that HTTP 204 responses have no content, so it doesn't consume the content.
    
    If the connection is reused, this causes httpclient to hang when looking for the status line of the next response.
    
    This patch attempts to prevent the issue by allowing HTTP 204 responses with Content-length or Transfer-encoding: Chunked as responses to have a content.

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

    $ git pull https://github.com/agherardi/httpcomponents-core nocontent

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

    https://github.com/apache/httpcomponents-core/pull/57.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 #57
    
----
commit c4780e32c3a67fe7fd82da8fd9bc2d2d4b240876
Author: alessandro.gherardi <al...@...>
Date:   2018-01-19T18:39:27Z

    Workaround for misbehaved servers that return HTTP 204 responses with a content

----


---

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


[GitHub] httpcomponents-core issue #57: Workaround for misbehaved servers that return...

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

    https://github.com/apache/httpcomponents-core/pull/57
  
    @agherardi Committed to master and 4.4.x with some minor tweaks. Please review


---

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


[GitHub] httpcomponents-core issue #57: Workaround for misbehaved servers that return...

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

    https://github.com/apache/httpcomponents-core/pull/57
  
    I fully agree with @reschke. Being 'clever' about such severe protocol violations is not good idea. However I would happily commit a patch failing 204 responses with `Content-Length` or `Transfer-Encoding` headers


---

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


[GitHub] httpcomponents-core issue #57: Workaround for misbehaved servers that return...

Posted by agherardi <gi...@git.apache.org>.
Github user agherardi commented on the issue:

    https://github.com/apache/httpcomponents-core/pull/57
  
    Changed approach and modified HttpCore DefaultConnectionReuseStrategy as suggested. Added unit-tests.


---

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


[GitHub] httpcomponents-core issue #57: Workaround for misbehaved servers that return...

Posted by reschke <gi...@git.apache.org>.
Github user reschke commented on the issue:

    https://github.com/apache/httpcomponents-core/pull/57
  
    Both are spec violations. Maybe this should be treated as fatal error.


---

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


[GitHub] httpcomponents-core issue #57: Workaround for misbehaved servers that return...

Posted by reschke <gi...@git.apache.org>.
Github user reschke commented on the issue:

    https://github.com/apache/httpcomponents-core/pull/57
  
    That sounds like a bad idea. It would treat a 204 *with* Content-Length but without payload incorrectly, right?


---

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


[GitHub] httpcomponents-core issue #57: Workaround for misbehaved servers that return...

Posted by agherardi <gi...@git.apache.org>.
Github user agherardi commented on the issue:

    https://github.com/apache/httpcomponents-core/pull/57
  
    Closed and replaced by https://github.com/apache/httpcomponents-client/pull/95


---

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


[GitHub] httpcomponents-core issue #57: Workaround for misbehaved servers that return...

Posted by agherardi <gi...@git.apache.org>.
Github user agherardi commented on the issue:

    https://github.com/apache/httpcomponents-core/pull/57
  
    > It would treat a 204 with Content-Length but without payload incorrectly, right?
    
    Correct. However, the presence of a Content-Length is more indicative that a payload exists than the status code 204 being used incorrectly.


---

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


[GitHub] httpcomponents-core issue #57: Workaround for misbehaved servers that return...

Posted by agherardi <gi...@git.apache.org>.
Github user agherardi commented on the issue:

    https://github.com/apache/httpcomponents-core/pull/57
  
    Thanks for your feedback.
    
    Failing the response should work for me. However, in that case httpclient should also close the connection - if it goes back to the pool it'll cause troubles since client and server are out-of-sync. Do you have any suggestions on how to do that?


---

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


[GitHub] httpcomponents-core pull request #57: Workaround for misbehaved servers that...

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

    https://github.com/apache/httpcomponents-core/pull/57


---

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


[GitHub] httpcomponents-core issue #57: Workaround for misbehaved servers that return...

Posted by agherardi <gi...@git.apache.org>.
Github user agherardi commented on the issue:

    https://github.com/apache/httpcomponents-core/pull/57
  
    Looks good. Thank you!


---

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