#-}
-- |Utility functions used internally in this package.
module Network.HTTP.Lucu.Utils
- ( Host
+ ( Scheme
+ , Host
, PathSegment
, Path
, splitBy
, quoteStr
, parseWWWFormURLEncoded
+ , uriCIScheme
, uriHost
, uriPathSegments
, trim
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
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
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