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
    Response serve​(Request request)
    This method is called on every request, and allows for responses to be generated as appropriate.
    void setWebroot​(File webroot)
    Sets the root directory to look for requested files.
    void start()
    Starts the server instance.
    void stop()
    Requests that the server instance stop serving requests.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public 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. The executor supplier enables creating ExecutorService instances that can handle requests with a range of different threading models.
      Parameters:
      port - The port for the server to listen to.
      executorSupplier - A ExecutorService instances that can handle requests with a range of different threading models.
  • Method Details

    • setWebroot

      public void setWebroot​(File webroot)
      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

      public Response serve​(Request request)
      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.