pong-server-0.0.4.4: A simple embedded pingable server that runs in the background.

Copyright(c) Robert Fischer 2017
LicenseUnlicense
Maintainersmokejumper+network.pong@gmail.com
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

Network.Pong

Description

This is an exceedingly simple server: it listens on the given port on all interfaces, and when it retrieves a connection, it simply prints out the result of the pongMessage action, which is just the four characters pong by default.

The purpose of this server is to provide something for automated smoke checks (such as load balancers) to hit against. It provides a rudimentary server smoke check while requiring a minimal amount of overhead.

There are two customary ways to use this server. The first customary way uses whether the response is empty or not to signal whether there is an error or not. If the resulting body is empty, there is an error. If the response is non-empty, the server is fine. This is supported by pongCatch. The second customary way to use this server is to treat it as a server running HTTP/0.9, and to use 200 response status codes to mean the server is good and 500 response status codes to mean the server is having a problem. This is supported by the pongCatchHttp and the other pong*Http* functions.

A third way to use this server is to have the body of the message actually contain some meaningful values about the state of the system. The reason the response is a ByteString is specifically so that you could implement a binary protocol if you deeply wanted to. If you are heading down that path, though, please first look into the ekg package. Keep Pong in play for automated smoke checks, and use ekg for more precise status monitoring.

To run this server, simply add this into your main function:

  main = withPongServer defaultPongConfig $ do

It will then run the pong server on port 10411. Of course, you can customize the server through the configuration object.

Synopsis

Documentation

type PongAction m = m ByteString Source #

This is the type of the response. It is mostly aliased to make type signatures more obvious.

type PongHttpAction m = m Status Source #

This is the type of the response for HTTP-based responses. It is mostly aliased to make type signatures more obvious.

data PongConfig m Source #

This provides the configuration for the pong server.

Constructors

PongConfig 

Fields

defaultPongConfig :: Monad m => PongConfig m Source #

Default config that runs on port 10411 and just prints out the four characters pong.

pongActionHttp200 :: Monad m => PongAction m Source #

Provides an action generating an HTTP/0.9 response message for the ok200 Status.

pongActionHttp500 :: Monad m => PongAction m Source #

Provides an action generating an HTTP/0.9 response message for the internalServerError500 Status.

pongActionFromStatus :: Monad m => Status -> PongAction m Source #

Provides an action generating an HTTP/0.9 response message for the given Status.

pongHttpAction :: Monad m => PongHttpAction m -> PongAction m Source #

Convert a Status action into one returning a ByteString.

pongCatch :: (MonadCatch m, Exception e) => PongAction m -> (e -> PongAction m) -> PongAction m Source #

Allows for customization of the result message given different exceptions.

pongCatchHttp :: (MonadCatch m, Exception e) => PongHttpAction m -> (e -> PongHttpAction m) -> PongAction m Source #

Allows for customization of the result Status given different exceptions.

withPongServer :: (MonadBaseControl IO m, MonadMask m, MonadIO m) => PongConfig m -> m () -> m () Source #

Entry point to the pong server.