Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TCPtoHTTP

A comprehensive HTTP/1.1 server implementation built from scratch in Go

Demonstrating deep understanding of network protocols, concurrent programming, and system design

Go HTTP TCP


This is my first go project done with of the tcp to http course on boot.dev. It is a nice course which gives insight in how to read http standards, work with the tools in go, and does not hold your hand to much troughout the lessons, it justs tells what features to implement, like a set of good issues

Alt Text

The following technical summary was generated with GitHub Copilot to showcase the implementation details of this custom HTTP server project.

Features Implemented

Core HTTP Server
Feature Description
Custom TCP Server Built on raw TCP connections without using Go's net/http package
HTTP/1.1 Protocol Compliance Full implementation of HTTP request/response parsing and formatting
Concurrent Connection Handling Goroutine-based concurrent client handling
Graceful Shutdown Signal handling for clean server termination
HTTP Request Processing
  • State Machine Parser: Robust HTTP request parser with proper state management
  • Request Line Parsing: Method, path, and HTTP version validation
  • Header Processing: Case-insensitive header parsing with duplicate header support
  • Body Handling: Content-Length based body parsing with buffer management
  • Chunked Transfer Encoding: Support for parsing chunked request bodies
HTTP Response Generation
  • State-Based Writer: HTTP response writer with enforced write order (status → headers → body)
  • Multiple Content Types: Support for HTML, video (MP4), and plain text responses
  • Custom Status Codes: Implementation of 200, 400, 404, and 500 responses
  • Header Management: Dynamic header generation with proper Content-Length calculation
Advanced HTTP Features
  • Chunked Transfer Encoding: Full implementation of chunked response encoding
  • HTTP Trailers: Support for trailers after chunked body (SHA-256 hash, content length)
  • Proxy Functionality: HTTP proxy implementation with request forwarding
  • Content Streaming: Efficient streaming of large responses with configurable chunk sizes
Quality Assurance
  • Comprehensive Testing: Unit tests covering request parsing, header handling, and edge cases
  • Error Handling: Robust error handling throughout the HTTP pipeline
  • Memory Management: Efficient buffer management to prevent memory leaks
  • Protocol Validation: Strict adherence to HTTP/1.1 specification

📁 Project Structure

📂 TCPtoHTTP/
├── 📂 cmd/
│   ├── 🌐 httpserver/     # Main HTTP server implementation
│   ├── 👂 tcplistener/    # Basic TCP listener for debugging
│   └── 📡 udpsender/      # UDP client utility
│
├── 📂 internal/
│   ├── 🖥️  server/         # TCP server and connection management
│   ├── 📥 request/        # HTTP request parsing and validation
│   ├── 📤 response/       # HTTP response writing and formatting
│   └── 📋 headers/        # HTTP header processing utilities
│
└── 📂 assets/            # Static files (videos, etc.)

🛠️ Key Technical Implementations

🔧 Core Systems

  • 🔄 Buffer Management: Dynamic buffer resizing for variable-length HTTP messages
  • 🤖 State Machines: Clean state-based parsing for requests and responses
  • 🔐 SHA-256 Trailers: Cryptographic content verification via HTTP trailers

🌐 Network Features

  • 🔄 Proxy Handler: Transparent HTTP proxy with chunked encoding preservation
  • 🎥 Video Streaming: MP4 file serving with proper MIME type headers
  • 📊 Content Negotiation: Multiple response formats and status codes

🧪 Testing & Validation

Test Type Implementation
🔧 Unit Tests Extensive coverage using testify framework
🌐 Network Simulation Chunk-based reading simulation for network conditions
⚠️ Edge Cases Malformed request and response handling
🔗 Integration Testing with real HTTP clients (curl, browsers)

💡 What This Project Showcases

graph TB
    A[🔧 Low-Level Networking] --> B[🌐 HTTP Protocol Mastery]
    B --> C[⚡ Concurrent Programming]
    C --> D[🏗️ System Architecture]
    D --> E[🧪 Testing]

    style A fill:#ff6b6b
    style B fill:#4ecdc4
    style C fill:#45b7d1
    style D fill:#96ceb4
    style E fill:#feca57
Loading

Advanced Go programming concepts: goroutines • channels • interfaces • state machines • low-level network programming


_Built from the ground up without relying on Go's standard `net/http` package_

About

Repo for the tcp to http in go course from boot.dev/thePrimeagen

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages