Skip to content

achnitreda/LocalServer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LocalServer

PROJECT STRUCTURE

/localserver
├── /src
│   ├── Main.java  
│   ├── /config
│   │   ├── ConfigLoader.java    
│   │   ├── ServerConfig.java     
│   │   └── RouteConfig.java 
│   ├── /core
│   │   ├── Server.java           
|   |   ├── ConnectionHandler.java
│   ├── /http
│   │   ├── Cookie.java           
│   │   ├── HttpRequest.java           
|   |   ├── HttpException.java
|   |   ├── HttpRequestParser.java
│   │   ├── HttpResponse.java  
│   │   ├── HttpStatus.java    
│   ├── /handlers
|   |   ├── CGIHandler.java   
│   │   ├── StaticFileHandler.java 
|   |   ├── UploadHandler.java   
|   |   ├── DeleteHandler.java  
|   |   ├── MultipartFile.java
|   |   ├── MultipartParser.java
│   ├── /session
│   │   ├── Session.java   
│   │   ├── SessionManager.java   
│   ├── /utils
│   │   ├── MimeTypes.java    
|   ├── /www
├── /cgi-bin
└── README.md

TEST:

siege testing:

chmod +x install_siege.sh
./install_siege.sh

chmod +x test_siege.sh

# Start server
make

./test_siege.sh

Test Everything:

Test 1: Static Files (GET)

curl http://localhost:8091/
# Should return index.html

Test : Simple POST

curl -X POST --data "test" http://localhost:8080/
# Returns 201 with "POST data received: 4 bytes"

Test 2: Sessions

# First request
curl -b cookies.txt -c cookies.txt http://localhost:8091/session
# Output: visits=1

# Second request
curl -b cookies.txt -c cookies.txt http://localhost:8091/session
# Output: visits=2

Test 3: File Upload (POST) and GET file content

echo "Hello integration" > test.txt
curl -F "file=@test.txt" http://localhost:8091/uploads
# Should return JSON with upload info

curl http://localhost:8091/uploads/test.txt
# ✅ (file content)

Test 4: File Delete (DELETE)

# First check file exists
ls build/uploads/test.txt

# Delete it
curl -X DELETE http://localhost:8091/uploads/test.txt
# Should return 204 No Content

# Verify deleted
ls build/uploads/test.txt
# Should show: No such file

Test 5: CGI Execution

curl http://localhost:8091/api/test.py
# Should return HTML with Python CGI output

curl "http://localhost:8091/api/test.py?name=Bob"
# Should show query string in output

Test 6: Method Validation

# Route "/" only allows GET
curl -X POST http://localhost:8091/
# Should return: 405 Method Not Allowed

Test 7: Multi-Port

# Test different ports
curl http://localhost:8091/
curl http://localhost:8092/
curl http://localhost:8099/
# All should work

Test 8: Test keep-alive and connection close:

(
  printf "GET / HTTP/1.1\r\nHost: localhost\r\n\r\n"
  sleep 2
  printf "GET /test.txt HTTP/1.1\r\nHost: localhost\r\n\r\n"
  sleep 2
  printf "GET /style.css HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n"
  sleep 1
) | nc localhost 8091

Expected output:

HTTP/1.1 200 OK
...
(response 1)

HTTP/1.1 200 OK
...
(response 2)

HTTP/1.1 200 OK
...
(response 3)

Expected server logs:

[KEEP-ALIVE] Connection kept open for next request
[KEEP-ALIVE] Connection kept open for next request
[CONNECTION] Closing as requested by client

Testing Your Virtual Hosting:

# Test 1: goats.com:
curl --resolve goats.com:8080:127.0.0.1 http://goats.com:8080/

# Test 2: test:
curl --resolve test:8080:127.0.0.1 http://test:8080/

# Test 3: Unknown host (uses default):
curl --resolve unknown.com:8080:127.0.0.1 http://unknown.com:8080/

About

HTTP server in Java featuring non-blocking I/O, CGI execution, chunked encoding, session management, and robust security protections. Siege-tested at 99.5%+ availability.

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors