Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make sure the http response was delivered?

Tags:

cherrypy

To respond a http request, we can just use return "content" in the method function.

But for some mission-critical use cases, I would like to make sure the http 200 OK response was delivered. Any idea?

like image 598
Kevin Kuei Avatar asked Mar 23 '18 07:03

Kevin Kuei


People also ask

How does HTTP response look like?

After receiving and interpreting a request message, a server responds with an HTTP response message: A Status-line. Zero or more header (General|Response|Entity) fields followed by CRLF. An empty line (i.e., a line with nothing preceding the CRLF) indicating the end of the header fields.

How do you handle HTTP response?

HTTP Response sent by a server to the client. The response is used to provide the client with the resource it requested. It is also used to inform the client that the action requested has been carried out. It can also inform the client that an error occurred in processing its request.

What are the 3 parts of an HTTP response?

HTTP Response broadly has 3 main components: Status Line. Headers. Body (Optional)

What happens when a HTTP request is sent?

The URL you are requesting is the address that belongs to the server. Once the TCP connection is established, the client sends a HTTP GET request to the server to retrieve the webpage it should display. After the server has sent the response, it closes the TCP connection.


2 Answers

The HTTP protocol doesn't work that way. If you need an acknowledgement then you need the client to send the acknowledgement to you.

Or you should look at implementing a bi-direction socket (a sample library is socket.io) where the client can send the ACK. If it is mission critical, then don't let it be on just http, use websockets

Also you can use AJAX callbacks to gather acknowledgment. One way of creating such a solution would be UUID generated for every request and returned as a part of header

$ curl -v http://domain/url
....
response:

X-ACK-Token: 89080-3e432423-234234-23-42323

and then client make a call again

$ curl http://domain/ack/89080-3e432423-234234-23-42323

So the server would know that the given response has been acknowledge by the client. But you cannot enforce automatic ACK, it is still on the client to send it, if they don't, you have no way of knowing

PS: The UUID is not an actual UUID here, just for example shared as random number

like image 200
Tarun Lalwani Avatar answered Oct 03 '22 06:10

Tarun Lalwani


Take a look at Microsofts asynchronous server socket.

An asynchronous server socket requires a method to begin accepting connection requests from the network, a callback method to handle the connection requests and begin receiving data from the network, and a callback method to end receiving the data (this is where your client could respond with the success or failure of the HTTP request that was made).

Example

like image 23
Jesse Milam Avatar answered Oct 03 '22 06:10

Jesse Milam