@@ -33,7 +33,7 @@ import Network
3333 ( listenOn, sClose, PortID(PortNumber), Socket
3434 , withSocketsDo)
3535import Network.Socket
36− ( accept
36+ ( accept, SockAddr
3737 )
3838import qualified Network.Socket.ByteString as Sock
3939import Control.Exception (bracket, finally, Exception, SomeException, catch)
@@ -72,16 +72,10 @@ type Port = Int
7272serveConnections :: Port -> Application -> Socket -> IO ()
7373serveConnections port app socket = do
7474 (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
7776 serveConnections port app socket
78− where
79− stripPort s =
80− case break (== ':') $ reverse s of
81− (_, ':' : rest) -> reverse rest
82− _ -> s
8377
84−serveConnection :: Port -> Application -> Socket -> String -> IO ()
78+serveConnection :: Port -> Application -> Socket -> SockAddr -> IO ()
8579serveConnection port app conn remoteHost' = do
8680 catch
8781 (finally
@@ -98,7 +92,7 @@ serveConnection port app conn remoteHost' = do
9892 keepAlive <- liftIO $ sendResponse env (httpVersion env) conn res
9993 when keepAlive serveConnection'
10094
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)
10296parseRequest port remoteHost' = do
10397 headers' <- takeUntilBlank 0 id
10498 parseRequest' port headers' remoteHost'
@@ -156,7 +150,7 @@ instance Exception InvalidRequest
156150-- | Parse a set of header lines and body into a 'Request'.
157151parseRequest' :: Port
158152 -> [ByteString]
159− -> String
153+ -> SockAddr
160154 -> E.Iteratee S.ByteString IO (E.Enumeratee S.ByteString S.ByteString IO a, Request)
161155parseRequest' port lines' remoteHost' = do
162156 (firstLine, otherLines) <-
@@ -186,7 +180,7 @@ parseRequest' port lines' remoteHost' = do
186180 , requestHeaders = heads
187181 , isSecure = False
188182 , errorHandler = System.IO.hPutStr System.IO.stderr
189− , remoteHost = B.pack remoteHost'
183+ , remoteHost = remoteHost'
190184 })
191185
192186parseFirst :: ByteString