If my browser tries to do an HTTP GET on a file that isn’t on my server, I just write
HTTP/1.0 404 Not Found\r\n\r\n
to the port. In my browser’s web console, I can see that sometimes the error is recognized, but sometimes it’s not. Instead the text will be displayed in the browser window. Why does this happen?
If I use curl the response always looks the same, so why does it do this in the browser?
Seems that most web browsers expect the
Content-Length:header in all responses. Even if you are not replying anything; which is pretty funny because the only mandatory header isHost:only in requests and only for HTTP 1.1.I tested with Firefox and I had to write down the following to make it work:
And then the browser should close the connection. If you use libcurl, it is probably inserting this and other headers too, like
Date:for instance.