Class TeenyHttpd
java.lang.Object
net.jonathangiles.tools.teenyhttpd.TeenyHttpd
public class TeenyHttpd extends Object
The TeenyHttpd server itself - instantiating an instance of this class and calling 'start()' is all that is required
to begin serving requests.
-
Constructor Summary
Constructors Constructor Description TeenyHttpd(int port)Creates a single-threaded server that will work on the given port, although the server does not start until 'stort()' is called.TeenyHttpd(int port, Supplier<? extends ExecutorService> executorSupplier)Creates a server that will work on the given port, although the server does not start until 'stort()' is called. -
Method Summary
Modifier and Type Method Description Responseserve(Request request)This method is called on every request, and allows for responses to be generated as appropriate.voidsetWebroot(File webroot)Sets the root directory to look for requested files.voidstart()Starts the server instance.voidstop()Requests that the server instance stop serving requests.
-
Constructor Details
-
TeenyHttpd
public TeenyHttpd(int port)Creates a single-threaded server that will work on the given port, although the server does not start until 'stort()' is called.- Parameters:
port- The port for the server to listen to.
-
TeenyHttpd
Creates a server that will work on the given port, although the server does not start until 'stort()' is called. The executor supplier enables creatingExecutorServiceinstances that can handle requests with a range of different threading models.- Parameters:
port- The port for the server to listen to.executorSupplier- AExecutorServiceinstances that can handle requests with a range of different threading models.
-
-
Method Details
-
setWebroot
Sets the root directory to look for requested files.- Parameters:
webroot- A path on the local file system for serving requested files from.
-
start
public void start()Starts the server instance. -
stop
public void stop()Requests that the server instance stop serving requests. -
serve
This method is called on every request, and allows for responses to be generated as appropriate.- Parameters:
request- The incoming request that must be responded to.- Returns:
- The response that will be given to the requestor.
-