Skip to content

shorya-1012/http_server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple HTTP Server in C++

This is a basic Multi-Threaded HTTP Server implemented from scratch in C++ with support for serving HTML, plain text, and CSS files.

Features

  • Handle multiple routes
  • Implements Multi-Threading using a Thread Pool.
  • Serve static HTML and CSS files
  • Send plain text responses

Build Instructions

  1. Clone the repository:
git clone https://github.com/shorya-1012/http_server.git
cd http-server
  1. Build the project using CMake:
mkdir build && cd build
cmake ..
make
  1. Run the server:
./server
  1. Open your browser and navigate to:
  • http://localhost:8080/

Example Main Function

int main(int argc, char *argv[]) {
  Server server;

  server.add_routes("/", [](HttpRequest &req, HttpResponse &res) {
    res.send_html(200, "../templates/index.html");
  });

  server.add_routes("/about", [](HttpRequest &req, HttpResponse &res) {
    res.send_text(200, "Welcome to About Page");
  });

  server.add_routes("/foo", [](HttpRequest &req, HttpResponse &res) {
    res.send_text(200, "BAR");
  });

  server.run(8080);
  return 0;
}

Dependencies

No external dependencies. Uses only standard C++ and POSIX system calls (socket, fork, read, write, etc.).

About

A HTTP Server made from scratch in C++.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors