]> gitweb @ CieloNegro.org - Lucu.git/blobdiff - Network/HTTP/Lucu/Utils.hs
Still working on Router arrow
[Lucu.git] / Network / HTTP / Lucu / Utils.hs
index 7537eafcffacf7d8edf755e2bb8fea30cd636547..f8fd589b74bbd5c170f2a98aa0afd28aee91f33c 100644 (file)
@@ -5,13 +5,15 @@
   #-}
 -- |Utility functions used internally in this package.
 module Network.HTTP.Lucu.Utils
-    ( Host
+    ( Scheme
+    , Host
     , PathSegment
     , Path
 
     , splitBy
     , quoteStr
     , parseWWWFormURLEncoded
+    , uriCIScheme
     , uriHost
     , uriPathSegments
     , trim
@@ -26,7 +28,7 @@ module Network.HTTP.Lucu.Utils
     where
 import Control.Applicative hiding (empty)
 import Control.Monad hiding (mapM)
-import Data.Ascii (Ascii, AsciiBuilder)
+import Data.Ascii (Ascii, AsciiBuilder, CIAscii)
 import qualified Data.Ascii as A
 import Data.ByteString (ByteString)
 import qualified Data.ByteString.Char8 as BS
@@ -48,6 +50,9 @@ import Prelude hiding (last, mapM, null, reverse)
 import Prelude.Unicode
 import System.Directory
 
+-- |'Scheme' represents an URI scheme.
+type Scheme = CIAscii
+
 -- |'Host' represents an IP address or a host name in an URI
 -- authority.
 type Host = CI Text
@@ -113,6 +118,12 @@ parseWWWFormURLEncoded src
       plusToSpace '+' = ' '
       plusToSpace c   = c
 
+-- |>>> uriCIScheme "http://example.com/foo/bar"
+-- "http"
+uriCIScheme ∷ URI → CIAscii
+{-# INLINE uriCIScheme #-}
+uriCIScheme = convertUnsafe ∘ fst ∘ fromJust ∘ back ∘ uriScheme
+
 -- |>>> uriHost "http://example.com/foo/bar"
 -- "example.com"
 uriHost ∷ URI → Host