Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Moved the web application interface module.

  • Loading branch information...
commit eb4ee0ff35fd20d4a33c75848abb3f10c9cc53eb 1 parent 363cf92
@tibbe tibbe authored
View
7 Hyena/Http.hs
@@ -43,8 +43,8 @@ import Data.Maybe (fromJust)
import Data.Word (Word8)
import Network.Socket (Socket)
import Network.Socket.ByteString (send)
+import Network.Wai (Enumerator, Headers, Method(..))
-import Hyena.Application (Enumerator, Headers, Method(..))
import Hyena.BufferedSocket
import Hyena.Parser
@@ -72,6 +72,7 @@ data IRequest = IRequest
-- | An HTTP response.
data Response = Response
{ statusCode :: Int
+ , reasonPhrase :: S.ByteString
, responseHeaders :: [(S.ByteString, S.ByteString)]
, responseBody :: Enumerator
}
@@ -86,11 +87,10 @@ blockSize = 4 * 1024
-- | Send response over socket.
sendResponse :: Socket -> Response -> IO ()
sendResponse sock resp = do
- let reasonPhrase = fromJust $ M.lookup (statusCode resp) reasonPhrases
-- TODO: Check if all data was sent.
send sock $ (C.pack $ "HTTP/1.1 ")
send sock $ (C.pack $ show (statusCode resp) ++ " "
- ++ (C.unpack $ reasonPhrase))
+ ++ (C.unpack $ reasonPhrase resp))
send sock $ C.pack "\r\n"
sendHeaders sock (responseHeaders resp)
send sock $ C.pack "\r\n"
@@ -159,6 +159,7 @@ errorResponse :: Int -> Response
errorResponse status =
Response
{ statusCode = status
+ , reasonPhrase = fromJust $ M.lookup status reasonPhrases
, responseHeaders = [(C.pack "Connection", C.pack "close")]
, responseBody = emptyMessageBody
}
View
3  Hyena/Parser.hs
@@ -114,6 +114,7 @@ finished v s = IFinished v s
failed :: S -> IResult a
failed (S _ pos _) = IFailed pos
+-- | TODO: Write documentation.
runParser :: Parser a -> S.ByteString -> Result a
runParser p bs = toResult $ unParser p (initState bs) finished failed
@@ -137,7 +138,6 @@ satisfy p =
Just bs' -> retry (S bs' pos eof)
Nothing -> fail (S bs pos True)
where retry s' = unParser (satisfy p) s' succ fail
-{-# INLINE satisfy #-}
-- | @byte b@ parses a single byte @b@. Returns the parsed byte
-- (i.e. @b@).
@@ -152,4 +152,3 @@ bytes = fmap S.pack . go
go bs = case S.uncons bs of
Just (b, bs') -> liftA2 (:) (byte b) (go bs')
Nothing -> pure []
-
View
17 Hyena/Application.hs → Network/Wai.hs
@@ -2,7 +2,7 @@
------------------------------------------------------------------------
-- |
--- Module : Hyena.Application
+-- Module : Network.Wai
-- Copyright : (c) Johan Tibell 2008
-- License : BSD3-style (see LICENSE)
--
@@ -18,13 +18,11 @@
-- >
-- > import qualified Data.ByteString as S
-- > import qualified Data.ByteString.Char8 as C (pack, unpack)
+-- > import Network.Wai (Application(..), Enumerator(..))
-- > import System.Directory (getCurrentDirectory)
-- > import System.FilePath ((</>), makeRelative)
-- > import System.IO
-- >
--- > import Hyena.Application
--- > import Hyena.Server
--- >
-- > sendFile :: FilePath -> IO Enumerator
-- > sendFile fname = do
-- > cwd <- getCurrentDirectory
@@ -45,14 +43,11 @@
-- > let contentType = (C.pack "Content-Type",
-- > C.pack "application/octet-stream")
-- > enumerator <- sendFile $ C.unpack $ pathInfo environ
--- > return (200, [contentType], enumerator)
--- >
--- > main :: IO ()
--- > main = serve fileServer
--- > --
+-- > return (200, pack "OK", [contentType], enumerator)
+--
------------------------------------------------------------------------
-module Hyena.Application
+module Network.Wai
( -- * The Application type
Application,
Enumerator,
@@ -110,5 +105,5 @@ type Enumerator = forall a. (a -> S.ByteString -> IO (Either a a)) -> a -> IO a
-- | An application takes an environment and returns a HTTP status
-- code, a sequence of headers and an 'Enumerator' containing the
-- response body.
-type Application = Environment -> IO (Int, Headers, Enumerator)
+type Application = Environment -> IO (Int, S.ByteString, Headers, Enumerator)
Please sign in to comment.
Something went wrong with that request. Please try again.