X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=Lucu.git;a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FPreprocess.hs;h=77047273c43564feddc2ef688be16eb652f57d73;hp=3a02ad8f194c4a0b6e41cd850e59725a0030752f;hb=6680828c79aff38431704075c339e043b577589e;hpb=51eda5b02d4528e2e240cbfc228de02b1c83799a diff --git a/Network/HTTP/Lucu/Preprocess.hs b/Network/HTTP/Lucu/Preprocess.hs index 3a02ad8..7704727 100644 --- a/Network/HTTP/Lucu/Preprocess.hs +++ b/Network/HTTP/Lucu/Preprocess.hs @@ -16,6 +16,9 @@ import Control.Monad.State.Strict import Data.Ascii (Ascii) import qualified Data.Ascii as A import qualified Data.ByteString.Char8 as C8 +import Data.CaseInsensitive (CI) +import qualified Data.CaseInsensitive as CI +import Data.Convertible.Base import Data.Maybe import Data.Text (Text) import qualified Data.Text as T @@ -44,7 +47,7 @@ data RequestBodyLength | Chunked deriving (Eq, Show) -preprocess ∷ Text → PortNumber → Request → AugmentedRequest +preprocess ∷ CI Text → PortNumber → Request → AugmentedRequest preprocess localHost localPort req@(Request {..}) = execState go initialAR where @@ -104,7 +107,7 @@ examineMethod DELETE → return () _ → setStatus NotImplemented -examineAuthority ∷ Text → PortNumber → State AugmentedRequest () +examineAuthority ∷ CI Text → PortNumber → State AugmentedRequest () examineAuthority localHost localPort = do req ← gets arRequest when (isNothing $ uriAuthority $ reqURI req) $ @@ -133,23 +136,23 @@ examineAuthority localHost localPort -- Should never reach here... ver → fail ("internal error: unknown version: " ⧺ show ver) -parseHost ∷ Ascii → (Text, Ascii) +parseHost ∷ Ascii → (CI Text, Ascii) parseHost hp - = let (h, p) = C8.break (≡ ':') $ A.toByteString hp + = let (h, p) = C8.break (≡ ':') $ cs hp -- FIXME: should decode punycode here. - hText = T.decodeUtf8 h + hText = CI.mk $ T.decodeUtf8 h pAscii = A.unsafeFromByteString p in (hText, pAscii) -updateAuthority ∷ Text → Ascii → Request → Request +updateAuthority ∷ CI Text → Ascii → Request → Request updateAuthority host port req = let uri = reqURI req uri' = uri { uriAuthority = Just URIAuth { uriUserInfo = "" - , uriRegName = T.unpack host - , uriPort = A.toString port + , uriRegName = T.unpack $ CI.original host + , uriPort = cs port } } in @@ -177,7 +180,7 @@ examineHeaders | otherwise → setStatus NotImplemented - case A.toByteString <$> getHeader "Content-Length" req of + case cs <$> getHeader "Content-Length" req of Nothing → return () Just value → case C8.readInt value of Just (len, garbage)