HTTP 1.1 20 second delay compared to HTTP 1.0

I wrote a C program that sends an HTTP 1.1 POST to a web server.
Tracking it well with wirehark, it takes less than a second to respond to the server and receive the HTTP/1.1 200 OK message, but then it takes another 20 seconds to get the FIN, ACK packet, which I believe causes what recv calls to return 0 without specifying more data.
Causing my program to hang for 20 seconds, so the server is waiting for the FIN, ACK packet to be sent.

I tested this with HTTP 1.0 and there is no delay. Therefore, I think this is because HTTP 1.1 by default treats all connections as persistent connections .
But my web browser uses HTTP 1.1 and there is no delay, so I think I'm not doing something right.

One of my ideas was to return 0 instead of recv , I have to check if I am at the end of the document differently, but I can’t figure out how to do this.

So, if someone could explain to me how should I do this? Thanks in advance.

+4
source share
1 answer

HTTP 1.1 by default supports keep-alive connections, but 1.0 does not. You can request non-keep-alive by adding a header

 Connection: close 

which instructs the server to close the connection immediately after it is completed.

+6
source

All Articles