Skip to content

oliverigor27/c-http-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 

Repository files navigation

🧱 C HTTP Server

A simple HTTP server built from scratch in C using low-level socket programming.

πŸš€ Features

  • Handles basic HTTP requests
  • Supports simple routing:
    • / β†’ Home
    • /sobre β†’ About page
  • Returns plain text responses
  • Built using POSIX sockets (socket, bind, listen, accept)
  • Minimal and easy to understand

πŸ› οΈ How to Run

1. Compile

gcc server.c -o server

2. Run

./server

3. Open in browser

http://localhost:8080

πŸ“‘ Available Routes

Route Method Description
/ GET Home page
/sobre GET About page

🧠 How It Works

This server:

  1. Creates a socket using TCP
  2. Binds it to port 8080
  3. Listens for incoming connections
  4. Accepts client requests
  5. Reads raw HTTP requests
  6. Parses routes using simple string matching
  7. Sends HTTP responses manually

πŸ“Œ Example Request

GET / HTTP/1.1
Host: localhost:8080

πŸ“Œ Example Response

HTTP/1.1 200 OK
Content-Type: text/plain

PΓ‘gina inicial

⚠️ Limitations

  • No concurrency (handles one client at a time)
  • Basic request parsing (strstr)
  • No support for POST/PUT yet
  • No file serving
  • Not production-ready

🎯 Future Improvements

  • JSON responses
  • Better HTTP parsing
  • Support for POST requests
  • Multithreading
  • Static file serving
  • Routing system

πŸ“š Learning Goals

This project was built to understand:

  • How HTTP works under the hood
  • Socket programming in C
  • Client-server communication
  • Manual request/response handling

πŸ§‘β€πŸ’» Author

Igor Oliveira

About

A simple HTTP server built from scratch in C using low-level socket programming.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages