@@ -33,7 +33,7 @@ import Network
33 ( listenOn, sClose, PortID(PortNumber), Socket
33 ( listenOn, sClose, PortID(PortNumber), Socket
34 , withSocketsDo)
34 , withSocketsDo)
35import Network.Socket
35import Network.Socket
36− ( accept
36+ ( accept, SockAddr
38import qualified Network.Socket.ByteString as Sock
38import qualified Network.Socket.ByteString as Sock
39import Control.Exception (bracket, finally, Exception, SomeException, catch)
39import Control.Exception (bracket, finally, Exception, SomeException, catch)
@@ -72,16 +72,10 @@ type Port = Int
72serveConnections :: Port -> Application -> Socket -> IO ()
72serveConnections :: Port -> Application -> Socket -> IO ()
73serveConnections port app socket = do
73serveConnections port app socket = do
74 (conn, sa) <- accept socket
74 (conn, sa) <- accept socket
75− let remoteHost' = stripPort $ show sa -- FIXME
76− _ <- forkIO $ serveConnection port app conn remoteHost'
75+ _ <- forkIO $ serveConnection port app conn sa
77 serveConnections port app socket
76 serveConnections port app socket
80− case break (== ':') $ reverse s of
81− (_, ':' : rest) -> reverse rest
84−serveConnection :: Port -> Application -> Socket -> String -> IO ()
78+serveConnection :: Port -> Application -> Socket -> SockAddr -> IO ()
85serveConnection port app conn remoteHost' = do
79serveConnection port app conn remoteHost' = do
@@ -98,7 +92,7 @@ serveConnection port app conn remoteHost' = do
98 keepAlive <- liftIO $ sendResponse env (httpVersion env) conn res
92 keepAlive <- liftIO $ sendResponse env (httpVersion env) conn res
99 when keepAlive serveConnection'
93 when keepAlive serveConnection'
101−parseRequest :: Port -> String -> E.Iteratee S.ByteString IO (E.Enumeratee ByteString ByteString IO a, Request)
95+parseRequest :: Port -> SockAddr -> E.Iteratee S.ByteString IO (E.Enumeratee ByteString ByteString IO a, Request)
102parseRequest port remoteHost' = do
96parseRequest port remoteHost' = do
103 headers' <- takeUntilBlank 0 id
97 headers' <- takeUntilBlank 0 id
104 parseRequest' port headers' remoteHost'
98 parseRequest' port headers' remoteHost'
@@ -156,7 +150,7 @@ instance Exception InvalidRequest
156-- | Parse a set of header lines and body into a 'Request'.
150-- | Parse a set of header lines and body into a 'Request'.
157parseRequest' :: Port
151parseRequest' :: Port
158 -> [ByteString]
152 -> [ByteString]
159− -> String
153+ -> SockAddr
160 -> E.Iteratee S.ByteString IO (E.Enumeratee S.ByteString S.ByteString IO a, Request)
154 -> E.Iteratee S.ByteString IO (E.Enumeratee S.ByteString S.ByteString IO a, Request)
161parseRequest' port lines' remoteHost' = do
155parseRequest' port lines' remoteHost' = do
162 (firstLine, otherLines) <-
156 (firstLine, otherLines) <-
@@ -186,7 +180,7 @@ parseRequest' port lines' remoteHost' = do
186 , requestHeaders = heads
180 , requestHeaders = heads
187 , isSecure = False
181 , isSecure = False
188 , errorHandler = System.IO.hPutStr System.IO.stderr
182 , errorHandler = System.IO.hPutStr System.IO.stderr
189− , remoteHost = B.pack remoteHost'
183+ , remoteHost = remoteHost'
192parseFirst :: ByteString
186parseFirst :: ByteString