Uploaded image for project: 'HttpComponents HttpCore'
  1. HttpComponents HttpCore
  2. HTTPCORE-508

Handle "HTTP/1.1 000 status code 000" responses

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 4.4.9, 5.0-beta2
    • 4.4.10, 5.0-beta3
    • HttpCore, HttpCore NIO
    • None

    Description

      Hi!

      I have a very funny behaviour where the HttpClient seems to wrongly interpret the body of an HTTP response as headers, the parsing of which eventually leads to a java.net.SocketTimeoutException.

      The underlying cause of this seems to be a a faulty server response, i.e.,

      HTTP/1.1 000 status code 000

      Thank you Apple! /s

       

      I have managed to trace the origin of the problem to the method HttpRequestExecutor#canResponseHaveBody where, as expected, 000 is not considered as a valid status code.

      So what happens seems to be that the status line and headers get parsed. The 000 is not considered valid and that ends the processing of the response. Then the rest of the response (the body) seems to go through the parsing procedure again in DefaultHttpResponseParser#parseHead. The body is of content type application/json. Eventually the following exceptions gets thrown after a while:

      java.net.SocketTimeoutException: Read timed out
      
      at java.net.SocketInputStream.socketRead0(Native Method)
      
      at java.net.SocketInputStream.socketRead(SocketInputStream.java:127)
      
      at java.net.SocketInputStream.read(SocketInputStream.java:182)
      
      at java.net.SocketInputStream.read(SocketInputStream.java:152)
      
      at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:137)
      
      at org.apache.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:153)
      
      at org.apache.http.impl.io.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:282)
      
      at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:138)
      
      at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:56)
      
      at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:259)
      
      at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:163)
      
      at org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:165)
      
      at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:273)
      
      at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:125)
      
      at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:272)
      
      at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185)
      
      at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
      
      at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111)
      
      at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
      
      at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
      
      at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:108)
      

       

      I'm not really familiar if 000 is even a valid return code. When querying the server with some other HTTP tools like Postman, I do get the json response with a status code 000.

      Do you guys think this is something that can be fixed in HttpClient or at least handled by some sort of an error?

       

      Attachments

        1. doReceiveResponse.png
          180 kB
          Petar Petrov
        2. canResponseHaveABody.png
          124 kB
          Petar Petrov

        Activity

          People

            olegk Oleg Kalnichevski
            ppetrov Petar Petrov
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: