<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Salaheddine Hali</title>
    <description>The latest articles on DEV Community by Salaheddine Hali (@salaheddinee).</description>
    <link>https://dev.to/salaheddinee</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3912167%2F89e67724-ab29-4284-a127-1d6e6cd9b92c.jpg</url>
      <title>DEV Community: Salaheddine Hali</title>
      <link>https://dev.to/salaheddinee</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/salaheddinee"/>
    <language>en</language>
    <item>
      <title>Building a Web Server from Scratch in C++: Server Architecture, HTTP Parsing &amp; Methods</title>
      <dc:creator>Salaheddine Hali</dc:creator>
      <pubDate>Fri, 24 Jul 2026 19:49:15 +0000</pubDate>
      <link>https://dev.to/salaheddinee/building-a-web-server-from-scratch-in-c-server-architecture-http-parsing-methods-2nld</link>
      <guid>https://dev.to/salaheddinee/building-a-web-server-from-scratch-in-c-server-architecture-http-parsing-methods-2nld</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftfl7h5l7jhttqy3f4ybl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftfl7h5l7jhttqy3f4ybl.png" alt=" " width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Introduction&lt;/p&gt;

&lt;p&gt;Every day, we type a URL into a browser without thinking about what actually happens behind the scenes. A single click triggers a fascinating chain of events: establishing a TCP connection, parsing an HTTP request, routing it to the correct handler, generating a response, and sending it back to the client—all within milliseconds.&lt;/p&gt;

&lt;p&gt;As part of the 42 School Webserv project, my team and I decided to build an HTTP server completely from scratch in C++98. No web frameworks. No Boost. No existing HTTP libraries. Just low-level sockets, the C++ standard library, and a deep dive into how the web actually works.&lt;/p&gt;

&lt;p&gt;The goal wasn't just to create another server—it was to understand every layer involved in serving a web page. From creating sockets and accepting client connections to parsing raw HTTP requests, implementing GET, POST, and DELETE methods, serving static files, handling CGI, and generating valid HTTP responses, every component had to be designed and implemented by us.&lt;/p&gt;

&lt;p&gt;This project completely changed the way I think about web applications. Before starting, a browser request felt almost magical. Now I understand the complete lifecycle of an HTTP request—from the moment it leaves the browser until the server sends back the response.&lt;/p&gt;

&lt;p&gt;In this article, I'll walk through the architecture of our server, explain how HTTP requests are parsed, how different HTTP methods are handled, and share some of the engineering challenges we faced while building everything from the ground up.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Project Overview&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The objective is to build a fully functional HTTP/1.1 web server from scratch using C++98, without relying on existing web server implementations or HTTP libraries.&lt;/p&gt;

&lt;p&gt;Instead of using mature solutions like Nginx or Apache, we had to implement the fundamental building blocks ourselves. This includes creating TCP sockets, accepting multiple client connections, parsing raw HTTP requests, serving static content, executing CGI scripts, handling file uploads, and generating standards-compliant HTTP responses.&lt;/p&gt;

&lt;p&gt;Our implementation follows an event-driven architecture capable of managing multiple clients simultaneously using I/O multiplexing. Every incoming request passes through several stages before a response is returned to the client.&lt;/p&gt;

&lt;p&gt;The project is composed of several independent components working together:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Configuration Parser – Reads and validates the server configuration file.
TCP Server – Creates listening sockets, binds to ports, and accepts incoming client connections.
Event Loop – Monitors multiple sockets efficiently using I/O multiplexing.
HTTP Request Parser – Converts raw bytes received from the network into structured HTTP requests.
Router – Determines which server block and location should process the request.
HTTP Method Handlers – Implements the behavior of GET, POST, and DELETE requests.
Static File Server – Serves HTML, CSS, JavaScript, images, and other resources.
CGI Executor – Executes external scripts and returns their output as HTTP responses.
Response Builder – Constructs valid HTTP responses, including status codes, headers, and body content.
Error Handling – Generates appropriate HTTP error pages such as 404 Not Found, 403 Forbidden, and 500 Internal Server Error.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At a high level, every request follows the same lifecycle:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Browser
    │
    ▼
TCP Connection
    │
    ▼
HTTP Request Parser
    │
    ▼
Router
    │
    ▼
HTTP Method (GET / POST / DELETE)
    │
    ├──────────────┐
    ▼              ▼
Static Files      CGI
    │              │
    └──────┬───────┘
           ▼
