Skip to content

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HTTP Server from Scratch (Go)

A low-level HTTP/1.1 server and parser built from scratch using pure TCP sockets in Go — no net/http, no frameworks.

🚀 Overview

This project explores how HTTP actually works under the hood by implementing:

  • TCP server using net.Listen
  • Byte-level stream processing
  • Custom HTTP request parsing
  • Basic HTTP response handling

Instead of relying on abstractions, this project treats everything as a stream of bytes, helping you deeply understand networking fundamentals.

🧠 Key Concepts

  • TCP vs UDP: Reliable, ordered data transmission
  • Streams: Files and network connections as byte streams
  • HTTP Protocol:
    • Request line (GET /path HTTP/1.1)
    • Headers (key-value pairs)
    • Body parsing (Content-Length, etc.)
  • Parsing: Converting raw text into structured data

⚙️ How It Works

Client (curl/browser)
↓
TCP Connection
↓
Read byte stream
↓
Parse HTTP request
↓
Generate response
↓
Send back over TCP

🛠️ Run the Server

go run cmd/httpserver/main.go

In another terminal:

curl http://localhost:42069

📌 Features

  • Read data byte-by-byte from TCP connections
  • Line-based stream parsing using Go interfaces
  • Custom HTTP request parser (start line, headers, body)
  • Works with raw HTTP requests (via curl or netcat)

🎯 Learning Goals

  • Understand how HTTP is built on TCP
  • Learn how data is streamed and parsed
  • Build intuition for protocols and system design
  • Transition from “library user” → “system builder”

⚠️ Limitations

  • Minimal HTTP compliance
  • No concurrency optimizations
  • No TLS / HTTP2 / HTTP3 support
  • Designed for learning, not production

📚 References

  • RFC 9110 (HTTP Semantics)
  • RFC 9112 (HTTP/1.1)
  • Go net package

🙌 Acknowledgment

Inspired by hands-on systems learning approaches focused on building everything from first principles.

About

Built a low-level HTTP/1.1 server in Go from scratch using raw TCP sockets. Parses byte streams into structured requests without external libraries, demonstrating deep understanding of networking, protocols, and systems fundamentals.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages