Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-users] Jettu consumes request body with "Expect: 100-continue" header before "100 Continue" response is sent

Hi,

First, some background. I have a client code working with remote server. Client is based on HttpClient. I have access to its code, but I cannot change it. Remote server is also out of my control. This server provides standard "100 Continue" feature. First, client sends only POST request header. Then server decides whether to accept it and then sends either "100 Continue" or an error response back to the client. In case client receives "100 Continue", it submits request body to the server. Nothing special.

What I need is to mimic this server behavior using Jetty and some custom logic so that client do not see any difference between my server and the real server. Jetty version is 9.0.3 v20130506. 

Here is how I handle request rejection on the server side:

resp.setStatus(403);
resp.setHeader("header", "value");
ServletOutputStream os = resp.getOutputStream();
os.println("Error text.");
os.close();

And at first glance this works fine: client expects 100 code, but recieves someting else, do not send request body and returns error code.

However, if I change my code as follows:

Thread.sleep(2000); // Think about it as a some long-running server-side logic.
resp.setStatus(403);
resp.setHeader("header", "value");
ServletOutputStream os = resp.getOutputStream();
os.println("Error text.");
os.close();

... client got stuck trying to write request body data to the socket.

Then I injected TCPMon between the client and my server and saw the following picture:
1) Client sends request header to the server WITHOUT body
2) Then it waits for a while (about a second) ...
3) ... and then starts writing request body data to server even if 100 Continue was not sent by the server!

The problem could be on either side:
1) May be HttpClient breaks 100 Continue contract and start pushing request data before getting 100 Continue.
2) May be some background Jetty threads start reading request body before actually sending 100 Continue.

Anyway, client code cannot be changed and it works normally with the real server even if I simulate extremly slow connection through proxy. So I assume that it is something on Jetty side - may be some additional configuration is required, may be this is a bug. may be something else.

Could you please help me with this issue?

Thanks in advance.

Vladimir Ozerov.

 


Back to the top