Skip to content

geobour98/http-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HTTP Server in C

This is a simple HTTP server written in C that performs basic handling of GET and POST requests.

The server runs on whatever port is available. If a port less than 1024 is needed, then the binary should either be given CAP_NET_BIND_SERVICE capability or be run with sudo.

sudo setcap cap_net_bind_service=ep <binary>

Usage

Compile and generate both debug and release versions:

$ make all
[+] Cleaning up...
[+] Building the http server in debug mode...
[+] Building the http server in release mode...

Or for debug: make debug and for release: make release.

GET Request

1st window:

$ ./http-server-rel 4000

2nd window:

$ curl -X GET http://127.0.0.1:4000
<!DOCTYPE html>
<html>
    <head>
        <title>Page Title</title>
    </head>
    <body>
        <h1>Index page!</h1>
    </body>
</html>

POST Request

1st window:

$ ./http-server-rel 4000
[+] POST request's body is:
aa

2nd window:

$ curl -X POST http://127.0.0.1:4000 -H "Content-Length: 4" -d "aa"
curl: (52) Empty reply from server