-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A very minimal webserver -- -- A very minimal webserver @package network-minihttp @version 0.1 -- | This module serialises and deserialises HTTP headers. It contains -- Haskell representations of request and replies and can transform them -- to, and from, the HTTP wire format. module Network.MiniHTTP.Marshal -- | A HTTP request data Request Request :: Method -> ByteString -> Int -> Int -> Headers -> Request reqMethod :: Request -> Method reqUrl :: Request -> ByteString reqMajor :: Request -> Int reqMinor :: Request -> Int reqHeaders :: Request -> Headers -- | A HTTP reply data Reply Reply :: Int -> Int -> Int -> String -> Headers -> Reply replyMajor :: Reply -> Int replyMinor :: Reply -> Int replyStatus :: Reply -> Int replyMessage :: Reply -> String replyHeaders :: Reply -> Headers -- | A HTTP range data Range -- | everything from the given byte onwards RangeFrom :: Int64 -> Range -- | the bytes in the given range, inclusive RangeOf :: Int64 -> Int64 -> Range -- | the final n bytes RangeSuffix :: Int64 -> Range -- | HTTP headers, see RFC 2616 section 14 data Headers Headers :: Maybe [(MediaType, Int)] -> Maybe [(String, Int)] -> Maybe [(String, Int)] -> Maybe [(String, Int)] -> Bool -> Maybe Int64 -> Maybe [Method] -> Maybe ByteString -> Bool -> [String] -> [String] -> Maybe [String] -> Maybe Int64 -> Maybe ByteString -> Maybe (Maybe (Int64, Int64), Maybe Int64) -> Maybe MediaType -> Maybe UTCTime -> Maybe (Bool, ByteString) -> Maybe UTCTime -> Maybe ByteString -> Maybe (Either () [ByteString]) -> Maybe UTCTime -> Maybe (Either () [(Bool, ByteString)]) -> Maybe (Either ByteString UTCTime) -> Maybe UTCTime -> Maybe Int -> Maybe UTCTime -> Maybe ByteString -> Maybe [(String, Maybe String)] -> Maybe ByteString -> Maybe ByteString -> Maybe [Range] -> Maybe ByteString -> Maybe Int64 -> Maybe ByteString -> Maybe [String] -> [String] -> Maybe ByteString -> Maybe ByteString -> Map ByteString ByteString -> Headers httpAccept :: Headers -> Maybe [(MediaType, Int)] httpAcceptCharset :: Headers -> Maybe [(String, Int)] httpAcceptEncoding :: Headers -> Maybe [(String, Int)] httpAcceptLanguage :: Headers -> Maybe [(String, Int)] httpAcceptRanges :: Headers -> Bool httpAge :: Headers -> Maybe Int64 httpAllow :: Headers -> Maybe [Method] httpAuthorization :: Headers -> Maybe ByteString httpConnectionClose :: Headers -> Bool httpConnection :: Headers -> [String] httpContentEncodings :: Headers -> [String] httpContentLanguage :: Headers -> Maybe [String] httpContentLength :: Headers -> Maybe Int64 httpContentLocation :: Headers -> Maybe ByteString httpContentRange :: Headers -> Maybe (Maybe (Int64, Int64), Maybe Int64) httpContentType :: Headers -> Maybe MediaType httpDate :: Headers -> Maybe UTCTime httpETag :: Headers -> Maybe (Bool, ByteString) httpExpires :: Headers -> Maybe UTCTime httpHost :: Headers -> Maybe ByteString httpIfMatch :: Headers -> Maybe (Either () [ByteString]) httpIfModifiedSince :: Headers -> Maybe UTCTime httpIfNoneMatch :: Headers -> Maybe (Either () [(Bool, ByteString)]) httpIfRange :: Headers -> Maybe (Either ByteString UTCTime) httpIfUnmodifiedSince :: Headers -> Maybe UTCTime httpKeepAlive :: Headers -> Maybe Int httpLastModified :: Headers -> Maybe UTCTime httpLocation :: Headers -> Maybe ByteString httpPragma :: Headers -> Maybe [(String, Maybe String)] httpProxyAuthenticate :: Headers -> Maybe ByteString httpProxyAuthorization :: Headers -> Maybe ByteString httpRange :: Headers -> Maybe [Range] httpReferer :: Headers -> Maybe ByteString httpRetryAfter :: Headers -> Maybe Int64 httpServer :: Headers -> Maybe ByteString httpTrailer :: Headers -> Maybe [String] httpTransferEncoding :: Headers -> [String] httpUserAgent :: Headers -> Maybe ByteString httpWWWAuthenticate :: Headers -> Maybe ByteString httpOtherHeaders :: Headers -> Map ByteString ByteString emptyHeaders :: Headers -- | Convert a status code to a message (e.g. 200 -> OK) statusToMessage :: Int -> String -- | The list of valid methods, see RFC 2616 section 5.1 data Method OPTIONS :: Method GET :: Method HEAD :: Method POST :: Method PUT :: Method DELETE :: Method TRACE :: Method CONNECT :: Method type MediaType = ((String, String), [(String, String)]) putRequest :: Request -> Put putReply :: Reply -> Put parseRequest :: (BinaryParser m) => m Request parseReply :: (BinaryParser m) => m Reply instance Ord Method instance Enum Method instance Show Method instance Eq Method instance Show Headers instance Show Range instance Show Reply instance Show Request -- | This module parses the etcmime.types file, commonly found on -- UNIX systems. This file provides a mapping from file extension to MIME -- type. module Network.MiniHTTP.MimeTypesParse -- | Parse the given filename as a mime.types file and return a map from -- file extension to mime type. parseMimeTypes :: String -> IO (Map ByteString MediaType) -- | Same as parseMimeTypes, but never throw an exception, return -- a Nothing instead. parseMimeTypesTotal :: String -> IO (Maybe (Map ByteString MediaType)) -- | This module contains functions for writing webservers. These servers -- process requests in a state monad pipeline and several useful actions -- are provided here in. See examples/fileserver.hs for an example of how -- to use this module. module Network.MiniHTTP.Server -- | A source is a stream of data, like a lazy data structure, but without -- some of the dangers that such entail. A source returns a -- SourceResult each time you evaluate it. type Source = IO SourceResult data SourceResult -- | error - please don't read this source again SourceError :: SourceResult -- | end of data SourceEOF :: SourceResult -- | some data SourceData :: ByteString -> SourceResult -- | Construct a source from a ByteString bsSource :: ByteString -> IO Source -- | Construct a source from a Handle hSource :: (Int64, Int64) -> Handle -> IO Source -- | A source with no data (e.g. devnull) nullSource :: Source -- | The processing monad type WebMonad = StateT WebState IO -- | Processing a request involve running a number of actions in a StateT -- monad where the state for that monad is this record. This contains -- both a Source and a Handle element. Often something -- will fill in the Handle and expect later processing to -- convert it to a Source. Somehow, you have to end up with a -- Source, however. data WebState -- | Return the request getRequest :: WebMonad Request -- | Return the current reply getReply :: WebMonad Reply -- | Set the current reply to be a reply with the given status code, the -- default message for that status code, an empty body and an empty set -- of headers. setReply :: Int -> WebMonad () -- | Set a header in the current reply. Because of the way records work, -- you use this function like this: -- --
--   setHeader $ \h -> h { httpSomeHeader = Just value }
--   
setHeader :: (Headers -> Headers) -> WebMonad () -- | This handles the If-*Matches and If-*Modified conditional headers. It -- takes its information from the Last-Modified and ETag headers of the -- current reply. Note that, for the purposes of ETag matching, a reply -- without an ETag header is considered not to exist from the point of -- view of, say, If-Matches: *. handleConditionalRequest :: WebMonad () -- | If the current state includes a Handle, this turns it into a Source handleHandleToSource :: WebMonad () -- | This handles Range requests and also translates from Handles to -- Sources. If the WebMonad has a Handle at this point, then we can -- construct sources from any subrange of the file. (We also assume that -- Content-Length is correctly set.) -- -- See RFC 2616, section 14.35 handleRangeRequests :: WebMonad () -- | At the moment, this just adds the header Server: Network.MiniHTTP handleDecoration :: WebMonad () -- | This is a very simple handler which deals with requests by returning -- the requested file from the filesystem. It sets a Handle in the state -- and sets the Content-Type, Content-Length and Last-Modified headers handleFromFilesystem :: FilePath -> WebMonad () serve :: Int -> WebMonad () -> IO () instance Show SourceResult