How to send a Bad Request HTTP request
I am writing a C program that needs to send back an HTTP Bad Response. This is what I am writing to the socket.
HTTP/1.1 400 Bad Request\r\n
Connection: close\r\n
\r\n
My question is why is the browser still spinning (as if it is still downloading something? Am I missing the header in the Http response? Or am I missing something else?)
Thanks.
+2
a source to share
2 answers
Connection: close
does not close the connection immediately - it just indicates that the connection will not be reused after the current request - it is the opposite Connection: keep-alive
. Try to include Content-Length: 0
to indicate there is no content.
Or just close your socket.
+1
a source to share