Skip to content

A simple HTTP/1.1 server implemented from scratch in Go using the net package. Handles multiple connections with goroutines, supports chunked transfer encoding, and can serve text or binary data.

Notifications You must be signed in to change notification settings

dibakarghosh03/httpfromtcp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

βš™οΈ Go HTTP/1.1 Server (Built from Scratch)

A minimal yet functional HTTP/1.1 server implemented from scratch in Go, using only the standard net package. This project was built to understand the internals of HTTP and TCP, following RFC 9110 (HTTP Semantics) and RFC 9112 (HTTP/1.1).


πŸš€ Features

  • πŸ”Œ Built using raw TCP sockets
  • βš™οΈ Compliant with HTTP/1.1 semantics
  • 🧡 Concurrent client handling using goroutines
  • πŸ“¦ Chunked Transfer Encoding support (streamed responses)
  • πŸ–ΌοΈ Binary data support β€” serves images, videos, etc.
  • πŸ“ Request parsing and response generation from scratch

🧠 Motivation

The goal of this project was to:

  • Deeply understand how HTTP actually works under the hood
  • Explore Go’s low-level networking capabilities (net package)
  • Learn how HTTP messages are parsed, formatted, and transmitted over TCP

βš™οΈ How It Works

  1. The server listens on a TCP port (default :42069)
  2. Accepts incoming TCP connections
  3. Spawns a goroutine per client connection
  4. Parses:
    • Request line (GET /index.html HTTP/1.1)
    • Headers
    • Optional body
  5. Sends a valid HTTP/1.1 response, using:
    • Content-Length (for known sizes)
    • or Transfer-Encoding: chunked (for streaming)
  6. Supports binary and text responses
  7. Closes the connection

πŸ“š References


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

Dibakar Ghosh πŸ”— GitHub Profile

About

A simple HTTP/1.1 server implemented from scratch in Go using the net package. Handles multiple connections with goroutines, supports chunked transfer encoding, and can serve text or binary data.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages