X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=Lucu.git;a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FUtils.hs;fp=Network%2FHTTP%2FLucu%2FUtils.hs;h=7537eafcffacf7d8edf755e2bb8fea30cd636547;hp=9abaf1e9c511d3e0d2d61bf1008640471f2baa51;hb=5f2ef377345fc47aabc63c1325df82c1cd9da9ed;hpb=313924e79d4ed48d3efb9f2530a48305fdd68c4b diff --git a/Network/HTTP/Lucu/Utils.hs b/Network/HTTP/Lucu/Utils.hs index 9abaf1e..7537eaf 100644 --- a/Network/HTTP/Lucu/Utils.hs +++ b/Network/HTTP/Lucu/Utils.hs @@ -35,18 +35,18 @@ import qualified Data.CaseInsensitive as CI import Data.Char import Data.Collections import Data.Collections.BaseInstances () +import Data.Convertible.Base +import Data.Convertible.Instances.Ascii () +import Data.Convertible.Instances.Text () +import Data.Convertible.Instances.Time () import Data.Maybe import Data.Monoid.Unicode -import Data.Ratio import Data.Text (Text) -import qualified Data.Text as T import Data.Time -import Data.Time.Clock.POSIX import Network.URI import Prelude hiding (last, mapM, null, reverse) import Prelude.Unicode import System.Directory -import System.Time (ClockTime(..)) -- |'Host' represents an IP address or a host name in an URI -- authority. @@ -74,9 +74,9 @@ splitBy isSep src -- >>> quoteStr "ab\"c" -- "\"ab\\\"c\"" quoteStr ∷ Ascii → AsciiBuilder -quoteStr str = A.toAsciiBuilder "\"" ⊕ - go (A.toByteString str) (∅) ⊕ - A.toAsciiBuilder "\"" +quoteStr str = cs ("\"" ∷ Ascii) ⊕ + go (cs str) (∅) ⊕ + cs ("\"" ∷ Ascii) where go ∷ ByteString → AsciiBuilder → AsciiBuilder go bs ab @@ -86,10 +86,10 @@ quoteStr str = A.toAsciiBuilder "\"" ⊕ → ab ⊕ b2ab x | otherwise → go (BS.tail y) - (ab ⊕ b2ab x ⊕ A.toAsciiBuilder "\\\"") + (ab ⊕ b2ab x ⊕ cs ("\\\"" ∷ Ascii)) b2ab ∷ ByteString → AsciiBuilder - b2ab = A.toAsciiBuilder ∘ A.unsafeFromByteString + b2ab = cs ∘ A.unsafeFromByteString -- |>>> parseWWWFormURLEncoded "aaa=bbb&ccc=ddd" -- [("aaa", "bbb"), ("ccc", "ddd")] @@ -98,7 +98,7 @@ parseWWWFormURLEncoded src -- THINKME: We could gain some performance by using attoparsec -- here. | src ≡ "" = [] - | otherwise = do pairStr ← splitBy (\ c → c ≡ ';' ∨ c ≡ '&') (A.toString src) + | otherwise = do pairStr ← splitBy (\ c → c ≡ ';' ∨ c ≡ '&') (cs src) let (key, value) = break (≡ '=') pairStr return ( unescape key , unescape $ case value of @@ -117,7 +117,7 @@ parseWWWFormURLEncoded src -- "example.com" uriHost ∷ URI → Host {-# INLINE uriHost #-} -uriHost = CI.mk ∘ T.pack ∘ uriRegName ∘ fromJust ∘ uriAuthority +uriHost = CI.mk ∘ cs ∘ uriRegName ∘ fromJust ∘ uriAuthority -- |>>> uriPathSegments "http://example.com/foo/bar" -- ["foo", "bar"] @@ -166,9 +166,4 @@ mapM = flip foldrM empty ∘ (flip ((<$>) ∘ flip insert) ∘) -- |Get the modification time of a given file. getLastModified ∷ FilePath → IO UTCTime -getLastModified = (clockTimeToUTC <$>) ∘ getModificationTime - where - clockTimeToUTC ∷ ClockTime → UTCTime - clockTimeToUTC (TOD sec picoSec) - = posixSecondsToUTCTime ∘ fromRational - $ sec % 1 + picoSec % (1000 ⋅ 1000 ⋅ 1000 ⋅ 1000) +getLastModified = (cs <$>) ∘ getModificationTime