X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=Lucu.git;a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FETag.hs;h=f7ef8387c7044d02acc1451a7fa0e140c3197c60;hp=9bfa9aa29e67555499dc62bfecfa3b8b8f97b04b;hb=ac2ff93f647d60d43ca3cc54eb776fe0f701ac9e;hpb=fc4e0252eed3c9cb43c250ea7dd29ef5dffa6dad diff --git a/Network/HTTP/Lucu/ETag.hs b/Network/HTTP/Lucu/ETag.hs index 9bfa9aa..f7ef838 100644 --- a/Network/HTTP/Lucu/ETag.hs +++ b/Network/HTTP/Lucu/ETag.hs @@ -36,6 +36,7 @@ data ETag = ETag { -- |Convert an 'ETag' to 'AsciiBuilder'. printETag ∷ ETag → AsciiBuilder +{-# INLINEABLE printETag #-} printETag et = ( if etagIsWeak et then A.toAsciiBuilder "W/" @@ -48,32 +49,38 @@ printETag et -- |Parse 'Etag' from an 'Ascii'. This functions throws an exception -- for parse error. parseETag ∷ Ascii → ETag +{-# INLINEABLE parseETag #-} parseETag str - = let p = do et ← eTagP - endOfInput - return et - bs = A.toByteString str - in - case parseOnly p bs of - Right et → et - Left err → error ("unparsable ETag: " ⧺ A.toString str ⧺ ": " ⧺ err) + = case parseOnly p $ A.toByteString str of + Right et → et + Left err → error ("unparsable ETag: " ⧺ A.toString str ⧺ ": " ⧺ err) + where + p ∷ Parser ETag + {-# INLINE p #-} + p = do et ← eTagP + endOfInput + return et -- |This is equivalent to @'ETag' 'Prelude.False'@. If you want to -- generate an ETag from a file, try using -- 'Network.HTTP.Lucu.StaticFile.generateETagFromFile'. strongETag ∷ Ascii → ETag +{-# INLINE strongETag #-} strongETag = ETag False -- |This is equivalent to @'ETag' 'Prelude.True'@. weakETag ∷ Ascii → ETag +{-# INLINE weakETag #-} weakETag = ETag True eTagP ∷ Parser ETag +{-# INLINEABLE eTagP #-} eTagP = do isWeak ← option False (string "W/" *> return True) str ← quotedStr return $ ETag isWeak str eTagListP ∷ Parser [ETag] +{-# INLINEABLE eTagListP #-} eTagListP = do xs ← listOf eTagP when (null xs) $ fail "empty list of ETags"