-- | Generate responses based on their HTTP status
module WebGear.Core.Trait.Status (
  Status (..),

  -- * Create responses
  mkResponse,
  continue100,
  switchingProtocols101,
  ok200,
  created201,
  accepted202,
  nonAuthoritative203,
  noContent204,
  resetContent205,
  partialContent206,
  multipleChoices300,
  movedPermanently301,
  found302,
  seeOther303,
  notModified304,
  temporaryRedirect307,
  permanentRedirect308,
  badRequest400,
  unauthorized401,
  paymentRequired402,
  forbidden403,
  notFound404,
  methodNotAllowed405,
  notAcceptable406,
  proxyAuthenticationRequired407,
  requestTimeout408,
  conflict409,
  gone410,
  lengthRequired411,
  preconditionFailed412,
  requestEntityTooLarge413,
  requestURITooLong414,
  unsupportedMediaType415,
  requestedRangeNotSatisfiable416,
  expectationFailed417,
  imATeapot418,
  unprocessableEntity422,
  preconditionRequired428,
  tooManyRequests429,
  requestHeaderFieldsTooLarge431,
  internalServerError500,
  notImplemented501,
  badGateway502,
  serviceUnavailable503,
  gatewayTimeout504,
  httpVersionNotSupported505,
  networkAuthenticationRequired511,
) where

import qualified Network.HTTP.Types as HTTP
import WebGear.Core.Response (Response (..), ResponseBody (ResponseBodyBuilder))
import WebGear.Core.Trait (Set, Trait (..), With, plant, wzero)

-- | HTTP response status
newtype Status = Status HTTP.Status

instance Trait Status Response where
  type Attribute Status Response = HTTP.Status

