X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=Lucu.git;a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FResource.hs;fp=Network%2FHTTP%2FLucu%2FResource.hs;h=41415290961632701c97e8b9bb2c1639ba729e19;hp=8585ceaf29ce993f6a1a002ed41c61d3f5c18f1e;hb=1de2506621977a383b991cadce024f626023908b;hpb=5f2ef377345fc47aabc63c1325df82c1cd9da9ed diff --git a/Network/HTTP/Lucu/Resource.hs b/Network/HTTP/Lucu/Resource.hs index 8585cea..4141529 100644 --- a/Network/HTTP/Lucu/Resource.hs +++ b/Network/HTTP/Lucu/Resource.hs @@ -151,6 +151,7 @@ import Control.Monad.Unicode import Data.Ascii (Ascii, CIAscii, AsciiBuilder) import Data.Attempt import qualified Data.Attoparsec.Char8 as P +import Data.Attoparsec.Parsable import Data.ByteString (ByteString) import qualified Data.ByteString as Strict import qualified Data.ByteString.Lazy as Lazy @@ -180,9 +181,7 @@ import Network.HTTP.Lucu.Parser import Network.HTTP.Lucu.Request import Network.HTTP.Lucu.Resource.Internal import Network.HTTP.Lucu.Response -import Network.HTTP.Lucu.MIMEType (MIMEType(..)) -import qualified Network.HTTP.Lucu.MIMEType as MT -import Network.HTTP.Lucu.MIMEType.TH +import Network.HTTP.Lucu.MIMEType import Network.HTTP.Lucu.Utils import Network.Socket hiding (accept) import Network.URI hiding (path) @@ -265,7 +264,7 @@ getAccept Nothing → return [] Just accept - → case P.parseOnly (finishOff MT.mimeTypeList) (cs accept) of + → case P.parseOnly (finishOff parser) (cs accept) of Right xs → return xs Left _ → abort $ mkAbortion' BadRequest $ "Unparsable Accept: " ⊕ cs accept @@ -293,7 +292,7 @@ getAcceptEncoding -- identity のみが許される。 return [("identity", Nothing)] else - case P.parseOnly (finishOff acceptEncodingList) (cs ae) of + case P.parseOnly (finishOff parser) (cs ae) of Right xs → return $ map toTuple $ reverse $ sort xs Left _ → abort $ mkAbortion' BadRequest $ "Unparsable Accept-Encoding: " ⊕ cs ae @@ -317,7 +316,7 @@ getContentType Nothing → return Nothing Just cType - → case P.parseOnly (finishOff MT.mimeType) (cs cType) of + → case P.parseOnly (finishOff parser) (cs cType) of Right t → return $ Just t Left _ → abort $ mkAbortion' BadRequest $ "Unparsable Content-Type: " ⊕ cs cType @@ -331,7 +330,7 @@ getAuthorization Nothing → return Nothing Just auth - → case P.parseOnly (finishOff authCredential) (cs auth) of + → case P.parseOnly (finishOff parser) (cs auth) of Right ac → return $ Just ac Left _ → return Nothing @@ -394,11 +393,11 @@ foundETag tag → if value ≡ "*" then return () else - case P.parseOnly (finishOff eTagList) (cs value) of + case P.parseOnly (finishOff parser) (cs value) of Right tags -- tags の中に一致するものが無ければ -- PreconditionFailed で終了。 - → when ((¬) (any (≡ tag) tags)) + → when ((¬) (any (≡ tag) (tags ∷ [ETag]))) $ abort $ mkAbortion' PreconditionFailed $ "The entity tag doesn't match: " ⊕ cs value @@ -422,9 +421,9 @@ foundETag tag abort $ mkAbortion' statusForNoneMatch $ "The entity tag matches: *" else - case P.parseOnly (finishOff eTagList) (cs value) of + case P.parseOnly (finishOff parser) (cs value) of Right tags - → when (any (≡ tag) tags) + → when (any (≡ tag) (tags ∷ [ETag])) $ abort $ mkAbortion' statusForNoneMatch $ "The entity tag matches: " ⊕ cs value