X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=Lucu.git;a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FHeaders.hs;fp=Network%2FHTTP%2FLucu%2FHeaders.hs;h=e6641154adc1d390b1c7cd35bb4d5d5a4c71342d;hp=f0e6ad8958bf056c30f41767263469c51a65922f;hb=1de2506621977a383b991cadce024f626023908b;hpb=5f2ef377345fc47aabc63c1325df82c1cd9da9ed diff --git a/Network/HTTP/Lucu/Headers.hs b/Network/HTTP/Lucu/Headers.hs index f0e6ad8..e664115 100644 --- a/Network/HTTP/Lucu/Headers.hs +++ b/Network/HTTP/Lucu/Headers.hs @@ -12,7 +12,6 @@ module Network.HTTP.Lucu.Headers ( Headers , HasHeaders(..) - , headers ) where import Control.Applicative hiding (empty) @@ -21,6 +20,8 @@ import Control.Monad import Data.Ascii (Ascii, AsciiBuilder, CIAscii) import qualified Data.Ascii as A import Data.Attoparsec.Char8 +import Data.Attoparsec.Parsable +import Data.ByteString (ByteString) import qualified Data.Collections.Newtype.TH as C import Data.Convertible.Base import Data.Convertible.Instances.Ascii () @@ -138,30 +139,31 @@ deriveAttempts [ ([t| Headers |], [t| Ascii |]) field-value の先頭および末尾にある LWS は全て削除され、それ以外の LWS は單一の SP に變換される。 -} -headers ∷ Parser Headers -{-# INLINEABLE headers #-} -headers = do xs ← many header - crlf - return $ fromFoldable xs - where - header ∷ Parser (CIAscii, Ascii) - header = do name ← cs <$> token - void $ char ':' - skipMany lws - values ← content `sepBy` try lws - skipMany (try lws) - crlf - return (name, joinValues values) - - content ∷ Parser Ascii - {-# INLINE content #-} - content = A.unsafeFromByteString - <$> - takeWhile1 (\c → isText c ∧ c ≢ '\x20') - - joinValues ∷ [Ascii] → Ascii - {-# INLINE joinValues #-} - joinValues = cs - ∘ mconcat - ∘ intersperse (cs ("\x20" ∷ Ascii) ∷ AsciiBuilder) - ∘ (cs <$>) +instance Parsable ByteString Headers where + {-# INLINEABLE parser #-} + parser = do xs ← many header + crlf + return $ fromFoldable xs + where + header ∷ Parser (CIAscii, Ascii) + {-# INLINEABLE header #-} + header = do name ← cs <$> token + void $ char ':' + skipMany lws + values ← content `sepBy` try lws + skipMany (try lws) + crlf + return (name, joinValues values) + + content ∷ Parser Ascii + {-# INLINEABLE content #-} + content = A.unsafeFromByteString + <$> + takeWhile1 (\c → isText c ∧ c ≢ '\x20') + + joinValues ∷ [Ascii] → Ascii + {-# INLINEABLE joinValues #-} + joinValues = cs + ∘ mconcat + ∘ intersperse (cs ("\x20" ∷ Ascii) ∷ AsciiBuilder) + ∘ (cs <$>)