Response Builder
           │
           ▼
HTTP Response
           │
           ▼
Browser
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Rather than focusing only on making the server work, our goal was to understand how modern web servers operate internally. Building each component from scratch gave us a much deeper understanding of networking, the HTTP protocol, operating system concepts, and software architecture.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Server Architecture&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before implementing HTTP methods or parsing requests, we first needed a solid server architecture. A web server is much more than a single loop waiting for incoming requests—it's a collection of independent components working together to transform raw network data into valid HTTP responses.&lt;/p&gt;

&lt;p&gt;To keep the project modular and maintainable, we separated the server into multiple layers, each responsible for a single task.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                     +----------------------+
                     |      Browser         |
                     +----------+-----------+
                                |
                                | HTTP Request
                                |
                                ▼
                   +-------------------------+
                   |     TCP Socket Layer    |
                   | socket() / bind()       |
                   | listen() / accept()     |
                   +-----------+-------------+
                               |
                               ▼
                  +--------------------------+
                  |     Event Loop           |
                  | poll() / multiplexing    |
                  +-----------+--------------+
                              |
                              ▼
                  +--------------------------+
                  |   HTTP Request Parser    |
                  +-----------+--------------+
                              |
                              ▼
                  +--------------------------+
                  |         Router           |
                  +-----------+--------------+
                              |
             +----------------+----------------+
             |                |                |
             ▼                ▼                ▼
        GET Handler      POST Handler    DELETE Handler
             |                |                |
             +----------------+----------------+
                              |
                              ▼
                 +--------------------------+
                 |   Response Builder       |
                 +-----------+--------------+
                             |
                             ▼
                     HTTP Response
                             |
                             ▼
                          Browser

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;1. TCP Socket Layer&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Everything begins with the networking layer.&lt;/p&gt;

&lt;p&gt;The server creates one or more listening sockets using the operating system's socket API.&lt;/p&gt;

&lt;p&gt;The lifecycle follows the classic sequence:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;socket()
   ↓
bind()
   ↓
listen()
   ↓
accept()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each function has a specific responsibility:&lt;/p&gt;

&lt;p&gt;socket() creates a communication endpoint.&lt;br&gt;
bind() associates that socket with an IP address and a port.&lt;br&gt;
listen() tells the kernel that the socket is ready to accept incoming connections.&lt;br&gt;
accept() creates a new client socket for every connected browser while keeping the listening socket available for future clients.&lt;/p&gt;

&lt;p&gt;At this stage, the server still has no knowledge of HTTP—it only deals with raw TCP connections.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Event Loop&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Instead of creating one thread per client, our server uses an event-driven architecture.&lt;/p&gt;

&lt;p&gt;The event loop continuously monitors all active sockets using I/O multiplexing (poll() in our implementation).&lt;/p&gt;

