Skip to content

shamalroy/SimpleWebServer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Web Server

A multi-threaded web server with thread-pooling implemented in Java.

Implemented features:

  • HTTP/1.1 keep-alive behavior is implemented based on the http-client's capabilities exposed through its request headers. The keep-alive behavior is implemented through Pre and Post Filters.

    • If a keep-alive header is identified in the KeepAlivePreFilter the keepAlive flag is set on the client socket and keep the inputStream open for subsequent requests until a request with no keep-alive header is received. If a request with no keep-alive header received the server stops reading from inputSteam and close the client socket after the request is served. A Connection:Keep-Alive response header is also added to the keep-alive requests using KeepAlivePostFilter.
  • Configuration using java properties file. The available configuration properties are:

bindAddress=127.0.0.1
port=3333
backlog=100
noOfThreadPool=10
docRoots=./doc-root1,./doc-root2
  • Filter chain: Pre Filters are invoked after the request received and Post Filters are invoked before the response is served. Chain of responsibility pattern is used to implement Filter chain. Each filter implements the doFilter() method. Currently implemented filters:

    • Pre Filter
      • KeepAlivePreFilter
    • Post Filter
      • KeepAlivePostFilter
      • ContentHeaderPostFilter
      • ServerHeaderPostFilter
  • Multiple doc roots support to serve contents from multiple directories in the filesystem.

  • HTTP Status code for the filesystem contents using custom Exception handing. Implemented codes are 200, 404, and 500.

How to run the server:

Build an executable jar file using maven package command (or use use the existing one in this github repo). Update the server-config.properties file with the correct configuration values. The doc-root1 folder contains some sample html and css files as well. Use the following terminal commands to run the jar.

mvn clean package
java -jar target/simplewebserver-1.0-SNAPSHOT.jar

After running the server you will see the welcome message with the server address to access the sample home page.

About

A Simple Web Server supports GET methods, multiple doc-roots, Keep-Alive, Pre/Post Filters, etc.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages