Skip to content

yus-works/tcp-to-http

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

77 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HTTP Server from TCP

A custom HTTP/1.1 server implementation built using raw TCP sockets in Go, without using the standard library's net/http package.

Features

  • HTTP/1.1 request parsing (request line, headers, body)
  • Concurrent connection handling
  • Custom routing with handler functions
  • Support for GET, POST, PUT, DELETE, OPTIONS methods
  • Content-Length based body parsing
  • Graceful shutdown handling

Project Structure

├── cmd/main.go                # Server entry point
└── internal/
    ├── request/               # HTTP request parsing
    ├── response/              # HTTP response building
    ├── headers/               # Header parsing and handling
    └── server/                # TCP server implementation

Running

go run cmd/main.go

Server runs on port 42069. Test with:

curl localhost:42069
curl localhost:42069/yourproblem  # Returns 400
curl localhost:42069/myproblem    # Returns 500

Testing

go test ./...

Technical Details

  • Parses HTTP requests byte-by-byte from TCP streams
  • Handles partial reads and buffering
  • Validates HTTP/1.1 protocol compliance
  • Implements proper CRLF line endings and header formatting

Dependencies

  • Standard library only (except testify for tests)
  • No net/http usage

About

Custom HTTP/1.1 server built from TCP sockets in Go

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published