-- | 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 (..))
import WebGear.Core.Trait (Linked, Set, Trait (..), linkzero, plant)

-- | 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 () (Linked '[Status] Response)
mkResponse :: Status -> h () (Linked '[Status] Response)
mkResponse Status
status = proc () -> do
  let response :: Linked '[] Response
response = Response -> Linked '[] Response
forall a. a -> Linked '[] a
linkzero (Response -> Linked '[] Response)
-> Response -> Linked '[] Response
forall a b. (a -> b) -> a -> b
$ Status
-> HashMap HeaderName ByteString -> Maybe ByteString -> Response
Response Status
status [] Maybe ByteString
forall a. Maybe a
Nothing
  Status
-> h (Linked '[] Response, Attribute Status Response)
     (Linked '[Status] Response)
forall t (ts :: [*]) (h :: * -> * -> *) a.
Set h t a =>
t -> h (Linked ts a, Attribute t a) (Linked (t : ts) a)
plant (Status -> Status
Status Status
status) -< (Linked '[] Response
response, Status
status)

-- | Continue 100 response
continue100 :: Set h Status Response => h () (Linked '[Status] Response)
continue100 :: h () (Linked '[Status] Response)
continue100 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.continue100

-- | Switching Protocols 101 response
switchingProtocols101 :: Set h Status Response => h () (Linked '[Status] Response)
switchingProtocols101 :: h () (Linked '[Status] Response)
switchingProtocols101 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.switchingProtocols101

-- | OK 200 response
ok200 :: Set h Status Response => h () (Linked '[Status] Response)
ok200 :: h () (Linked '[Status] Response)
ok200 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.ok200

-- | Created 201 response
created201 :: Set h Status Response => h () (Linked '[Status] Response)
created201 :: h () (Linked '[Status] Response)
created201 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.created201

-- | Accepted 202 response
accepted202 :: Set h Status Response => h () (Linked '[Status] Response)
accepted202 :: h () (Linked '[Status] Response)
accepted202 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.accepted202

-- | Non-Authoritative 203 response
nonAuthoritative203 :: Set h Status Response => h () (Linked '[Status] Response)
nonAuthoritative203 :: h () (Linked '[Status] Response)
nonAuthoritative203 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.nonAuthoritative203

-- | No Content 204 response
noContent204 :: Set h Status Response => h () (Linked '[Status] Response)
noContent204 :: h () (Linked '[Status] Response)
noContent204 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.noContent204

-- | Reset Content 205 response
resetContent205 :: Set h Status Response => h () (Linked '[Status] Response)
resetContent205 :: h () (Linked '[Status] Response)
resetContent205 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.resetContent205

-- | Partial Content 206 response
partialContent206 :: Set h Status Response => h () (Linked '[Status] Response)
partialContent206 :: h () (Linked '[Status] Response)
partialContent206 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.partialContent206

-- | Multiple Choices 300 response
multipleChoices300 :: Set h Status Response => h () (Linked '[Status] Response)
multipleChoices300 :: h () (Linked '[Status] Response)
multipleChoices300 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.multipleChoices300

-- | Moved Permanently 301 response
movedPermanently301 :: Set h Status Response => h () (Linked '[Status] Response)
movedPermanently301 :: h () (Linked '[Status] Response)
movedPermanently301 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.movedPermanently301

-- | Found 302 response
found302 :: Set h Status Response => h () (Linked '[Status] Response)
found302 :: h () (Linked '[Status] Response)
found302 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.found302

-- | See Other 303 response
seeOther303 :: Set h Status Response => h () (Linked '[Status] Response)
seeOther303 :: h () (Linked '[Status] Response)
seeOther303 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.seeOther303

-- | Not Modified 304 response
notModified304 :: Set h Status Response => h () (Linked '[Status] Response)
notModified304 :: h () (Linked '[Status] Response)
notModified304 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.notModified304

-- | Temporary Redirect 307 response
temporaryRedirect307 :: Set h Status Response => h () (Linked '[Status] Response)
temporaryRedirect307 :: h () (Linked '[Status] Response)
temporaryRedirect307 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.temporaryRedirect307

-- | Permanent Redirect 308 response
permanentRedirect308 :: Set h Status Response => h () (Linked '[Status] Response)
permanentRedirect308 :: h () (Linked '[Status] Response)
permanentRedirect308 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.permanentRedirect308

-- | Bad Request 400 response
badRequest400 :: Set h Status Response => h () (Linked '[Status] Response)
badRequest400 :: h () (Linked '[Status] Response)
badRequest400 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.badRequest400

-- | Unauthorized 401 response
unauthorized401 :: Set h Status Response => h () (Linked '[Status] Response)
unauthorized401 :: h () (Linked '[Status] Response)
unauthorized401 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.unauthorized401

-- | Payment Required 402 response
paymentRequired402 :: Set h Status Response => h () (Linked '[Status] Response)
paymentRequired402 :: h () (Linked '[Status] Response)
paymentRequired402 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.paymentRequired402

-- | Forbidden 403 response
forbidden403 :: Set h Status Response => h () (Linked '[Status] Response)
forbidden403 :: h () (Linked '[Status] Response)
forbidden403 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.forbidden403

-- | Not Found 404 response
notFound404 :: Set h Status Response => h () (Linked '[Status] Response)
notFound404 :: h () (Linked '[Status] Response)
notFound404 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.notFound404

-- | Method Not Allowed 405 response
methodNotAllowed405 :: Set h Status Response => h () (Linked '[Status] Response)
methodNotAllowed405 :: h () (Linked '[Status] Response)
methodNotAllowed405 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.methodNotAllowed405

-- | Not Acceptable 406 response
notAcceptable406 :: Set h Status Response => h () (Linked '[Status] Response)
notAcceptable406 :: h () (Linked '[Status] Response)
notAcceptable406 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.notAcceptable406

-- | Proxy Authentication Required 407 response
proxyAuthenticationRequired407 :: Set h Status Response => h () (Linked '[Status] Response)
proxyAuthenticationRequired407 :: h () (Linked '[Status] Response)
proxyAuthenticationRequired407 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.proxyAuthenticationRequired407

-- | Request Timeout 408 response
requestTimeout408 :: Set h Status Response => h () (Linked '[Status] Response)
requestTimeout408 :: h () (Linked '[Status] Response)
requestTimeout408 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.requestTimeout408

-- | Conflict 409 response
conflict409 :: Set h Status Response => h () (Linked '[Status] Response)
conflict409 :: h () (Linked '[Status] Response)
conflict409 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.conflict409

-- | Gone 410 response
gone410 :: Set h Status Response => h () (Linked '[Status] Response)
gone410 :: h () (Linked '[Status] Response)
gone410 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.gone410

-- | Length Required 411 response
lengthRequired411 :: Set h Status Response => h () (Linked '[Status] Response)
lengthRequired411 :: h () (Linked '[Status] Response)
lengthRequired411 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.lengthRequired411

-- | Precondition Failed 412 response
preconditionFailed412 :: Set h Status Response => h () (Linked '[Status] Response)
preconditionFailed412 :: h () (Linked '[Status] Response)
preconditionFailed412 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.preconditionFailed412

-- | Request Entity Too Large 413 response
requestEntityTooLarge413 :: Set h Status Response => h () (Linked '[Status] Response)
requestEntityTooLarge413 :: h () (Linked '[Status] Response)
requestEntityTooLarge413 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.requestEntityTooLarge413

-- | Request URI Too Long 414 response
requestURITooLong414 :: Set h Status Response => h () (Linked '[Status] Response)
requestURITooLong414 :: h () (Linked '[Status] Response)
requestURITooLong414 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.requestURITooLong414

-- | Unsupported Media Type 415 response
unsupportedMediaType415 :: Set h Status Response => h () (Linked '[Status] Response)
unsupportedMediaType415 :: h () (Linked '[Status] Response)
unsupportedMediaType415 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.unsupportedMediaType415

-- | Requested Range Not Satisfiable 416 response
requestedRangeNotSatisfiable416 :: Set h Status Response => h () (Linked '[Status] Response)
requestedRangeNotSatisfiable416 :: h () (Linked '[Status] Response)
requestedRangeNotSatisfiable416 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.requestedRangeNotSatisfiable416

-- | Expectation Failed 417 response
expectationFailed417 :: Set h Status Response => h () (Linked '[Status] Response)
expectationFailed417 :: h () (Linked '[Status] Response)
expectationFailed417 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.expectationFailed417

-- | I'm A Teapot 418 response
imATeapot418 :: Set h Status Response => h () (Linked '[Status] Response)
imATeapot418 :: h () (Linked '[Status] Response)
imATeapot418 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.imATeapot418

-- | Unprocessable Entity 422 response
unprocessableEntity422 :: Set h Status Response => h () (Linked '[Status] Response)
unprocessableEntity422 :: h () (Linked '[Status] Response)
unprocessableEntity422 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.unprocessableEntity422

-- | Precondition Required 428 response
preconditionRequired428 :: Set h Status Response => h () (Linked '[Status] Response)
preconditionRequired428 :: h () (Linked '[Status] Response)
preconditionRequired428 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.preconditionRequired428

-- | Too Many Requests 429 response
tooManyRequests429 :: Set h Status Response => h () (Linked '[Status] Response)
tooManyRequests429 :: h () (Linked '[Status] Response)
tooManyRequests429 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.tooManyRequests429

-- | Request Header Fields Too Large 431 response
requestHeaderFieldsTooLarge431 :: Set h Status Response => h () (Linked '[Status] Response)
requestHeaderFieldsTooLarge431 :: h () (Linked '[Status] Response)
requestHeaderFieldsTooLarge431 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.requestHeaderFieldsTooLarge431

-- | Internal Server Error 500 response
internalServerError500 :: Set h Status Response => h () (Linked '[Status] Response)
internalServerError500 :: h () (Linked '[Status] Response)
internalServerError500 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.internalServerError500

-- | Not Implemented 501 response
notImplemented501 :: Set h Status Response => h () (Linked '[Status] Response)
notImplemented501 :: h () (Linked '[Status] Response)
notImplemented501 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.notImplemented501

-- | Bad Gateway 502 response
badGateway502 :: Set h Status Response => h () (Linked '[Status] Response)
badGateway502 :: h () (Linked '[Status] Response)
badGateway502 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.badGateway502

-- | Service Unavailable 503 response
serviceUnavailable503 :: Set h Status Response => h () (Linked '[Status] Response)
serviceUnavailable503 :: h () (Linked '[Status] Response)
serviceUnavailable503 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.serviceUnavailable503

-- | Gateway Timeout 504 response
gatewayTimeout504 :: Set h Status Response => h () (Linked '[Status] Response)
gatewayTimeout504 :: h () (Linked '[Status] Response)
gatewayTimeout504 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.gatewayTimeout504

-- | HTTP Version Not Supported 505 response
httpVersionNotSupported505 :: Set h Status Response => h () (Linked '[Status] Response)
httpVersionNotSupported505 :: h () (Linked '[Status] Response)
httpVersionNotSupported505 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.httpVersionNotSupported505

-- | Network Authentication Required 511 response
networkAuthenticationRequired511 :: Set h Status Response => h () (Linked '[Status] Response)
networkAuthenticationRequired511 :: h () (Linked '[Status] Response)
networkAuthenticationRequired511 = Status -> h () (Linked '[Status] Response)
forall (h :: * -> * -> *).
Set h Status Response =>
Status -> h () (Linked '[Status] Response)
mkResponse Status
HTTP.networkAuthenticationRequired511