-- | Generate a response with the specified status
mkResponse :: (Set h Status Response) => HTTP.Status -> h () (Response `With` '[Status])
mkResponse :: forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
status = proc () -> do
  let response :: With Response '[]
response = forall a. a -> With a '[]
wzero forall a b. (a -> b) -> a -> b
$ Status -> ResponseHeaders -> ResponseBody -> Response
Response Status
status [] (Builder -> ResponseBody
ResponseBodyBuilder forall a. Monoid a => a
mempty)
  forall t (ts :: [*]) (h :: * -> * -> *) a.
Set h t a =>
t -> h (With a ts, Attribute t a) (With a (t : ts))
plant (Status -> Status
Status Status
status) -< (With Response '[]
response, Status
status)
{-# INLINE mkResponse #-}

-- | Continue 100 response
continue100 :: (Set h Status Response) => h () (Response `With` '[Status])
continue100 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
continue100 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.continue100
{-# INLINE continue100 #-}

-- | Switching Protocols 101 response
switchingProtocols101 :: (Set h Status Response) => h () (Response `With` '[Status])
switchingProtocols101 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
switchingProtocols101 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.switchingProtocols101
{-# INLINE switchingProtocols101 #-}

-- | OK 200 response
ok200 :: (Set h Status Response) => h () (Response `With` '[Status])
ok200 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
ok200 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.ok200
{-# INLINE ok200 #-}

-- | Created 201 response
created201 :: (Set h Status Response) => h () (Response `With` '[Status])
created201 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
created201 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.created201
{-# INLINE created201 #-}

-- | Accepted 202 response
accepted202 :: (Set h Status Response) => h () (Response `With` '[Status])
accepted202 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
accepted202 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.accepted202
{-# INLINE accepted202 #-}

-- | Non-Authoritative 203 response
nonAuthoritative203 :: (Set h Status Response) => h () (Response `With` '[Status])
nonAuthoritative203 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
nonAuthoritative203 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.nonAuthoritative203
{-# INLINE nonAuthoritative203 #-}

-- | No Content 204 response
noContent204 :: (Set h Status Response) => h () (Response `With` '[Status])
noContent204 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
noContent204 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.noContent204
{-# INLINE noContent204 #-}

-- | Reset Content 205 response
resetContent205 :: (Set h Status Response) => h () (Response `With` '[Status])
resetContent205 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
resetContent205 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.resetContent205
{-# INLINE resetContent205 #-}

-- | Partial Content 206 response
partialContent206 :: (Set h Status Response) => h () (Response `With` '[Status])
partialContent206 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
partialContent206 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.partialContent206
{-# INLINE partialContent206 #-}

-- | Multiple Choices 300 response
multipleChoices300 :: (Set h Status Response) => h () (Response `With` '[Status])
multipleChoices300 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
multipleChoices300 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.multipleChoices300
{-# INLINE multipleChoices300 #-}

-- | Moved Permanently 301 response
movedPermanently301 :: (Set h Status Response) => h () (Response `With` '[Status])
movedPermanently301 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
movedPermanently301 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.movedPermanently301
{-# INLINE movedPermanently301 #-}

-- | Found 302 response
found302 :: (Set h Status Response) => h () (Response `With` '[Status])
found302 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
found302 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.found302
{-# INLINE found302 #-}

-- | See Other 303 response
seeOther303 :: (Set h Status Response) => h () (Response `With` '[Status])
seeOther303 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
seeOther303 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.seeOther303
{-# INLINE seeOther303 #-}

-- | Not Modified 304 response
notModified304 :: (Set h Status Response) => h () (Response `With` '[Status])
notModified304 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
notModified304 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.notModified304
{-# INLINE notModified304 #-}

-- | Temporary Redirect 307 response
temporaryRedirect307 :: (Set h Status Response) => h () (Response `With` '[Status])
temporaryRedirect307 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
temporaryRedirect307 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.temporaryRedirect307
{-# INLINE temporaryRedirect307 #-}

-- | Permanent Redirect 308 response
permanentRedirect308 :: (Set h Status Response) => h () (Response `With` '[Status])
permanentRedirect308 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
permanentRedirect308 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.permanentRedirect308
{-# INLINE permanentRedirect308 #-}

-- | Bad Request 400 response
badRequest400 :: (Set h Status Response) => h () (Response `With` '[Status])
badRequest400 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
badRequest400 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.badRequest400
{-# INLINE badRequest400 #-}

-- | Unauthorized 401 response
unauthorized401 :: (Set h Status Response) => h () (Response `With` '[Status])
unauthorized401 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
unauthorized401 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.unauthorized401
{-# INLINE unauthorized401 #-}

-- | Payment Required 402 response
paymentRequired402 :: (Set h Status Response) => h () (Response `With` '[Status])
paymentRequired402 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
paymentRequired402 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.paymentRequired402
{-# INLINE paymentRequired402 #-}

-- | Forbidden 403 response
forbidden403 :: (Set h Status Response) => h () (Response `With` '[Status])
forbidden403 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
forbidden403 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.forbidden403
{-# INLINE forbidden403 #-}

-- | Not Found 404 response
notFound404 :: (Set h Status Response) => h () (Response `With` '[Status])
notFound404 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
notFound404 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.notFound404
{-# INLINE notFound404 #-}

-- | Method Not Allowed 405 response
methodNotAllowed405 :: (Set h Status Response) => h () (Response `With` '[Status])
methodNotAllowed405 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
methodNotAllowed405 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.methodNotAllowed405
{-# INLINE methodNotAllowed405 #-}

-- | Not Acceptable 406 response
notAcceptable406 :: (Set h Status Response) => h () (Response `With` '[Status])
notAcceptable406 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
notAcceptable406 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.notAcceptable406
{-# INLINE notAcceptable406 #-}

-- | Proxy Authentication Required 407 response
proxyAuthenticationRequired407 :: (Set h Status Response) => h () (Response `With` '[Status])
proxyAuthenticationRequired407 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
proxyAuthenticationRequired407 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.proxyAuthenticationRequired407
{-# INLINE proxyAuthenticationRequired407 #-}

-- | Request Timeout 408 response
requestTimeout408 :: (Set h Status Response) => h () (Response `With` '[Status])
requestTimeout408 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
requestTimeout408 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.requestTimeout408
{-# INLINE requestTimeout408 #-}

-- | Conflict 409 response
conflict409 :: (Set h Status Response) => h () (Response `With` '[Status])
conflict409 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
conflict409 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.conflict409
{-# INLINE conflict409 #-}

-- | Gone 410 response
gone410 :: (Set h Status Response) => h () (Response `With` '[Status])
gone410 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
gone410 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.gone410
{-# INLINE gone410 #-}

-- | Length Required 411 response
lengthRequired411 :: (Set h Status Response) => h () (Response `With` '[Status])
lengthRequired411 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
lengthRequired411 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.lengthRequired411
{-# INLINE lengthRequired411 #-}

-- | Precondition Failed 412 response
preconditionFailed412 :: (Set h Status Response) => h () (Response `With` '[Status])
preconditionFailed412 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
preconditionFailed412 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.preconditionFailed412
{-# INLINE preconditionFailed412 #-}

-- | Request Entity Too Large 413 response
requestEntityTooLarge413 :: (Set h Status Response) => h () (Response `With` '[Status])
requestEntityTooLarge413 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
requestEntityTooLarge413 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.requestEntityTooLarge413
{-# INLINE requestEntityTooLarge413 #-}

-- | Request URI Too Long 414 response
requestURITooLong414 :: (Set h Status Response) => h () (Response `With` '[Status])
requestURITooLong414 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
requestURITooLong414 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.requestURITooLong414
{-# INLINE requestURITooLong414 #-}

-- | Unsupported Media Type 415 response
unsupportedMediaType415 :: (Set h Status Response) => h () (Response `With` '[Status])
unsupportedMediaType415 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
unsupportedMediaType415 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.unsupportedMediaType415
{-# INLINE unsupportedMediaType415 #-}

-- | Requested Range Not Satisfiable 416 response
requestedRangeNotSatisfiable416 :: (Set h Status Response) => h () (Response `With` '[Status])
requestedRangeNotSatisfiable416 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
requestedRangeNotSatisfiable416 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.requestedRangeNotSatisfiable416
{-# INLINE requestedRangeNotSatisfiable416 #-}

-- | Expectation Failed 417 response
expectationFailed417 :: (Set h Status Response) => h () (Response `With` '[Status])
expectationFailed417 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
expectationFailed417 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.expectationFailed417
{-# INLINE expectationFailed417 #-}

-- | I'm A Teapot 418 response
imATeapot418 :: (Set h Status Response) => h () (Response `With` '[Status])
imATeapot418 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
imATeapot418 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.imATeapot418
{-# INLINE imATeapot418 #-}

-- | Unprocessable Entity 422 response
unprocessableEntity422 :: (Set h Status Response) => h () (Response `With` '[Status])
unprocessableEntity422 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
unprocessableEntity422 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.unprocessableEntity422
{-# INLINE unprocessableEntity422 #-}

-- | Precondition Required 428 response
preconditionRequired428 :: (Set h Status Response) => h () (Response `With` '[Status])
preconditionRequired428 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
preconditionRequired428 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.preconditionRequired428
{-# INLINE preconditionRequired428 #-}

-- | Too Many Requests 429 response
tooManyRequests429 :: (Set h Status Response) => h () (Response `With` '[Status])
tooManyRequests429 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
tooManyRequests429 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.tooManyRequests429
{-# INLINE tooManyRequests429 #-}

-- | Request Header Fields Too Large 431 response
requestHeaderFieldsTooLarge431 :: (Set h Status Response) => h () (Response `With` '[Status])
requestHeaderFieldsTooLarge431 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
requestHeaderFieldsTooLarge431 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.requestHeaderFieldsTooLarge431
{-# INLINE requestHeaderFieldsTooLarge431 #-}

-- | Internal Server Error 500 response
internalServerError500 :: (Set h Status Response) => h () (Response `With` '[Status])
internalServerError500 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
internalServerError500 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.internalServerError500
{-# INLINE internalServerError500 #-}

-- | Not Implemented 501 response
notImplemented501 :: (Set h Status Response) => h () (Response `With` '[Status])
notImplemented501 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
notImplemented501 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.notImplemented501
{-# INLINE notImplemented501 #-}

-- | Bad Gateway 502 response
badGateway502 :: (Set h Status Response) => h () (Response `With` '[Status])
badGateway502 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
badGateway502 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.badGateway502
{-# INLINE badGateway502 #-}

-- | Service Unavailable 503 response
serviceUnavailable503 :: (Set h Status Response) => h () (Response `With` '[Status])
serviceUnavailable503 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
serviceUnavailable503 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.serviceUnavailable503
{-# INLINE serviceUnavailable503 #-}

-- | Gateway Timeout 504 response
gatewayTimeout504 :: (Set h Status Response) => h () (Response `With` '[Status])
gatewayTimeout504 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
gatewayTimeout504 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.gatewayTimeout504
{-# INLINE gatewayTimeout504 #-}

-- | HTTP Version Not Supported 505 response
httpVersionNotSupported505 :: (Set h Status Response) => h () (Response `With` '[Status])
httpVersionNotSupported505 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
httpVersionNotSupported505 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.httpVersionNotSupported505
{-# INLINE httpVersionNotSupported505 #-}

-- | Network Authentication Required 511 response
networkAuthenticationRequired511 :: (Set h Status Response) => h () (Response `With` '[Status])
networkAuthenticationRequired511 :: forall (h :: * -> * -> *).
Set h Status Response =>
h () (With Response '[Status])
networkAuthenticationRequired511 = forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (With Response '[Status])
mkResponse Status
HTTP.networkAuthenticationRequired511
{-# INLINE networkAuthenticationRequired511 #-}