{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Airship.Resource
( Resource(..)
, PostResponse(..)
, serverError
, defaultResource
) where
import Airship.Types
import Data.ByteString (ByteString)
#if __GLASGOW_HASKELL__ < 710
import Data.Monoid (mappend, mempty)
#endif
import Data.Text (Text)
import Data.Time.Clock (UTCTime)
import Network.HTTP.Media (MediaType)
import Network.HTTP.Types
data PostResponse m
= PostCreate [Text]
| PostCreateRedirect [Text]
| PostProcess [(MediaType, Webmachine m ())]
| PostProcessRedirect [(MediaType, Webmachine m ByteString)]
data Resource m =
Resource {
Resource m -> Webmachine m Bool
allowMissingPost :: Webmachine m Bool
, Resource m -> Webmachine m [Method]
allowedMethods :: Webmachine m [Method]
, Resource m -> Webmachine m [(MediaType, Webmachine m ())]
contentTypesAccepted :: Webmachine m [(MediaType, Webmachine m ())]
, Resource m -> Webmachine m [(MediaType, Webmachine m ResponseBody)]
contentTypesProvided :: Webmachine m [(MediaType, Webmachine m ResponseBody)]
, Resource m -> Webmachine m Bool
deleteCompleted :: Webmachine m Bool
, Resource m -> Webmachine m Bool
deleteResource :: Webmachine m Bool
, Resource m -> Webmachine m Bool
entityTooLarge :: Webmachine m Bool
, Resource m -> Webmachine m Bool
forbidden :: Webmachine m Bool
, Resource m -> Webmachine m (Maybe ETag)
generateETag :: Webmachine m (Maybe ETag)
, Resource m -> Webmachine m Bool
implemented :: Webmachine m Bool
, Resource m -> Webmachine m Bool
isAuthorized :: Webmachine m Bool
, Resource m -> Webmachine m Bool
isConflict :: Webmachine m Bool
, Resource m -> Webmachine m Bool
knownContentType :: Webmachine m Bool
, Resource m -> Webmachine m (Maybe UTCTime)
lastModified :: Webmachine m (Maybe UTCTime)
, Resource m -> Webmachine m Bool
languageAvailable :: Webmachine m Bool
, Resource m -> Webmachine m Bool
malformedRequest :: Webmachine m Bool
, Resource m -> Webmachine m (Maybe Method)
movedPermanently :: Webmachine m (Maybe ByteString)
, Resource m -> Webmachine m (Maybe Method)
movedTemporarily :: Webmachine m (Maybe ByteString)
, Resource m -> Webmachine m Bool
multipleChoices :: Webmachine m Bool
, Resource m -> Webmachine m [(MediaType, Webmachine m ())]
patchContentTypesAccepted :: Webmachine m [(MediaType, Webmachine m ())]
, Resource m -> Webmachine m Bool
previouslyExisted :: Webmachine m Bool
, Resource m -> Webmachine m (PostResponse m)
processPost :: Webmachine m (PostResponse m)
, Resource m -> Webmachine m Bool
resourceExists :: Webmachine m Bool
, Resource m -> Webmachine m Bool
serviceAvailable :: Webmachine m Bool
, Resource m -> Webmachine m Bool
uriTooLong :: Webmachine m Bool
, :: Webmachine m Bool
, Resource m
-> Monad m => Map Status [(MediaType, Webmachine m ResponseBody)]
errorResponses :: ErrorResponses m
}
serverError :: Monad m => Webmachine m a
serverError :: Webmachine m a
serverError = Response -> Webmachine m a
forall (m :: * -> *) a. Monad m => Response -> Webmachine m a
finishWith (Status -> ResponseHeaders -> ResponseBody -> Response
Response Status
status500 [] ResponseBody
Empty)
defaultResource :: Monad m => Resource m
defaultResource :: Resource m
defaultResource = Resource :: forall (m :: * -> *).
Webmachine m Bool
-> Webmachine m [Method]
-> Webmachine m [(MediaType, Webmachine m ())]
-> Webmachine m [(MediaType, Webmachine m ResponseBody)]
-> Webmachine m Bool
-> Webmachine m Bool
-> Webmachine m Bool
-> Webmachine m Bool
-> Webmachine m (Maybe ETag)
-> Webmachine m Bool
-> Webmachine m Bool
-> Webmachine m Bool
-> Webmachine m Bool
-> Webmachine m (Maybe UTCTime)
-> Webmachine m Bool
-> Webmachine m Bool
-> Webmachine m (Maybe Method)
-> Webmachine m (Maybe Method)
-> Webmachine m Bool
-> Webmachine m [(MediaType, Webmachine m ())]
-> Webmachine m Bool
-> Webmachine m (PostResponse m)
-> Webmachine m Bool
-> Webmachine m Bool
-> Webmachine m Bool
-> Webmachine m Bool
-> ErrorResponses m
-> Resource m
Resource { allowMissingPost :: Webmachine m Bool
allowMissingPost = Bool -> Webmachine m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
, allowedMethods :: Webmachine m [Method]
allowedMethods = [Method] -> Webmachine m [Method]
forall (m :: * -> *) a. Monad m => a -> m a
return [Method
methodOptions, Method
methodGet, Method
methodHead]
, contentTypesAccepted :: Webmachine m [(MediaType, Webmachine m ())]
contentTypesAccepted = [(MediaType, Webmachine m ())]
-> Webmachine m [(MediaType, Webmachine m ())]
forall (m :: * -> *) a. Monad m => a -> m a
return []
, contentTypesProvided :: Webmachine m [(MediaType, Webmachine m ResponseBody)]
contentTypesProvided = [(MediaType, Webmachine m ResponseBody)]
-> Webmachine m [(MediaType, Webmachine m ResponseBody)]
forall (m :: * -> *) a. Monad m => a -> m a
return [(MediaType
"text/html", Status -> Webmachine m ResponseBody
forall (m :: * -> *) a. Monad m => Status -> Webmachine m a
halt Status
status405)]
, deleteCompleted :: Webmachine m Bool
deleteCompleted = Bool -> Webmachine m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
, deleteResource :: Webmachine m Bool
deleteResource = Bool -> Webmachine m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
, entityTooLarge :: Webmachine m Bool
entityTooLarge = Bool -> Webmachine m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
, forbidden :: Webmachine m Bool
forbidden = Bool -> Webmachine m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
, generateETag :: Webmachine m (Maybe ETag)
generateETag = Maybe ETag -> Webmachine m (Maybe ETag)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe ETag
forall a. Maybe a
Nothing
, implemented :: Webmachine m Bool
implemented = Bool -> Webmachine m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
, isAuthorized :: Webmachine m Bool
isAuthorized = Bool -> Webmachine m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
, isConflict :: Webmachine m Bool
isConflict = Bool -> Webmachine m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
, knownContentType :: Webmachine m Bool
knownContentType = Bool -> Webmachine m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
, lastModified :: Webmachine m (Maybe UTCTime)
lastModified = Maybe UTCTime -> Webmachine m (Maybe UTCTime)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe UTCTime
forall a. Maybe a
Nothing
, languageAvailable :: Webmachine m Bool
languageAvailable = Bool -> Webmachine m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
, malformedRequest :: Webmachine m Bool
malformedRequest = Bool -> Webmachine m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
, movedPermanently :: Webmachine m (Maybe Method)
movedPermanently = Maybe Method -> Webmachine m (Maybe Method)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Method
forall a. Maybe a
Nothing
, movedTemporarily :: Webmachine m (Maybe Method)
movedTemporarily = Maybe Method -> Webmachine m (Maybe Method)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Method
forall a. Maybe a
Nothing
, multipleChoices :: Webmachine m Bool
multipleChoices = Bool -> Webmachine m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
, patchContentTypesAccepted :: Webmachine m [(MediaType, Webmachine m ())]
patchContentTypesAccepted = [(MediaType, Webmachine m ())]
-> Webmachine m [(MediaType, Webmachine m ())]
forall (m :: * -> *) a. Monad m => a -> m a
return []
, previouslyExisted :: Webmachine m Bool
previouslyExisted = Bool -> Webmachine m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
, processPost :: Webmachine m (PostResponse m)
processPost = PostResponse m -> Webmachine m (PostResponse m)
forall (m :: * -> *) a. Monad m => a -> m a
return ([(MediaType, Webmachine m ())] -> PostResponse m
forall (m :: * -> *).
[(MediaType, Webmachine m ())] -> PostResponse m
PostProcess [])
, resourceExists :: Webmachine m Bool
resourceExists = Bool -> Webmachine m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
, serviceAvailable :: Webmachine m Bool
serviceAvailable = Bool -> Webmachine m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
, uriTooLong :: Webmachine m Bool
uriTooLong = Bool -> Webmachine m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
, validContentHeaders :: Webmachine m Bool
validContentHeaders = Bool -> Webmachine m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
, errorResponses :: ErrorResponses m
errorResponses = ErrorResponses m
forall a. Monoid a => a
mempty
}