{"id":48178930,"url":"https://github.com/marcocampos/tiny-http","last_synced_at":"2026-04-04T17:41:42.091Z","repository":{"id":294688747,"uuid":"987647065","full_name":"marcocampos/tiny-http","owner":"marcocampos","description":"A lightweight HTTP server written in Go that serves static files.","archived":false,"fork":false,"pushed_at":"2025-05-28T15:30:15.000Z","size":37,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-28T16:47:26.900Z","etag":null,"topics":["go","http","server","static"],"latest_commit_sha":null,"homepage":"https://github.com/marcocampos/tiny-http","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marcocampos.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-21T11:33:43.000Z","updated_at":"2025-05-28T15:30:20.000Z","dependencies_parsed_at":"2025-05-28T16:33:44.558Z","dependency_job_id":null,"html_url":"https://github.com/marcocampos/tiny-http","commit_stats":null,"previous_names":["marcocampos/tiny-http"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/marcocampos/tiny-http","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcocampos%2Ftiny-http","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcocampos%2Ftiny-http/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcocampos%2Ftiny-http/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcocampos%2Ftiny-http/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marcocampos","download_url":"https://codeload.github.com/marcocampos/tiny-http/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcocampos%2Ftiny-http/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31407648,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-04T10:20:44.708Z","status":"ssl_error","status_checked_at":"2026-04-04T10:20:06.846Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","http","server","static"],"created_at":"2026-04-04T17:41:41.480Z","updated_at":"2026-04-04T17:41:42.086Z","avatar_url":"https://github.com/marcocampos.png","language":"Go","readme":"# tiny-http\n\nA lightweight HTTP server written in Go that serves static files.\n\n\u003c!--toc:start--\u003e\n- [tiny-http](#tiny-http)\n  - [Features](#features)\n  - [Installation](#installation)\n  - [Usage](#usage)\n    - [Command Line](#command-line)\n    - [Command Line Options](#command-line-options)\n    - [Example](#example)\n  - [Architecture](#architecture)\n    - [Project Structure](#project-structure)\n    - [Key Components](#key-components)\n    - [Middleware](#middleware)\n  - [Security Features](#security-features)\n  - [Performance Optimizations](#performance-optimizations)\n  - [Testing](#testing)\n  - [Docker Support](#docker-support)\n  - [Contributing](#contributing)\n  - [License](#license)\n\n## Features\n\n- **Static File Serving**: Efficiently serves static files from a specified directory\n- **MIME Type Detection**: Automatically detects and sets appropriate Content-Type headers\n- **Directory Index**: Automatically serves `index.html` for directory requests\n- **Gzip Compression**: Compresses responses when supported by the client\n- **Security Headers**: Implements security best practices with proper headers\n- **Graceful Shutdown**: Handles shutdown signals gracefully with connection draining\n- **Request Logging**: Structured logging with configurable log levels\n- **Connection Keep-Alive**: Supports HTTP/1.1 persistent connections\n- **Regex-based Routing**: Flexible routing system with regex pattern support\n- **Middleware Pipeline**: Extensible middleware system for request/response processing\n- **Concurrent Request Handling**: Handles multiple connections concurrently\n- **Request Timeouts**: Prevents resource exhaustion with connection timeouts\n\n## Installation\n\n```bash\ngo get github.com/marcocampos/tiny-http\n```\n\n## Usage\n\n### Command Line\n\n```bash\n# Build the server\ngo build ./cmd/main.go\n\n# Run the server\n./main -directory ./static -port 8080 -hostname 0.0.0.0 -log-level info\n```\n\n### Command Line Options\n\n- `-directory` (required): Directory to serve files from\n- `-hostname`: Hostname or IP address to bind to (default: \"0.0.0.0\")\n- `-port`: Port to listen on (default: \"8080\")\n- `-log-level`: Log level - debug, info, warn, error (default: \"info\")\n\n### Example\n\n```bash\n# Serve files from the current directory on port 3000\n./main -directory . -port 3000\n\n# Serve with debug logging\n./main -directory ./public -log-level debug\n```\n\n## Architecture\n\n### Project Structure\n\n```\ntiny-http/\n├── cmd/\n│   ├── main.go                 # Entry point with CLI argument parsing and server setup\n│   └── main_test.go           # Integration tests for the main application\n├── internal/\n│   └── server/\n│       ├── handlers.go         # File serving handler with MIME type detection and security\n│       ├── handlers_test.go    # Tests for file handlers and static content serving\n│       ├── http.go            # HTTP request/response types and router implementation\n│       ├── http_test.go       # Tests for HTTP parsing and router functionality\n│       ├── middleware.go      # Request/response middleware (logging, gzip, security)\n│       ├── middleware_test.go # Tests for middleware components and pipeline\n│       ├── server.go          # Core HTTP server with connection handling and shutdown\n│       └── server_test.go     # Tests for server lifecycle and connection management\n├── static/\n│   └── index.html            # Default static content for testing and demonstration\n├── Dockerfile                # Container configuration for deployment\n├── go.mod                   # Go module dependencies and version management\n└── README.md               # Project documentation and usage instructions\n```\n\n### Key Components\n\n1. **HTTPServer**: Main server struct that manages connections and request handling\n2. **HTTPRouter**: Flexible router supporting both exact matches and regex patterns\n3. **FileHandler**: Handles static file serving with security checks\n4. **Middleware System**: Pluggable middleware for cross-cutting concerns\n\n### Middleware\n\nThe server includes several built-in middleware:\n\n- **BaseMiddleware**: Adds default headers and ensures proper response structure\n- **LoggingMiddleware**: Logs all requests and responses with timing information\n- **GzipMiddleware**: Compresses responses for supported clients\n- **SecurityMiddleware**: Adds security headers (can be enabled)\n- **CORSMiddleware**: Handles cross-origin requests (can be enabled)\n\n## Security Features\n\n- Path traversal protection\n- Secure default headers\n- Content-Type sniffing prevention\n- XSS protection headers\n- Configurable CORS support\n\n## Performance Optimizations\n\n- Concurrent connection handling with goroutines\n- Efficient file reading with proper buffer management\n- Smart gzip compression (skips already compressed formats)\n- Regex patterns compiled once and reused\n\n## Testing\n\nRun the comprehensive test suite:\n\n```bash\ngo test ./internal/server -v\n```\n\nThe test suite covers:\n\n- Router functionality (exact and regex matching)\n- HTTP request parsing\n- Middleware pipeline\n- File serving with various scenarios\n- Graceful shutdown behavior\n\n## Docker Support\n\nBuild and run with Docker:\n\n```bash\n# Build the image\ndocker build -t tiny-http .\n\n# Run the container\ndocker run -p 8080:8080 -v $(pwd)/static:/static tiny-http\n```\n\n## Contributing\n\nContributions are welcome! Please ensure:\n\n1. All tests pass\n2. Code follows Go best practices\n3. New features include appropriate tests\n4. Documentation is updated\n\n## License\n\nThis project is open source and available under the MIT License.\n\n---\nHappy Hacking!","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcocampos%2Ftiny-http","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarcocampos%2Ftiny-http","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcocampos%2Ftiny-http/lists"}