Skip to content

MatheusBenestorff/Torff

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Torff Web Server

A custom HTTP Web Server and Reverse Proxy built in pure C# to demystify how web servers and gateways work under the hood.

About the Project

Torff was born from the desire to understand the fundamental mechanics of the web. Instead of relying on robust, production-ready servers like Kestrel, IIS, or Nginx, this project takes a step back to the basics.

By utilizing raw TCP Sockets (System.Net.Sockets) in pure C#, Torff handles everything manually: opening network ports, listening for incoming connections, parsing raw HTTP text requests, routing, and building formatted HTTP responses.

Torff also acts as an API Gateway, capable of translating HTTP traffic into an internal protocol (TTP) to securely proxy requests to backend frameworks.

Architecture

/Torff
├── torff.json                 # Global configuration file 
├── Torff.sln                 
└── src/
    ├── Torff.Server/          # The Gateway / Web Server
    │   ├── Adapters/          # Translates HTTP <-> TTP
    │   ├── Config/            # JSON configuration loaders
    │   ├── Core/              # The heart of the server (TCP Listeners)
    │   ├── Http/              # HTTP Protocol logic
    │   ├── Routing/           # Static file serving and Proxy routing
    │   └── wwwroot/           # Public static files (HTML, CSS, Images)
    │
    └── Torff.Ttp/             # The Protocol Library
        ├── TtpRequest.cs      
        └── TtpResponse.cs     

What is TTP?

Torff Transfer Protocol (TTP) is a class library (.dll) acting as the contract between the Torff Gateway and custom web frameworks (Like 'BenCore'). It strips away the heavy text-parsing of standard HTTP, providing backend applications with clean, structured data for maximum efficiency in a microservices environment.

Configuration (torff.json)

You can tweak the server's behavior on the fly by editing the root JSON file:

{
  "Port": 8080,
  "WebRoot": "src/Torff.Server/wwwroot",
  "EnableKeepAlive": true,
  "TimeoutSeconds": 5,
  "EnableHttps": false,
  "CertificatePath": "torff-cert.pfx",
  "CertificatePassword": "senha123"
}

Getting Started

The easiest way to run Torff is by using Docker.

  • Start the server using Docker Compose:
docker-compose up --build
  • Open your browser and navigate to:

(Depending on your torff.json configuration)

HTTP: http://localhost:8080

HTTPS: https://localhost:5001 (Accept the self-signed dev certificate)

About

A custom HTTP Web Server built from scratch in pure C#.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors