-- #prune
--- | Aborting the computation of 'Network.HTTP.Lucu.Resource.Resource'
--- in any IO monads or arrows.
+-- |Aborting the computation of 'Network.HTTP.Lucu.Resource.Resource'
+-- in any 'Prelude.IO' monads or arrows.
module Network.HTTP.Lucu.Abortion
( Abortion(..)
, abort
, aboMessage :: !(Maybe String)
} deriving (Show, Typeable)
--- | Computation of @'abort' status headers msg@ aborts the
+-- |Computation of @'abort' status headers msg@ aborts the
-- 'Network.HTTP.Lucu.Resource.Resource' monad with given status,
-- additional response headers, and optional message string.
--
--- What this really does is to just throw a special DynException. The
--- exception will be caught by the system.
+-- What this really does is to just throw a special
+-- 'Control.Exception.DynException'. The exception will be caught by
+-- the Lucu.
--
-- 1. If the 'Network.HTTP.Lucu.Resource.Resource' is in the /Deciding
-- Header/ or any precedent states, it is possible to use the
liftIO $ throwIO exc
{-# SPECIALIZE abort :: StatusCode -> [ (String, String) ] -> Maybe String -> Resource a #-}
--- | Computation of @'abortSTM' status headers msg@ just computes
--- 'abort' in a STM monad.
+-- |Computation of @'abortSTM' status headers msg@ just computes
+-- 'abort' in a 'Control.Monad.STM.STM' monad.
abortSTM :: StatusCode -> [ (String, String) ] -> Maybe String -> STM a
abortSTM status headers msg
= status `seq` headers `seq` msg `seq`
unsafeIOToSTM $! abort status headers msg
-- | Computation of @'abortA' -< (status, (headers, msg))@ just
--- computes 'abort' in an ArrowIO.
+-- computes 'abort' in an 'Control.Arrow.ArrowIO.ArrowIO'.
abortA :: ArrowIO a => a (StatusCode, ([ (String, String) ], Maybe String)) c
abortA
= arrIO3 abort
-- guessed only by file name.
--
-- Guessing by file magic is indeed a wonderful idea but that is
- -- not implemented (yet). But hey, don't you think it's better a
- -- file system got a MIME Type as a part of inode? Or it might be
- -- a good idea to use GnomeVFS
+ -- not implemented (yet). But, don't you think it's better a file
+ -- system got a MIME Type as a part of inode? Or it might be a
+ -- good idea to use GnomeVFS
-- (<http://developer.gnome.org/doc/API/2.0/gnome-vfs-2.0/>)
-- instead of vanilla FS.
, cnfExtToMIMEType :: !ExtMap
++
quoteStr token
--- |This is equivalent to @'ETag' False@. If you want to generate
--- an ETag from a file, try using
+-- |This is equivalent to @'ETag' 'Prelude.False'@. If you want to
+-- generate an ETag from a file, try using
-- 'Network.HTTP.Lucu.StaticFile.generateETagFromFile'.
strongETag :: String -> ETag
strongETag = ETag False
--- |This is equivalent to @'ETag' True@.
+-- |This is equivalent to @'ETag' 'Prelude.True'@.
weakETag :: String -> ETag
weakETag = ETag True
import System.IO
import System.Posix.Signals
--- | This is the entry point of Lucu httpd. It listens to a socket and
+-- |This is the entry point of Lucu httpd. It listens to a socket and
-- waits for clients. Computation of 'runHttpd' never stops by itself
-- so the only way to stop it is to raise an exception in the thread
-- computing it.
--
-- Note that 'runHttpd' automatically makes SIGPIPE be ignored by
--- computing @installHandler sigPIPE Ignore Nothing@. This can hardly
--- cause a problem but it may do.
+-- computing @'System.Posix.Signals.installHandler'
+-- 'System.Posix.Signals.sigPIPE' 'System.Posix.Signals.Ignore'
+-- 'Prelude.Nothing'@. This can hardly cause a problem but it may do.
--
-- Example:
--
--- |MIME Type guesser which guesses by a file extension. This is a
--- poor man's way of guessing MIME Types. It is simple and fast.
+-- |MIME Type guessing by a file extension. This is a poor man's way
+-- of guessing MIME Types. It is simple and fast.
--
-- In general you don't have to use this module directly.
module Network.HTTP.Lucu.MIMEType.Guess
import Network.HTTP.Lucu.Utils
import System.IO
--- |Map from extension to MIME Type.
+-- |'Data.Map.Map' from extension to MIME Type.
type ExtMap = Map String MIMEType
-- |Guess the MIME Type of file.
--- |Yet another parser combinator. This is mostly a subset of Parsec
--- but there are some differences:
+-- |Yet another parser combinator. This is mostly a subset of
+-- "Text.ParserCombinators.Parsec" but there are some differences:
--
--- * This parser works on ByteString instead of String.
+-- * This parser works on 'Data.ByteString.Base.LazyByteString'
+-- instead of 'Prelude.String'.
--
-- * Backtracking is the only possible behavior so there is no \"try\"
-- action.
where
import Control.Monad.State.Strict
+import Data.ByteString.Base (LazyByteString)
+import Data.ByteString.Lazy ()
import qualified Data.ByteString.Lazy.Char8 as B
-import Data.ByteString.Lazy.Char8 (ByteString)
-
--- |@Parser a@ is obviously a parser which parses and returns @a@.
+-- |@'Parser' a@ is obviously a parser which parses and returns @a@.
newtype Parser a = Parser {
runParser :: State ParserState (ParserResult a)
}
data ParserState
= PST {
- pstInput :: ByteString
+ pstInput :: LazyByteString
, pstIsEOFFatal :: !Bool
}
deriving (Eq, Show)
return x = x `seq` Parser $! return $! Success x
fail _ = Parser $! return $! IllegalInput
--- |@'failP'@ is just a synonym for @'Prelude.fail Prelude.undefined'@.
+-- |@'failP'@ is just a synonym for @'Prelude.fail'
+-- 'Prelude.undefined'@.
failP :: Parser a
failP = fail undefined
-- |@'parse' p bstr@ parses @bstr@ with @p@ and returns @(result,
-- remaining)@.
-parse :: Parser a -> ByteString -> (ParserResult a, ByteString)
+parse :: Parser a -> LazyByteString -> (ParserResult a, LazyByteString)
parse p input -- input は lazy である必要有り。
= p `seq`
let (result, state') = runState (runParser p) (PST input True)
result `seq` (result, pstInput state') -- pstInput state' も lazy である必要有り。
-- |@'parseStr' p str@ packs @str@ and parses it.
-parseStr :: Parser a -> String -> (ParserResult a, ByteString)
+parseStr :: Parser a -> String -> (ParserResult a, LazyByteString)
parseStr p input
= p `seq` -- input は lazy である必要有り。
parse p $! B.pack input