How to implement simple http echo server in C, posix sockets

Another snippet from Unix Sandbox.

Http echo server is a tool which echoes the data used in your request. Can be used for testing your clients, getting to know how HTTP works etc... only for fun, feel free to use it in any purpose.

Sample response:
GET / HTTP/1.1
Host: localhost
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8,pl;q=0.6

Full source code:


Popularne posty