Hi all,

during testing a Restlet based web app with JMeter I came across a strange 
issue, which I stripped down to an issue with the Apache HttpClient:

when a request gets a 204 (success no content) response, the NEXT request fails 
with a "org.apache.http.NoHttpResponseException: The target server failed to 
respond” exception (see stacktrace below), but only if the request follows 
immediately (like 200ms) after the 1st request. With some time (e.g. 2s) 
between the requests the 2nd request succeeds.

The only interesting fact I found so far is, that Restlet adds a 
“Content-Length: 0” header to the 204 response. There seems to be some 
disussion if that is allowed or not. While I agree that the header does make 
much sense for a 204, it seems not to be strictly forbidden.

Find example code at https://github.com/slintes/httpclienttest with 3 
components:

- the Restlet server with 2 endpoints, “test” which returns a 200 with response 
body, and “empty” which returns a 204 without body (but automatically added 
Content-Length header)
- an Apache HttpClient based test client, which request “test”, “empty”, 
“test”, “test”: the 3rd request fails, unless you increase the sleep in line 
35. The 4th request is always successful.
- for comparison a Vertx HttpClient based test client, which does the same and 
always succeeds.

Is this a bug? And if not, why not?

Complete stacktrace of the failing request:

org.apache.http.NoHttpResponseException: The target server failed to respond
        at 
org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:143)
        at 
org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57)
        at 
org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:261)
        at 
org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:165)
        at 
org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:167)
        at 
org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:272)
        at 
org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:124)
        at 
org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:271)
        at 
org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
        at 
org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
        at 
org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
        at 
org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:71)
        at 
org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:220)
        at 
org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:164)
        at 
org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:139)

Kind Regards,

Marc Sluiter

Reply via email to