jira-importer opened a new issue, #998:
URL: https://github.com/apache/httpcomponents-core/issues/998

   **[Tuomas 
Kiviaho](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=tuomas_kiviaho)**
 opened 
**[HTTPCORE-481](https://issues.apache.org/jira/browse/HTTPCORE-481?redirect=false)**
 and commented
   
   I have a `text/event-stream` response where status code 200 is sent 
immediately back even when there is still request body streaming in process. 
This works well with Jetty client but for some reason I could only receive the 
first full buffer at server side when switching over to HttpAsyncClient. The 
only visible notion that something went wrong was Jetty doing an idle timeout 
cleanup. Luckily there is a notion of connection state which got invalidated 
when response was received but only when request body streaming was still in 
progress.
   
   I found out via this link 
https://stackoverflow.com/questions/14250991/is-it-acceptable-for-a-server-to-send-a-http-response-before-the-entire-request
 that probably the reason behind the behavior is to prevent flooding the server 
in case of an error.
   
   > An HTTP/1.1 (or later) client sending a message-body SHOULD monitor the 
network connection for an error status while it is transmitting the request. If 
the client sees an error status, it SHOULD immediately cease transmitting the 
body.
   
   Below is a patch that currently functions as a work-a-round for me. I'd 
still prefer the current behavior in case of unauthorized authentication etc. 
because the request body can be quite large.
   
   ```
            } else if (state.getRequestState() == MessageState.BODY_STREAM) {
                // Early response
   +            if (statusCode >= 400) {
                   conn.resetOutput();
                   conn.suspendOutput();
                   state.setRequestState(MessageState.COMPLETED);
                   state.invalidate();
   +            }
            }
   ```
   
   
   
   ---
   
   **Affects:** 4.4.5
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to