Skip to content

RayanMalki/tcptohttp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HTTP/1.1 Server over Raw TCP (Go)

Overview

This project implements a low-level HTTP/1.1 server written in Go using raw TCP sockets, without relying on Go’s standard net/http package.

It closely follows:

  • RFC 9110 – HTTP Semantics
  • RFC 9112 – HTTP/1.1 Protocol

The goal is to provide a standards-compliant and educational implementation of HTTP built directly on top of TCP.


Features

  • Full HTTP/1.1 request parsing

    • Request line, headers, body
    • Response/status line handling
  • Chunked transfer encoding

    • Supports streaming data using hexadecimal-sized chunks
    • Proper handling of chunked bodies and terminating chunk
  • Trailers for data integrity

    • Adds X-Content-SHA256 and X-Content-Length as HTTP trailers
    • Enables verification of streamed content
  • Proxy streaming mode

    • Routes under /httpbin/... forward live HTTP streams from https://httpbin.org
    • Acts as a basic HTTP proxy on top of the custom TCP server
  • Binary data streaming

    • Streams binary files (e.g. MP4 videos)
    • Uses correct Content-Type and Content-Length headers
  • Extensible architecture

    • Designed to integrate with a Node.js/TypeScript backend and a React frontend
    • Can be used as the “data plane” for monitoring/observability tools

Architecture

  • Transport layer: Raw TCP socket listener in Go
  • Protocol layer: HTTP/1.1 parsing (request line, headers, body, chunked encoding)
  • Application layer:
    • Static/binary file serving
    • Proxy routes (/httpbin/...)
    • Trailers and integrity metadata
flowchart LR
   subgraph CLIENT["Client Side"]
       C["Client (curl / browser)"]
   end

   subgraph GO["Go HTTP Server"]
       M["Server - main.go"]
       RP["Request Parser (package request)"]
       RW["Response Writer (package response)"]
       H["Handler Logic (myHandler)"]
       M --> RP --> RW --> H
   end

   subgraph EXT["External Service"]
       E["httpbin.org"]
   end

   C -- "TCP Request (HTTP/1.1)" --> M
   H -- "/httpbin/stream/x (proxy request)" --> E
   E -- "Chunked Body + Trailers" --> RW
   RW -- "Chunked Body + Trailers" --> C

Loading

Usage

Run the server

go run cmd/httpserver/main.go

By default, the server listens on:

localhost:42069

Test proxy streaming (raw chunked response)

echo -e "GET /httpbin/stream/100 HTTP/1.1\r\nHost: localhost:42069\r\nConnection: close\r\n\r\n" \
  | nc localhost 42069

Test binary data streaming (MP4)

Open your browser and navigate to:

http://localhost:42069/video/httptotcp.mp4

Author

Rayan Malki Software Engineering Student – École de technologie supérieure (ÉTS), Montréal

Passionate about: • Backend systems and distributed architectures • Networking and protocol design • Low-level programming and infrastructure tooling

About

No description, website, or topics provided.

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages