Make response helpers API consistent (#79)

This commit is contained in:
Connor Prussin 2017-09-29 07:49:46 -07:00 committed by GitHub
parent f4599b276b
commit 8760334dcd
4 changed files with 110 additions and 73 deletions

View File

@ -35,7 +35,7 @@ headerMiddleware :: forall e.
HTTPure.ResponseM e HTTPure.ResponseM e
headerMiddleware router request = do headerMiddleware router request = do
response <- router request response <- router request
HTTPure.response response.status (header <> response.headers) response.body HTTPure.response' response.status (header <> response.headers) response.body
where where
header = HTTPure.headers [ Tuple.Tuple "X-Middleware" "middleware" ] header = HTTPure.headers [ Tuple.Tuple "X-Middleware" "middleware" ]

View File

@ -16,6 +16,7 @@ import HTTPure.Request (Request)
import HTTPure.Response import HTTPure.Response
( ResponseM ( ResponseM
, response, response' , response, response'
, emptyResponse, emptyResponse'
-- 1xx -- 1xx
, continue, continue' , continue, continue'

View File

@ -3,6 +3,7 @@ module HTTPure.Response
, ResponseM , ResponseM
, send , send
, response, response' , response, response'
, emptyResponse, emptyResponse'
-- 1xx -- 1xx
, continue, continue' , continue, continue'
@ -112,16 +113,24 @@ send httpresponse { status, headers, body } = do
-- | For custom response statuses or providing a body for response codes that -- | For custom response statuses or providing a body for response codes that
-- | don't typically send one. -- | don't typically send one.
response :: forall e. response :: forall e. Status.Status -> Body.Body -> ResponseM e
Status.Status -> response status = response' status Headers.empty
Headers.Headers ->
Body.Body -> -- | The same as `response` but with headers.
ResponseM e response' :: forall e.
response status headers body = pure $ { status, headers, body } Status.Status ->
Headers.Headers ->
Body.Body ->
ResponseM e
response' status headers body = pure $ { status, headers, body }
-- | The same as `response` but without a body. -- | The same as `response` but without a body.
response' :: forall e. Status.Status -> Headers.Headers -> ResponseM e emptyResponse :: forall e. Status.Status -> ResponseM e
response' status headers = response status headers $ "" emptyResponse status = emptyResponse' status Headers.empty
-- | The same as `emptyResponse` but with headers.
emptyResponse' :: forall e. Status.Status -> Headers.Headers -> ResponseM e
emptyResponse' status headers = response' status headers ""
--------- ---------
-- 1xx -- -- 1xx --
@ -133,7 +142,7 @@ continue = continue' Headers.empty
-- | 100 with headers -- | 100 with headers
continue' :: forall e. Headers.Headers -> ResponseM e continue' :: forall e. Headers.Headers -> ResponseM e
continue' = response' Status.continue continue' = emptyResponse' Status.continue
-- | 101 -- | 101
switchingProtocols :: forall e. ResponseM e switchingProtocols :: forall e. ResponseM e
@ -141,7 +150,7 @@ switchingProtocols = switchingProtocols' Headers.empty
-- | 101 with headers -- | 101 with headers
switchingProtocols' :: forall e. Headers.Headers -> ResponseM e switchingProtocols' :: forall e. Headers.Headers -> ResponseM e
switchingProtocols' = response' Status.switchingProtocols switchingProtocols' = emptyResponse' Status.switchingProtocols
-- | 102 -- | 102
processing :: forall e. ResponseM e processing :: forall e. ResponseM e
@ -149,7 +158,7 @@ processing = processing' Headers.empty
-- | 102 with headers -- | 102 with headers
processing' :: forall e. Headers.Headers -> ResponseM e processing' :: forall e. Headers.Headers -> ResponseM e
processing' = response' Status.processing processing' = emptyResponse' Status.processing
--------- ---------
-- 2xx -- -- 2xx --
@ -161,7 +170,7 @@ ok = ok' Headers.empty
-- | 200 with headers -- | 200 with headers
ok' :: forall e. Headers.Headers -> Body.Body -> ResponseM e ok' :: forall e. Headers.Headers -> Body.Body -> ResponseM e
ok' = response Status.ok ok' = response' Status.ok
-- | 201 -- | 201
created :: forall e. ResponseM e created :: forall e. ResponseM e
@ -169,7 +178,7 @@ created = created' Headers.empty
-- | 201 with headers -- | 201 with headers
created' :: forall e. Headers.Headers -> ResponseM e created' :: forall e. Headers.Headers -> ResponseM e
created' = response' Status.created created' = emptyResponse' Status.created
-- | 202 -- | 202
accepted :: forall e. ResponseM e accepted :: forall e. ResponseM e
@ -177,7 +186,7 @@ accepted = accepted' Headers.empty
-- | 202 with headers -- | 202 with headers
accepted' :: forall e. Headers.Headers -> ResponseM e accepted' :: forall e. Headers.Headers -> ResponseM e
accepted' = response' Status.accepted accepted' = emptyResponse' Status.accepted
-- | 203 -- | 203
nonAuthoritativeInformation :: forall e. Body.Body -> ResponseM e nonAuthoritativeInformation :: forall e. Body.Body -> ResponseM e
@ -188,7 +197,7 @@ nonAuthoritativeInformation' :: forall e.
Headers.Headers -> Headers.Headers ->
Body.Body -> Body.Body ->
ResponseM e ResponseM e
nonAuthoritativeInformation' = response Status.nonAuthoritativeInformation nonAuthoritativeInformation' = response' Status.nonAuthoritativeInformation
-- | 204 -- | 204
noContent :: forall e. ResponseM e noContent :: forall e. ResponseM e
@ -196,7 +205,7 @@ noContent = noContent' Headers.empty
-- | 204 with headers -- | 204 with headers
noContent' :: forall e. Headers.Headers -> ResponseM e noContent' :: forall e. Headers.Headers -> ResponseM e
noContent' = response' Status.noContent noContent' = emptyResponse' Status.noContent
-- | 205 -- | 205
resetContent :: forall e. ResponseM e resetContent :: forall e. ResponseM e
@ -204,7 +213,7 @@ resetContent = resetContent' Headers.empty
-- | 205 with headers -- | 205 with headers
resetContent' :: forall e. Headers.Headers -> ResponseM e resetContent' :: forall e. Headers.Headers -> ResponseM e
resetContent' = response' Status.resetContent resetContent' = emptyResponse' Status.resetContent
-- | 206 -- | 206
partialContent :: forall e. Body.Body -> ResponseM e partialContent :: forall e. Body.Body -> ResponseM e
@ -212,7 +221,7 @@ partialContent = partialContent' Headers.empty
-- | 206 with headers -- | 206 with headers
partialContent' :: forall e. Headers.Headers -> Body.Body -> ResponseM e partialContent' :: forall e. Headers.Headers -> Body.Body -> ResponseM e
partialContent' = response Status.partialContent partialContent' = response' Status.partialContent
-- | 207 -- | 207
multiStatus :: forall e. Body.Body -> ResponseM e multiStatus :: forall e. Body.Body -> ResponseM e
@ -220,7 +229,7 @@ multiStatus = multiStatus' Headers.empty
-- | 207 with headers -- | 207 with headers
multiStatus' :: forall e. Headers.Headers -> Body.Body -> ResponseM e multiStatus' :: forall e. Headers.Headers -> Body.Body -> ResponseM e
multiStatus' = response Status.multiStatus multiStatus' = response' Status.multiStatus
-- | 208 -- | 208
alreadyReported :: forall e. ResponseM e alreadyReported :: forall e. ResponseM e
@ -228,7 +237,7 @@ alreadyReported = alreadyReported' Headers.empty
-- | 208 with headers -- | 208 with headers
alreadyReported' :: forall e. Headers.Headers -> ResponseM e alreadyReported' :: forall e. Headers.Headers -> ResponseM e
alreadyReported' = response' Status.alreadyReported alreadyReported' = emptyResponse' Status.alreadyReported
-- | 226 -- | 226
iMUsed :: forall e. Body.Body -> ResponseM e iMUsed :: forall e. Body.Body -> ResponseM e
@ -236,7 +245,7 @@ iMUsed = iMUsed' Headers.empty
-- | 226 with headers -- | 226 with headers
iMUsed' :: forall e. Headers.Headers -> Body.Body -> ResponseM e iMUsed' :: forall e. Headers.Headers -> Body.Body -> ResponseM e
iMUsed' = response Status.iMUsed iMUsed' = response' Status.iMUsed
--------- ---------
-- 3xx -- -- 3xx --
@ -248,7 +257,7 @@ multipleChoices = multipleChoices' Headers.empty
-- | 300 with headers -- | 300 with headers
multipleChoices' :: forall e. Headers.Headers -> Body.Body -> ResponseM e multipleChoices' :: forall e. Headers.Headers -> Body.Body -> ResponseM e
multipleChoices' = response Status.multipleChoices multipleChoices' = response' Status.multipleChoices
-- | 301 -- | 301
movedPermanently :: forall e. Body.Body -> ResponseM e movedPermanently :: forall e. Body.Body -> ResponseM e
@ -256,7 +265,7 @@ movedPermanently = movedPermanently' Headers.empty
-- | 301 with headers -- | 301 with headers
movedPermanently' :: forall e. Headers.Headers -> Body.Body -> ResponseM e movedPermanently' :: forall e. Headers.Headers -> Body.Body -> ResponseM e
movedPermanently' = response Status.movedPermanently movedPermanently' = response' Status.movedPermanently
-- | 302 -- | 302
found :: forall e. Body.Body -> ResponseM e found :: forall e. Body.Body -> ResponseM e
@ -264,7 +273,7 @@ found = found' Headers.empty
-- | 302 with headers -- | 302 with headers
found' :: forall e. Headers.Headers -> Body.Body -> ResponseM e found' :: forall e. Headers.Headers -> Body.Body -> ResponseM e
found' = response Status.found found' = response' Status.found
-- | 303 -- | 303
seeOther :: forall e. Body.Body -> ResponseM e seeOther :: forall e. Body.Body -> ResponseM e
@ -272,7 +281,7 @@ seeOther = seeOther' Headers.empty
-- | 303 with headers -- | 303 with headers
seeOther' :: forall e. Headers.Headers -> Body.Body -> ResponseM e seeOther' :: forall e. Headers.Headers -> Body.Body -> ResponseM e
seeOther' = response Status.seeOther seeOther' = response' Status.seeOther
-- | 304 -- | 304
notModified :: forall e. ResponseM e notModified :: forall e. ResponseM e
@ -280,7 +289,7 @@ notModified = notModified' Headers.empty
-- | 304 with headers -- | 304 with headers
notModified' :: forall e. Headers.Headers -> ResponseM e notModified' :: forall e. Headers.Headers -> ResponseM e
notModified' = response' Status.notModified notModified' = emptyResponse' Status.notModified
-- | 305 -- | 305
useProxy :: forall e. Body.Body -> ResponseM e useProxy :: forall e. Body.Body -> ResponseM e
@ -288,7 +297,7 @@ useProxy = useProxy' Headers.empty
-- | 305 with headers -- | 305 with headers
useProxy' :: forall e. Headers.Headers -> Body.Body -> ResponseM e useProxy' :: forall e. Headers.Headers -> Body.Body -> ResponseM e
useProxy' = response Status.useProxy useProxy' = response' Status.useProxy
-- | 307 -- | 307
temporaryRedirect :: forall e. Body.Body -> ResponseM e temporaryRedirect :: forall e. Body.Body -> ResponseM e
@ -296,7 +305,7 @@ temporaryRedirect = temporaryRedirect' Headers.empty
-- | 307 with headers -- | 307 with headers
temporaryRedirect' :: forall e. Headers.Headers -> Body.Body -> ResponseM e temporaryRedirect' :: forall e. Headers.Headers -> Body.Body -> ResponseM e
temporaryRedirect' = response Status.temporaryRedirect temporaryRedirect' = response' Status.temporaryRedirect
-- | 308 -- | 308
permanentRedirect :: forall e. Body.Body -> ResponseM e permanentRedirect :: forall e. Body.Body -> ResponseM e
@ -304,7 +313,7 @@ permanentRedirect = permanentRedirect' Headers.empty
-- | 308 with headers -- | 308 with headers
permanentRedirect' :: forall e. Headers.Headers -> Body.Body -> ResponseM e permanentRedirect' :: forall e. Headers.Headers -> Body.Body -> ResponseM e
permanentRedirect' = response Status.permanentRedirect permanentRedirect' = response' Status.permanentRedirect
--------- ---------
@ -317,7 +326,7 @@ badRequest = badRequest' Headers.empty
-- | 400 with headers -- | 400 with headers
badRequest' :: forall e. Headers.Headers -> Body.Body -> ResponseM e badRequest' :: forall e. Headers.Headers -> Body.Body -> ResponseM e
badRequest' = response Status.badRequest badRequest' = response' Status.badRequest
-- | 401 -- | 401
unauthorized :: forall e. ResponseM e unauthorized :: forall e. ResponseM e
@ -325,7 +334,7 @@ unauthorized = unauthorized' Headers.empty
-- | 401 with headers -- | 401 with headers
unauthorized' :: forall e. Headers.Headers -> ResponseM e unauthorized' :: forall e. Headers.Headers -> ResponseM e
unauthorized' = response' Status.unauthorized unauthorized' = emptyResponse' Status.unauthorized
-- | 402 -- | 402
paymentRequired :: forall e. ResponseM e paymentRequired :: forall e. ResponseM e
@ -333,7 +342,7 @@ paymentRequired = paymentRequired' Headers.empty
-- | 402 with headers -- | 402 with headers
paymentRequired' :: forall e. Headers.Headers -> ResponseM e paymentRequired' :: forall e. Headers.Headers -> ResponseM e
paymentRequired' = response' Status.paymentRequired paymentRequired' = emptyResponse' Status.paymentRequired
-- | 403 -- | 403
forbidden :: forall e. ResponseM e forbidden :: forall e. ResponseM e
@ -341,7 +350,7 @@ forbidden = forbidden' Headers.empty
-- | 403 with headers -- | 403 with headers
forbidden' :: forall e. Headers.Headers -> ResponseM e forbidden' :: forall e. Headers.Headers -> ResponseM e
forbidden' = response' Status.forbidden forbidden' = emptyResponse' Status.forbidden
-- | 404 -- | 404
notFound :: forall e. ResponseM e notFound :: forall e. ResponseM e
@ -349,7 +358,7 @@ notFound = notFound' Headers.empty
-- | 404 with headers -- | 404 with headers
notFound' :: forall e. Headers.Headers -> ResponseM e notFound' :: forall e. Headers.Headers -> ResponseM e
notFound' = response' Status.notFound notFound' = emptyResponse' Status.notFound
-- | 405 -- | 405
methodNotAllowed :: forall e. ResponseM e methodNotAllowed :: forall e. ResponseM e
@ -357,7 +366,7 @@ methodNotAllowed = methodNotAllowed' Headers.empty
-- | 405 with headers -- | 405 with headers
methodNotAllowed' :: forall e. Headers.Headers -> ResponseM e methodNotAllowed' :: forall e. Headers.Headers -> ResponseM e
methodNotAllowed' = response' Status.methodNotAllowed methodNotAllowed' = emptyResponse' Status.methodNotAllowed
-- | 406 -- | 406
notAcceptable :: forall e. ResponseM e notAcceptable :: forall e. ResponseM e
@ -365,7 +374,7 @@ notAcceptable = notAcceptable' Headers.empty
-- | 406 with headers -- | 406 with headers
notAcceptable' :: forall e. Headers.Headers -> ResponseM e notAcceptable' :: forall e. Headers.Headers -> ResponseM e
notAcceptable' = response' Status.notAcceptable notAcceptable' = emptyResponse' Status.notAcceptable
-- | 407 -- | 407
proxyAuthenticationRequired :: forall e. ResponseM e proxyAuthenticationRequired :: forall e. ResponseM e
@ -373,7 +382,7 @@ proxyAuthenticationRequired = proxyAuthenticationRequired' Headers.empty
-- | 407 with headers -- | 407 with headers
proxyAuthenticationRequired' :: forall e. Headers.Headers -> ResponseM e proxyAuthenticationRequired' :: forall e. Headers.Headers -> ResponseM e
proxyAuthenticationRequired' = response' Status.proxyAuthenticationRequired proxyAuthenticationRequired' = emptyResponse' Status.proxyAuthenticationRequired
-- | 408 -- | 408
requestTimeout :: forall e. ResponseM e requestTimeout :: forall e. ResponseM e
@ -381,7 +390,7 @@ requestTimeout = requestTimeout' Headers.empty
-- | 408 with headers -- | 408 with headers
requestTimeout' :: forall e. Headers.Headers -> ResponseM e requestTimeout' :: forall e. Headers.Headers -> ResponseM e
requestTimeout' = response' Status.requestTimeout requestTimeout' = emptyResponse' Status.requestTimeout
-- | 409 -- | 409
conflict :: forall e. Body.Body -> ResponseM e conflict :: forall e. Body.Body -> ResponseM e
@ -389,7 +398,7 @@ conflict = conflict' Headers.empty
-- | 409 with headers -- | 409 with headers
conflict' :: forall e. Headers.Headers -> Body.Body -> ResponseM e conflict' :: forall e. Headers.Headers -> Body.Body -> ResponseM e
conflict' = response Status.conflict conflict' = response' Status.conflict
-- | 410 -- | 410
gone :: forall e. ResponseM e gone :: forall e. ResponseM e
@ -397,7 +406,7 @@ gone = gone' Headers.empty
-- | 410 with headers -- | 410 with headers
gone' :: forall e. Headers.Headers -> ResponseM e gone' :: forall e. Headers.Headers -> ResponseM e
gone' = response' Status.gone gone' = emptyResponse' Status.gone
-- | 411 -- | 411
lengthRequired :: forall e. ResponseM e lengthRequired :: forall e. ResponseM e
@ -405,7 +414,7 @@ lengthRequired = lengthRequired' Headers.empty
-- | 411 with headers -- | 411 with headers
lengthRequired' :: forall e. Headers.Headers -> ResponseM e lengthRequired' :: forall e. Headers.Headers -> ResponseM e
lengthRequired' = response' Status.lengthRequired lengthRequired' = emptyResponse' Status.lengthRequired
-- | 412 -- | 412
preconditionFailed :: forall e. ResponseM e preconditionFailed :: forall e. ResponseM e
@ -413,7 +422,7 @@ preconditionFailed = preconditionFailed' Headers.empty
-- | 412 with headers -- | 412 with headers
preconditionFailed' :: forall e. Headers.Headers -> ResponseM e preconditionFailed' :: forall e. Headers.Headers -> ResponseM e
preconditionFailed' = response' Status.preconditionFailed preconditionFailed' = emptyResponse' Status.preconditionFailed
-- | 413 -- | 413
payloadTooLarge :: forall e. ResponseM e payloadTooLarge :: forall e. ResponseM e
@ -421,7 +430,7 @@ payloadTooLarge = payloadTooLarge' Headers.empty
-- | 413 with headers -- | 413 with headers
payloadTooLarge' :: forall e. Headers.Headers -> ResponseM e payloadTooLarge' :: forall e. Headers.Headers -> ResponseM e
payloadTooLarge' = response' Status.payloadTooLarge payloadTooLarge' = emptyResponse' Status.payloadTooLarge
-- | 414 -- | 414
uRITooLong :: forall e. ResponseM e uRITooLong :: forall e. ResponseM e
@ -429,7 +438,7 @@ uRITooLong = uRITooLong' Headers.empty
-- | 414 with headers -- | 414 with headers
uRITooLong' :: forall e. Headers.Headers -> ResponseM e uRITooLong' :: forall e. Headers.Headers -> ResponseM e
uRITooLong' = response' Status.uRITooLong uRITooLong' = emptyResponse' Status.uRITooLong
-- | 415 -- | 415
unsupportedMediaType :: forall e. ResponseM e unsupportedMediaType :: forall e. ResponseM e
@ -437,7 +446,7 @@ unsupportedMediaType = unsupportedMediaType' Headers.empty
-- | 415 with headers -- | 415 with headers
unsupportedMediaType' :: forall e. Headers.Headers -> ResponseM e unsupportedMediaType' :: forall e. Headers.Headers -> ResponseM e
unsupportedMediaType' = response' Status.unsupportedMediaType unsupportedMediaType' = emptyResponse' Status.unsupportedMediaType
-- | 416 -- | 416
rangeNotSatisfiable :: forall e. ResponseM e rangeNotSatisfiable :: forall e. ResponseM e
@ -445,7 +454,7 @@ rangeNotSatisfiable = rangeNotSatisfiable' Headers.empty
-- | 416 with headers -- | 416 with headers
rangeNotSatisfiable' :: forall e. Headers.Headers -> ResponseM e rangeNotSatisfiable' :: forall e. Headers.Headers -> ResponseM e
rangeNotSatisfiable' = response' Status.rangeNotSatisfiable rangeNotSatisfiable' = emptyResponse' Status.rangeNotSatisfiable
-- | 417 -- | 417
expectationFailed :: forall e. ResponseM e expectationFailed :: forall e. ResponseM e
@ -453,7 +462,7 @@ expectationFailed = expectationFailed' Headers.empty
-- | 417 with headers -- | 417 with headers
expectationFailed' :: forall e. Headers.Headers -> ResponseM e expectationFailed' :: forall e. Headers.Headers -> ResponseM e
expectationFailed' = response' Status.expectationFailed expectationFailed' = emptyResponse' Status.expectationFailed
-- | 418 -- | 418
imATeapot :: forall e. ResponseM e imATeapot :: forall e. ResponseM e
@ -461,7 +470,7 @@ imATeapot = imATeapot' Headers.empty
-- | 418 with headers -- | 418 with headers
imATeapot' :: forall e. Headers.Headers -> ResponseM e imATeapot' :: forall e. Headers.Headers -> ResponseM e
imATeapot' = response' Status.imATeapot imATeapot' = emptyResponse' Status.imATeapot
-- | 421 -- | 421
misdirectedRequest :: forall e. ResponseM e misdirectedRequest :: forall e. ResponseM e
@ -469,7 +478,7 @@ misdirectedRequest = misdirectedRequest' Headers.empty
-- | 421 with headers -- | 421 with headers
misdirectedRequest' :: forall e. Headers.Headers -> ResponseM e misdirectedRequest' :: forall e. Headers.Headers -> ResponseM e
misdirectedRequest' = response' Status.misdirectedRequest misdirectedRequest' = emptyResponse' Status.misdirectedRequest
-- | 422 -- | 422
unprocessableEntity :: forall e. ResponseM e unprocessableEntity :: forall e. ResponseM e
@ -477,7 +486,7 @@ unprocessableEntity = unprocessableEntity' Headers.empty
-- | 422 with headers -- | 422 with headers
unprocessableEntity' :: forall e. Headers.Headers -> ResponseM e unprocessableEntity' :: forall e. Headers.Headers -> ResponseM e
unprocessableEntity' = response' Status.unprocessableEntity unprocessableEntity' = emptyResponse' Status.unprocessableEntity
-- | 423 -- | 423
locked :: forall e. ResponseM e locked :: forall e. ResponseM e
@ -485,7 +494,7 @@ locked = locked' Headers.empty
-- | 423 with headers -- | 423 with headers
locked' :: forall e. Headers.Headers -> ResponseM e locked' :: forall e. Headers.Headers -> ResponseM e
locked' = response' Status.locked locked' = emptyResponse' Status.locked
-- | 424 -- | 424
failedDependency :: forall e. ResponseM e failedDependency :: forall e. ResponseM e
@ -493,7 +502,7 @@ failedDependency = failedDependency' Headers.empty
-- | 424 with headers -- | 424 with headers
failedDependency' :: forall e. Headers.Headers -> ResponseM e failedDependency' :: forall e. Headers.Headers -> ResponseM e
failedDependency' = response' Status.failedDependency failedDependency' = emptyResponse' Status.failedDependency
-- | 426 -- | 426
upgradeRequired :: forall e. ResponseM e upgradeRequired :: forall e. ResponseM e
@ -501,7 +510,7 @@ upgradeRequired = upgradeRequired' Headers.empty
-- | 426 with headers -- | 426 with headers
upgradeRequired' :: forall e. Headers.Headers -> ResponseM e upgradeRequired' :: forall e. Headers.Headers -> ResponseM e
upgradeRequired' = response' Status.upgradeRequired upgradeRequired' = emptyResponse' Status.upgradeRequired
-- | 428 -- | 428
preconditionRequired :: forall e. ResponseM e preconditionRequired :: forall e. ResponseM e
@ -509,7 +518,7 @@ preconditionRequired = preconditionRequired' Headers.empty
-- | 428 with headers -- | 428 with headers
preconditionRequired' :: forall e. Headers.Headers -> ResponseM e preconditionRequired' :: forall e. Headers.Headers -> ResponseM e
preconditionRequired' = response' Status.preconditionRequired preconditionRequired' = emptyResponse' Status.preconditionRequired
-- | 429 -- | 429
tooManyRequests :: forall e. ResponseM e tooManyRequests :: forall e. ResponseM e
@ -517,7 +526,7 @@ tooManyRequests = tooManyRequests' Headers.empty
-- | 429 with headers -- | 429 with headers
tooManyRequests' :: forall e. Headers.Headers -> ResponseM e tooManyRequests' :: forall e. Headers.Headers -> ResponseM e
tooManyRequests' = response' Status.tooManyRequests tooManyRequests' = emptyResponse' Status.tooManyRequests
-- | 431 -- | 431
requestHeaderFieldsTooLarge :: forall e. ResponseM e requestHeaderFieldsTooLarge :: forall e. ResponseM e
@ -525,7 +534,7 @@ requestHeaderFieldsTooLarge = requestHeaderFieldsTooLarge' Headers.empty
-- | 431 with headers -- | 431 with headers
requestHeaderFieldsTooLarge' :: forall e. Headers.Headers -> ResponseM e requestHeaderFieldsTooLarge' :: forall e. Headers.Headers -> ResponseM e
requestHeaderFieldsTooLarge' = response' Status.requestHeaderFieldsTooLarge requestHeaderFieldsTooLarge' = emptyResponse' Status.requestHeaderFieldsTooLarge
-- | 451 -- | 451
unavailableForLegalReasons :: forall e. ResponseM e unavailableForLegalReasons :: forall e. ResponseM e
@ -533,7 +542,7 @@ unavailableForLegalReasons = unavailableForLegalReasons' Headers.empty
-- | 451 with headers -- | 451 with headers
unavailableForLegalReasons' :: forall e. Headers.Headers -> ResponseM e unavailableForLegalReasons' :: forall e. Headers.Headers -> ResponseM e
unavailableForLegalReasons' = response' Status.unavailableForLegalReasons unavailableForLegalReasons' = emptyResponse' Status.unavailableForLegalReasons
--------- ---------
-- 5xx -- -- 5xx --
@ -545,7 +554,7 @@ internalServerError = internalServerError' Headers.empty
-- | 500 with headers -- | 500 with headers
internalServerError' :: forall e. Headers.Headers -> Body.Body -> ResponseM e internalServerError' :: forall e. Headers.Headers -> Body.Body -> ResponseM e
internalServerError' = response Status.internalServerError internalServerError' = response' Status.internalServerError
-- | 501 -- | 501
notImplemented :: forall e. ResponseM e notImplemented :: forall e. ResponseM e
@ -553,7 +562,7 @@ notImplemented = notImplemented' Headers.empty
-- | 501 with headers -- | 501 with headers
notImplemented' :: forall e. Headers.Headers -> ResponseM e notImplemented' :: forall e. Headers.Headers -> ResponseM e
notImplemented' = response' Status.notImplemented notImplemented' = emptyResponse' Status.notImplemented
-- | 502 -- | 502
badGateway :: forall e. ResponseM e badGateway :: forall e. ResponseM e
@ -561,7 +570,7 @@ badGateway = badGateway' Headers.empty
-- | 502 with headers -- | 502 with headers
badGateway' :: forall e. Headers.Headers -> ResponseM e badGateway' :: forall e. Headers.Headers -> ResponseM e
badGateway' = response' Status.badGateway badGateway' = emptyResponse' Status.badGateway
-- | 503 -- | 503
serviceUnavailable :: forall e. ResponseM e serviceUnavailable :: forall e. ResponseM e
@ -569,7 +578,7 @@ serviceUnavailable = serviceUnavailable' Headers.empty
-- | 503 with headers -- | 503 with headers
serviceUnavailable' :: forall e. Headers.Headers -> ResponseM e serviceUnavailable' :: forall e. Headers.Headers -> ResponseM e
serviceUnavailable' = response' Status.serviceUnavailable serviceUnavailable' = emptyResponse' Status.serviceUnavailable
-- | 504 -- | 504
gatewayTimeout :: forall e. ResponseM e gatewayTimeout :: forall e. ResponseM e
@ -577,7 +586,7 @@ gatewayTimeout = gatewayTimeout' Headers.empty
-- | 504 with headers -- | 504 with headers
gatewayTimeout' :: forall e. Headers.Headers -> ResponseM e gatewayTimeout' :: forall e. Headers.Headers -> ResponseM e
gatewayTimeout' = response' Status.gatewayTimeout gatewayTimeout' = emptyResponse' Status.gatewayTimeout
-- | 505 -- | 505
hTTPVersionNotSupported :: forall e. ResponseM e hTTPVersionNotSupported :: forall e. ResponseM e
@ -585,7 +594,7 @@ hTTPVersionNotSupported = hTTPVersionNotSupported' Headers.empty
-- | 505 with headers -- | 505 with headers
hTTPVersionNotSupported' :: forall e. Headers.Headers -> ResponseM e hTTPVersionNotSupported' :: forall e. Headers.Headers -> ResponseM e
hTTPVersionNotSupported' = response' Status.hTTPVersionNotSupported hTTPVersionNotSupported' = emptyResponse' Status.hTTPVersionNotSupported
-- | 506 -- | 506
variantAlsoNegotiates :: forall e. ResponseM e variantAlsoNegotiates :: forall e. ResponseM e
@ -593,7 +602,7 @@ variantAlsoNegotiates = variantAlsoNegotiates' Headers.empty
-- | 506 with headers -- | 506 with headers
variantAlsoNegotiates' :: forall e. Headers.Headers -> ResponseM e variantAlsoNegotiates' :: forall e. Headers.Headers -> ResponseM e
variantAlsoNegotiates' = response' Status.variantAlsoNegotiates variantAlsoNegotiates' = emptyResponse' Status.variantAlsoNegotiates
-- | 507 -- | 507
insufficientStorage :: forall e. ResponseM e insufficientStorage :: forall e. ResponseM e
@ -601,7 +610,7 @@ insufficientStorage = insufficientStorage' Headers.empty
-- | 507 with headers -- | 507 with headers
insufficientStorage' :: forall e. Headers.Headers -> ResponseM e insufficientStorage' :: forall e. Headers.Headers -> ResponseM e
insufficientStorage' = response' Status.insufficientStorage insufficientStorage' = emptyResponse' Status.insufficientStorage
-- | 508 -- | 508
loopDetected :: forall e. ResponseM e loopDetected :: forall e. ResponseM e
@ -609,7 +618,7 @@ loopDetected = loopDetected' Headers.empty
-- | 508 with headers -- | 508 with headers
loopDetected' :: forall e. Headers.Headers -> ResponseM e loopDetected' :: forall e. Headers.Headers -> ResponseM e
loopDetected' = response' Status.loopDetected loopDetected' = emptyResponse' Status.loopDetected
-- | 510 -- | 510
notExtended :: forall e. ResponseM e notExtended :: forall e. ResponseM e
@ -617,7 +626,7 @@ notExtended = notExtended' Headers.empty
-- | 510 with headers -- | 510 with headers
notExtended' :: forall e. Headers.Headers -> ResponseM e notExtended' :: forall e. Headers.Headers -> ResponseM e
notExtended' = response' Status.notExtended notExtended' = emptyResponse' Status.notExtended
-- | 511 -- | 511
networkAuthenticationRequired :: forall e. ResponseM e networkAuthenticationRequired :: forall e. ResponseM e
@ -625,4 +634,5 @@ networkAuthenticationRequired = networkAuthenticationRequired' Headers.empty
-- | 511 with headers -- | 511 with headers
networkAuthenticationRequired' :: forall e. Headers.Headers -> ResponseM e networkAuthenticationRequired' :: forall e. Headers.Headers -> ResponseM e
networkAuthenticationRequired' = response' Status.networkAuthenticationRequired networkAuthenticationRequired' =
emptyResponse' Status.networkAuthenticationRequired

View File

@ -37,6 +37,18 @@ sendSpec = Spec.describe "send" do
responseFunctionSpec :: SpecHelpers.Test responseFunctionSpec :: SpecHelpers.Test
responseFunctionSpec = Spec.describe "response" do responseFunctionSpec = Spec.describe "response" do
Spec.it "has the right status" do
resp <- Response.response 123 "test"
resp.status ?= 123
Spec.it "has empty headers" do
resp <- Response.response 123 "test"
resp.headers ?= Headers.empty
Spec.it "has the right body" do
resp <- Response.response 123 "test"
resp.body ?= "test"
response'Spec :: SpecHelpers.Test
response'Spec = Spec.describe "response'" do
Spec.it "has the right status" do Spec.it "has the right status" do
resp <- mockResponse resp <- mockResponse
resp.status ?= 123 resp.status ?= 123
@ -48,10 +60,22 @@ responseFunctionSpec = Spec.describe "response" do
resp.body ?= "test" resp.body ?= "test"
where where
mockHeaders = Headers.header "Test" "test" mockHeaders = Headers.header "Test" "test"
mockResponse = Response.response 123 mockHeaders "test" mockResponse = Response.response' 123 mockHeaders "test"
response'Spec :: SpecHelpers.Test emptyResponseSpec :: SpecHelpers.Test
response'Spec = Spec.describe "response'" do emptyResponseSpec = Spec.describe "emptyResponse" do
Spec.it "has the right status" do
resp <- Response.emptyResponse 123
resp.status ?= 123
Spec.it "has empty headers" do
resp <- Response.emptyResponse 123
resp.headers ?= Headers.empty
Spec.it "has an empty body" do
resp <- Response.emptyResponse 123
resp.body ?= ""
emptyResponse'Spec :: SpecHelpers.Test
emptyResponse'Spec = Spec.describe "emptyResponse'" do
Spec.it "has the right status" do Spec.it "has the right status" do
resp <- mockResponse resp <- mockResponse
resp.status ?= 123 resp.status ?= 123
@ -63,10 +87,12 @@ response'Spec = Spec.describe "response'" do
resp.body ?= "" resp.body ?= ""
where where
mockHeaders = Headers.header "Test" "test" mockHeaders = Headers.header "Test" "test"
mockResponse = Response.response' 123 mockHeaders mockResponse = Response.emptyResponse' 123 mockHeaders
responseSpec :: SpecHelpers.Test responseSpec :: SpecHelpers.Test
responseSpec = Spec.describe "Response" do responseSpec = Spec.describe "Response" do
sendSpec sendSpec
responseFunctionSpec responseFunctionSpec
response'Spec response'Spec
emptyResponseSpec
emptyResponse'Spec