, setHeader
, redirect
, setContentType
+ , setLocation
-- ** Writing a response body
-- the request header. In general you don't have to use this action.
getRequest :: Resource Request
getRequest = do itr <- ask
- return $ fromJust $ itrRequest itr
+ req <- liftIO $ atomically $ readItr itr itrRequest fromJust
+ return req
-- |Get the 'Network.HTTP.Lucu.Request.Method' value of the request.
getMethod :: Resource Method
-- so frequently: there should be actions like 'getContentType' for
-- every common headers.
getHeader :: String -> Resource (Maybe String)
-getHeader name = do itr <- ask
- return $ H.getHeader name $ fromJust $ itrRequest itr
+getHeader name = do req <- getRequest
+ return $ H.getHeader name req
-- |Get a list of 'Network.HTTP.Lucu.MIMEType.MIMEType' enumerated on
-- header \"Accept\".
--
-- If this is a PUT request, 'foundNoEntity' performs \"If-Match\"
-- test and aborts with status \"412 Precondition Failed\" when it
--- failed. If this is a GET, HEAD or DELETE request, 'foundNoEntity'
--- always aborts with status \"404 Not Found\". It is an error to
--- compute 'foundNoEntity' if this is a POST request.
+-- failed. If this is a GET, HEAD, POST or DELETE request,
+-- 'foundNoEntity' always aborts with status \"404 Not Found\".
foundNoEntity :: Maybe String -> Resource ()
foundNoEntity msgM
= do driftTo ExaminingRequest
method <- getMethod
- when (method == POST)
- $ abort InternalServerError []
- (Just "Illegal computation of foundNoEntity for POST request.")
when (method /= PUT)
$ abort NotFound [] msgM
$ abort InternalServerError []
$ Just ("Attempted to redirect with status " ++ show code)
setStatus code
- setHeader "Location" (uriToString id uri $ "")
+ setLocation uri
-- | Computation of @'setContentType' mType@ sets the response header
-- \"Content-Type\" to @mType@.
setContentType mType
= setHeader "Content-Type" $ show mType
+-- | Computation of @'setLocation' uri@ sets the response header
+-- \"Location\" to @uri@.
+setLocation :: URI -> Resource ()
+setLocation uri
+ = setHeader "Location" $ uriToString id uri $ ""
+
{- DecidingBody 時に使用するアクション群 -}