Home > Software design >  Does HTTP allows the server to send its response before having received the entire body?
Does HTTP allows the server to send its response before having received the entire body?

Time:07-01

In the HTTP/1.1 standard, is it explicitly allowed or forbidden for a server to send a response before all the request's data have been received?

As an example, when uploading a large amount of data with a POST request, I may imagine the server returning a "202 ACCEPTED" response after receiving the request's header, but before having received the entire body. Would it be legal or not? Is this something existing out in the wild?

Strongly related to Is it acceptable for a server to send a HTTP response before the entire request has been received?, but the response there seems to focus on processing "errors" (4xx, 5xx maybe), not "success" (2xx)

CodePudding user response:

HTTP (Hypertext transfer protocol) defines the protocol of communication. The question you ask is strongly dependent on the implementation of the protocol. AFAIR, the protocol doesn't define a specification on when the response should be sent.

From the logical perspective though, as an implementer, I'd read all the data before sending the response.

1.4 Overall Operation

The HTTP protocol is a request/response protocol. A client sends a request to the server in the form of a request method, URI, and protocol version, followed by a MIME-like message containing request modifiers, client information, and possible body content over a connection with a server. The server responds with a status line, including the message's protocol version and a success or error code, followed by a MIME-like message containing server information, entity metainformation, and possible entity-body content. The relationship between HTTP and MIME is described in appendix 19.4.

As you may see here, it talks only about responding, but not when to respond. So, it's the implementer's decision.

CodePudding user response:

Seems the answer is yes

HTTP Response sent before async call returns

Please take a look at this too:

Stop Waiting! Start using Async and Await!

Without possibility to send response before receiving the entire request body, async processing of requests would not be possible.

And you can return 202 status code to indicate that:

The request has been accepted for processing, but the processing has not been completed.

HTTP Status Code for "Still Processing"

  •  Tags:  
  • http
  • Related