, QuasiQuotes
, RecordWildCards
, UnicodeSyntax
+ , ViewPatterns
#-}
-- |This is the Resource Monad; monadic actions to define a behavior
-- of resource. The 'Rsrc' Monad is a kind of 'IO' Monad thus it
import Data.Convertible.Instances.Text ()
import Data.Convertible.Utils
import Data.Default
-import Data.Eq.Indirect
import Data.List (intersperse, sort)
import Data.Maybe
import Data.Monoid
import Data.Monoid.Unicode
-import Data.Proxy
import Data.Tagged
import Data.Text (Text)
import Data.Time
import Network.HTTP.Lucu.Request
import Network.HTTP.Lucu.Resource.Internal
import Network.HTTP.Lucu.Response
+import Network.HTTP.Lucu.Response.StatusCode
import Network.HTTP.Lucu.MIMEType
import Network.HTTP.Lucu.Utils
import Network.Socket hiding (accept)
method ← getMethod
when (method ≡ GET ∨ method ≡ HEAD)
$ setHeader "Last-Modified"
- $ flip proxy http
- $ cs timeStamp
+ $ formatUTCTime timeStamp
when (method ≡ POST)
$ abort
$ mkAbortion' InternalServerError
method ← getMethod
when (method ≡ GET ∨ method ≡ HEAD)
$ setHeader "Last-Modified"
- $ flip proxy http
- $ cs timeStamp
+ $ formatUTCTime timeStamp
when (method ≡ POST)
$ abort
$ mkAbortion' InternalServerError
ifModSince ← getHeader "If-Modified-Since"
case ifModSince of
- Just str → case fromAttempt $ ca (Tagged str ∷ Tagged HTTP Ascii) of
+ Just str → case untag' <$> (fromAttempt $ ca str) of
Just lastTime
→ when (timeStamp ≤ lastTime)
$ abort
ifUnmodSince ← getHeader "If-Unmodified-Since"
case ifUnmodSince of
- Just str → case fromAttempt $ ca (Tagged str ∷ Tagged HTTP Ascii) of
+ Just str → case untag' <$> (fromAttempt $ ca str) of
Just lastTime
→ when (timeStamp > lastTime)
$ abort
Nothing → return ()
driftTo ReceivingBody
+ where
+ untag' ∷ Tagged HTTP α → α
+ {-# INLINE untag' #-}
+ untag' = untag
-- |@'foundNoEntity' mStr@ tells the system that the 'Rsrc' found no
-- entity for the request URI. @mStr@ is an optional error message to
-- \"Location\" header field as @uri@. The @code@ must satisfy
-- 'isRedirection' or it raises an error.
redirect ∷ StatusCode sc ⇒ sc → URI → Rsrc ()
-redirect sc uri
- = do when (sc ≡: NotModified ∨ (¬) (isRedirection sc))
+redirect (fromStatusCode → sc) uri
+ = do when (sc ≡ cs NotModified ∨ (¬) (isRedirection sc))
$ abort
$ mkAbortion' InternalServerError
$ cs
$ ("Attempted to redirect with status " ∷ Ascii)
- ⊕ cs (fromStatusCode sc)
+ ⊕ cs sc
setStatus sc
setLocation uri