| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
A lightweight, HTTP/1.1-compliant web server implementation in Java built from scratch using non-blocking I/O. This project demonstrates understanding of network protocols, socket programming, and event-driven architecture without relying on established frameworks.
This is a custom HTTP server designed to be:
git clone <repository-url>
cd JAVA-LOCALSERVER./run.shThe server will compile and start automatically, listening on the ports configured in application.yml.
The server is configured via src/main/resources/application.yml. The configuration file uses YAML format to define servers, routes, and behavior.
servers:
- name: server1
hosts: [localhost]
ports: [8080, 8443]
default: true
clientMaxBodySize: 5MB
sessionId: session-id # Optional
errorPages:
403: /errors/403.html
404: /errors/404.html
500: /errors/500.html
routes:
- name: static-files
path: /files
methods: [GET]
root: /files
indexFile: index.html
directoryListing: true| Option | Type | Description |
|---|---|---|
| name | String | Server identifier |
| hosts | Array | Virtual host names (e.g., localhost, example.com) |
| ports | Array | Port numbers to listen on |
| default | Boolean | Whether this is the default server for its ports |
| clientMaxBodySize | String | Maximum request body size (e.g., 5MB, 10GB) |
| sessionId | String | Optional session ID validation |
| errorPages | Map | Custom error pages mapping status codes to paths |
| routes | Array | Route configurations |
| Option | Type | Description |
|---|---|---|
| name | String | Route identifier |
| path | String | URL path pattern |
| methods | Array | Allowed HTTP methods |
| root | String | Root directory for static files (relative to resources) |
| indexFile | String | Default file to serve for directories |
| directoryListing | Boolean | Enable/disable directory browsing |
| redirect | Object | Redirect configuration (status, to) |
| cgi | Object | CGI interpreter mapping (extension: path) |
- name: static-files
path: /files
methods: [GET]
root: /files
indexFile: index.html
directoryListing: true- name: python-scripts
path: /cgi-bin
methods: [GET, POST]
root: /scripts
cgi:
py: /usr/bin/python3
js: /usr/bin/node- name: old-path
path: /old-files
methods: [GET]
redirect:
status: 301
to: /new-filesWith the default configuration:
# Access files in /images directory
curl http://localhost:8080/images/photo.jpg
# Access files with directory listing
curl http://localhost:8080/files/Place your scripts in src/main/resources/scripts/:
# Execute Python CGI script
curl http://localhost:8081/python/script.py
# Execute Node.js CGI script
curl http://localhost:8081/nodejs/app.js
# POST request to CGI
curl -X POST -d "data=value" http://localhost:8081/cgi-bin/process.py# Server 1 (default server)
curl http://localhost:8080/gallery/
# Server 2 with specific host
curl -H "Host: test2.com" http://localhost:8081/python/
# Server 3 with redirect
curl -L http://localhost:8888/JAVA-LOCALSERVER/
src/main/java/com/http/
Main.java # Entry point
application/
Application.java # Main application class
configuration/ # Configuration parsing
connectors/ # Network I/O handling
router/ # Request routing
session/ # Session management
http/
request/ # HTTP request parsing
response/ # HTTP response generation
enums/ # HTTP enums (methods, status)
cookie/ # Cookie handling
url/ # URL parsing
utils/ # Utilities (MIME types, etc.)
src/main/resources/
application.yml # Server configuration
The server uses a single thread with Java NIO's Selector to handle multiple connections concurrently:
Client Connection → Read Handler → Header Parser → Chunk Parser → Request Parser → Router → Response Generation → Write Handler
The server has been tested using siege benchmark tool and achieves excellent performance:
Test 1: 50 concurrent users, 100 repetitions each (5000 transactions)
Transactions: 10000 hits Availability: 100.00 % Elapsed time: 6.34 secs Response time: 31.48 ms Transaction rate: 1577.29 trans/sec Throughput: 0.66 MB/sec Concurrency: 49.65 Failed transactions: 0
Test 2: 100 concurrent users, 200 repetitions each (20000 transactions)
Transactions: 20000 hits Availability: 100.00 % Elapsed time: 13.79 secs Response time: 51.87 ms Transaction rate: 1450.33 trans/sec Throughput: 1.22 MB/sec Concurrency: 75.23 Failed transactions: 0
# Basic benchmark test
siege -b -c 50 -r 100 http://localhost:8080/
# High concurrency stress test
siege -b -c 100 -r 200 http://localhost:8080/
# Timed test (30 seconds)
siege -b -t30s -c 50 http://localhost:8080/This server implements key HTTP/1.1 features:
Sessions are automatically managed via cookies. Configure per-server:
sessionId: my-session-idPrevent large uploads by setting limits:
clientMaxBodySize: 5MB # Supports KB, MB, GBMultiple servers can share ports with host-based routing:
servers:
- name: site1
hosts: [example.com]
ports: [80]
- name: site2
hosts: [test.com]
ports: [80]CGI scripts receive standard environment variables:
Change the port in application.yml or stop the conflicting service.
| Back | FazBrowse Home | New Git URL |