Search code examples
chttpwebsocket

Handling HTTP Requests from Browsers


I am writing a very simple web server in C. I was wondering what HTTP requests I should handle from a browser. I have looked at websites such as Mozilla's HTTP Header docs, but this doesn't tell me exactly what browsers are going to be sending. And handling every request header field is very overkill for what I am attempting to do.

If someone could just point me in the right direction on what I need to handle that would be perfect.

One of the basic headers I have seen requested is:

GET / HTTP/1.1
Host: localhost:3000
Connection: keep-alive
sec-ch-ua: "Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Windows"
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
Sec-Fetch-Site: none
Sec-Fetch-Mode: navigate
Sec-Fetch-User: ?1
Sec-Fetch-Dest: document
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9

But the header is different for things like images or files. So I was wondering if there is a standard of what fields will be used for these different requests?

Any help, or even just a link, would be much appreciated.


Solution

  • Be warned, it is not an easy task to write a http server from scratch. If you still insist to implement one, then make sure to make the best out of the request and respond accordingly (based on the recommendation, aka standard).