&lt;p&gt;This allows a single process to manage many simultaneous clients efficiently.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;while (server is running)
{
    wait for socket events;

    if (new client)
        accept();

    if (client sent data)
        read request();

    if (socket ready to write)
        send response();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This design is lightweight, scalable, and forms the foundation of many high-performance web servers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. HTTP Request Parser&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once data arrives from a client socket, it is simply a sequence of bytes.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="nf"&gt;GET&lt;/span&gt; &lt;span class="nn"&gt;/index.html&lt;/span&gt; &lt;span class="k"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="m"&gt;1.1&lt;/span&gt;
&lt;span class="na"&gt;Host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;localhost&lt;/span&gt;
&lt;span class="na"&gt;User-Agent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Chrome&lt;/span&gt;
&lt;span class="na"&gt;Connection&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;keep-alive&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The parser transforms this raw text into a structured object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HttpRequest
{
    method  = GET;
    path    = "/index.html";
    version = "HTTP/1.1";
    headers = {...};
    body    = "";
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Having a structured request object makes every subsequent component independent from the networking layer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Router&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The router decides which part of the server should handle the request.&lt;/p&gt;

&lt;p&gt;It examines information such as:&lt;/p&gt;

&lt;p&gt;Requested URI&lt;br&gt;
Server block&lt;br&gt;
Location block&lt;br&gt;
HTTP method&lt;br&gt;
Configuration rules&lt;/p&gt;

&lt;p&gt;Depending on the request, it may choose to:&lt;/p&gt;

&lt;p&gt;Serve a static file&lt;br&gt;
Execute a CGI script&lt;br&gt;
Upload a file&lt;br&gt;
Delete a resource&lt;br&gt;
Return an error page&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. HTTP Method Handlers&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Each supported HTTP method is implemented independently.&lt;/p&gt;

&lt;p&gt;This separation makes the code easier to maintain and extend.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET
│
├── Validate request
├── Resolve file path
├── Read file
└── Build HTTP response
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;POST
│
├── Validate request
├── Read body
├── Save uploaded file
└── Return success response
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DELETE
│
├── Validate request
├── Locate resource
├── Delete file
└── Return status response
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each handler is responsible only for its own business logic.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Response Builder&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Regardless of which handler processes the request, the final step is always the same: generating a valid HTTP response.&lt;/p&gt;

&lt;p&gt;A typical response contains:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="k"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="m"&gt;1.1&lt;/span&gt; &lt;span class="m"&gt;200&lt;/span&gt; &lt;span class="ne"&gt;OK&lt;/span&gt;
&lt;span class="na"&gt;Content-Type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;text/html&lt;/span&gt;
&lt;span class="na"&gt;Content-Length&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;1024&lt;/span&gt;
&lt;span class="na"&gt;Connection&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;keep-alive&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
...
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The response builder is responsible for:&lt;/p&gt;

&lt;p&gt;Choosing the correct status code.&lt;br&gt;
Generating HTTP headers.&lt;br&gt;
Calculating Content-Length.&lt;br&gt;
Setting the appropriate Content-Type.&lt;br&gt;
Appending the response body.&lt;br&gt;
Why This Architecture?&lt;/p&gt;

&lt;p&gt;We intentionally designed the project around separation of responsibilities.&lt;/p&gt;

&lt;p&gt;Each component has a single purpose:&lt;/p&gt;

&lt;p&gt;The networking layer only manages TCP connections.&lt;br&gt;
The parser only understands HTTP syntax.&lt;br&gt;
The router only decides where requests should go.&lt;br&gt;
Method handlers implement application logic.&lt;br&gt;
The response builder constructs HTTP-compliant responses.&lt;/p&gt;

&lt;p&gt;This modular architecture made the project easier to debug, extend, and maintain, while closely reflecting the internal design of production-grade web servers such as Nginx and Apache.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. From Browser to Response: The Complete HTTP Request Lifecycle&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;At this point, we have explored the different components that make up our web server. The next step is to understand how these components interact when a browser sends an HTTP request.&lt;/p&gt;

&lt;p&gt;Although the process happens in just a few milliseconds, several independent layers collaborate before the browser finally receives a response.&lt;/p&gt;

&lt;p&gt;The following diagram illustrates the complete request lifecycle implemented in our server.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;┌──────────────┐
│   Browser    │
└──────┬───────┘
       │
       │  GET /index.html HTTP/1.1
       ▼
┌──────────────────────────────┐
│ TCP Connection Established   │
│ socket → accept()            │
└──────────────┬───────────────┘
               │
               ▼
┌──────────────────────────────┐
│ Receive Raw Bytes            │
│ recv()                       │
└──────────────┬───────────────┘
               │
               ▼
┌──────────────────────────────┐
│ HTTP Request Parser          │
│ Method │ URI │ Headers │ Body│
└──────────────┬───────────────┘
               │
               ▼
┌──────────────────────────────┐
│ Router                       │
│ Match Server &amp;amp; Location      │
└──────────────┬───────────────┘
               │
      ┌────────┴─────────┐
      │                  │
      ▼                  ▼
 Static File         CGI Script
      │                  │
      └────────┬─────────┘
               ▼
┌──────────────────────────────┐
│ HTTP Method Handler          │
│ GET / POST / DELETE          │
└──────────────┬───────────────┘
               │
               ▼
┌──────────────────────────────┐
│ Response Builder             │
│ Status │ Headers │ Body      │
└──────────────┬───────────────┘
               │
               ▼
┌──────────────────────────────┐
│ send()                       │
└──────────────┬───────────────┘
               │
               ▼
        Browser Receives Page
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 1 — The Browser Sends an HTTP Request&lt;/strong&gt;&lt;br&gt;
Everything begins when the user enters a URL into the browser.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="nf"&gt;GET&lt;/span&gt; &lt;span class="nn"&gt;/index.html&lt;/span&gt; &lt;span class="k"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="m"&gt;1.1&lt;/span&gt;
&lt;span class="na"&gt;Host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;localhost:8080&lt;/span&gt;
&lt;span class="na"&gt;User-Agent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Chrome&lt;/span&gt;
&lt;span class="na"&gt;Accept&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;text/html&lt;/span&gt;
&lt;span class="na"&gt;Connection&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;keep-alive&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At this stage, the browser doesn't send an object or a function call. It simply sends a stream of bytes over an established TCP connection.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2 — The Server Accepts the Connection&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Our listening socket continuously waits for new incoming connections.&lt;/p&gt;

&lt;p&gt;When a client connects, the operating system creates a new socket dedicated to that client.&lt;/p&gt;

&lt;p&gt;The listening socket remains available to accept future connections, while the new client socket is used for all communication with that specific browser.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3 — Receiving Raw Data&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The server reads data from the client socket using recv().&lt;/p&gt;

&lt;p&gt;Initially, the received data is nothing more than raw text.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="nf"&gt;GET&lt;/span&gt; &lt;span class="nn"&gt;/index.html&lt;/span&gt; &lt;span class="k"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="m"&gt;1.1&lt;/span&gt;
&lt;span class="na"&gt;Host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;localhost&lt;/span&gt;
&lt;span class="s"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At this point, the server still doesn't know where the request should go or what action needs to be performed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4 — Parsing the Request&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The parser analyzes the raw HTTP message and extracts every important component.&lt;/p&gt;

&lt;p&gt;It converts the incoming bytes into a structured object similar to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HttpRequest
{
    method  = GET;
    path    = "/index.html";
    version = "HTTP/1.1";
    headers = {...};
    body    = "";
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From this point onward, every module works with structured data instead of raw network bytes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5 — Routing the Request&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once the request has been parsed, the router determines how it should be processed.&lt;/p&gt;

&lt;p&gt;Based on the requested URI and the server configuration, it decides whether the request should:&lt;/p&gt;

&lt;p&gt;Serve a static file&lt;br&gt;
Execute a CGI program&lt;br&gt;
Upload data&lt;br&gt;
Delete a resource&lt;br&gt;
Return an error page&lt;/p&gt;

&lt;p&gt;This layer separates request interpretation from request execution.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 6 — Executing the HTTP Method&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The router forwards the request to the appropriate HTTP method handler.&lt;/p&gt;

&lt;p&gt;For example, a GET request follows a workflow similar to this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET Request
     │
     ▼
Validate HTTP Method
     │
     ▼
Validate Request URI
     │
     ▼
Resolve Target Path
     │
     ▼
Check File Existence
     │
     ├── File Found ───────────────► Read File
     │                                │
     │                                ▼
     │                         Detect Content-Type
     │                                │
     │                                ▼
     │                      Build HTTP 200 Response
     │
     └── File Not Found ─────────────► Build HTTP 404 Response

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The same principle applies to POST and DELETE, each implementing its own validation and business logic.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 7 — Building the HTTP Response&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Regardless of which handler processes the request, every execution ends by constructing a valid HTTP response.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="k"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="m"&gt;1.1&lt;/span&gt; &lt;span class="m"&gt;200&lt;/span&gt; &lt;span class="ne"&gt;OK&lt;/span&gt;
&lt;span class="na"&gt;Content-Type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;text/html&lt;/span&gt;
&lt;span class="na"&gt;Content-Length&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;512&lt;/span&gt;
&lt;span class="na"&gt;Connection&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;keep-alive&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
    ...
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The response builder ensures that the client receives a standards-compliant HTTP message, complete with the correct status line, headers, and body.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 8 — Sending the Response&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Finally, the server transmits the response back to the client using send().&lt;/p&gt;

&lt;p&gt;Once the browser receives the response, it begins rendering the HTML document, downloading additional resources such as CSS, JavaScript, and images, and displaying the page to the user.&lt;/p&gt;

&lt;p&gt;From the user's perspective, the page appears almost instantly. Behind the scenes, however, it has passed through every layer of our web server—from the TCP socket to the HTTP parser, router, method handler, and response builder.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>#1</title>
      <dc:creator>Salaheddine Hali</dc:creator>
      <pubDate>Thu, 16 Jul 2026 18:08:01 +0000</pubDate>
      <link>https://dev.to/salaheddinee/1-2eih</link>
      <guid>https://dev.to/salaheddinee/1-2eih</guid>
      <description>&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/iarchitsharma/http-request-and-response-explained-46l2" class="crayons-story__hidden-navigation-link"&gt;HTTP Request and Response explained&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/iarchitsharma" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F676134%2F61430b7f-13be-4572-8ed5-4ba8f732386f.JPG" alt="iarchitsharma profile" class="crayons-avatar__image" width="536" height="573"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/iarchitsharma" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Archit Sharma
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Archit Sharma
                
              
              &lt;div id="story-author-preview-content-2964345" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/iarchitsharma" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F676134%2F61430b7f-13be-4572-8ed5-4ba8f732386f.JPG" class="crayons-avatar__image" alt="" width="536" height="573"&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Archit Sharma&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/iarchitsharma/http-request-and-response-explained-46l2" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Oct 30 '25&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/iarchitsharma/http-request-and-response-explained-46l2" id="article-link-2964345"&gt;
          HTTP Request and Response explained
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/webdev"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;webdev&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/http"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;http&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/beginners"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;beginners&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/security"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;security&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://dev.to/iarchitsharma/http-request-and-response-explained-46l2" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/fire-f60e7a582391810302117f987b22a8ef04a2fe0df7e3258a5f49332df1cec71e.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/raised-hands-74b2099fd66a39f2d7eed9305ee0f4553df0eb7b4f11b01b6b1b499973048fe5.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;10&lt;span class="hidden s:inline"&gt;&amp;nbsp;reactions&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://dev.to/iarchitsharma/http-request-and-response-explained-46l2#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              

              &lt;span class="hidden s:inline"&gt;Add&amp;nbsp;Comment&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            5 min read
          &lt;/small&gt;
            
              &lt;span class="bm-initial crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
              &lt;span class="bm-success crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
            
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;


</description>
    </item>
    <item>
      <title>Inception-42 Building a Full Backend Infrastructure with Docker (Nginx, MariaDB, Redis)</title>
      <dc:creator>Salaheddine Hali</dc:creator>
      <pubDate>Mon, 04 May 2026 13:55:41 +0000</pubDate>
      <link>https://dev.to/salaheddinee/building-a-full-backend-infrastructure-with-docker-nginx-mariadb-redis-h61</link>
      <guid>https://dev.to/salaheddinee/building-a-full-backend-infrastructure-with-docker-nginx-mariadb-redis-h61</guid>
      <description>&lt;p&gt;As part of my journey in backend development, I built a complete infrastructure using Docker and Docker Compose. The goal was to simulate a real-world production environment with multiple services working together.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Architecture&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This project is composed of several services:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Nginx&lt;/strong&gt; → Reverse proxy &amp;amp; web server&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MariaDB&lt;/strong&gt; → Database&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Redis&lt;/strong&gt; → Caching system&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;FTP Server&lt;/strong&gt; → File management&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Adminer&lt;/strong&gt; → Database interface&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Portainer&lt;/strong&gt; → Container management&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each service runs in its own container, ensuring isolation and scalability.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Docker?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Docker allows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Isolation between services&lt;/li&gt;
&lt;li&gt;Easy debugging (if one service fails, others stay running)&lt;/li&gt;
&lt;li&gt;Reproducible environments&lt;/li&gt;
&lt;li&gt;Scalability for future improvements&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Challenges I Faced&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Configuring Nginx to handle multiple services&lt;/li&gt;
&lt;li&gt;Managing environment variables securely&lt;/li&gt;
&lt;li&gt;Connecting containers via Docker networks&lt;/li&gt;
&lt;li&gt;Optimizing performance under load&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;What I Learned&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How reverse proxies work (Nginx)&lt;/li&gt;
&lt;li&gt;Managing multi-container applications&lt;/li&gt;
&lt;li&gt;Basics of system design&lt;/li&gt;
&lt;li&gt;Debugging distributed systems&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Testing &amp;amp; Performance&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I tested the system by simulating multiple requests and checking how the server behaves under load.&lt;/p&gt;

&lt;p&gt;Key point:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Each worker in Nginx can handle multiple connections, but bad configuration can lead to bottlenecks.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This project helped me understand how real backend systems are structured and deployed. It’s a big step toward building scalable and production-ready applications.&lt;/p&gt;

&lt;p&gt;Project Link&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/Trojalarick/Inception" rel="noopener noreferrer"&gt;https://github.com/Trojalarick/Inception&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next step: Improving scalability and handling high traffic (10k+ requests)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcdy5svv4134qkcxz7s45.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcdy5svv4134qkcxz7s45.png" alt=" " width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>docker</category>
      <category>devops</category>
      <category>backend</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
