Add Headers.empty and Headers.header (#78)
This commit is contained in:
parent
48c529e9be
commit
f4599b276b
@ -8,7 +8,7 @@ module HTTPure
|
||||
, module HTTPure.Server
|
||||
) where
|
||||
|
||||
import HTTPure.Headers (Headers, headers)
|
||||
import HTTPure.Headers (Headers, empty, header, headers)
|
||||
import HTTPure.Lookup (lookup, (!!))
|
||||
import HTTPure.Method (Method(..))
|
||||
import HTTPure.Path (Path)
|
||||
|
@ -1,6 +1,8 @@
|
||||
module HTTPure.Headers
|
||||
( Headers
|
||||
, empty
|
||||
, headers
|
||||
, header
|
||||
, read
|
||||
, write
|
||||
) where
|
||||
@ -56,6 +58,14 @@ write :: forall e.
|
||||
write response (Headers headers') = void $
|
||||
TraversableWithIndex.traverseWithIndex (HTTP.setHeader response) headers'
|
||||
|
||||
-- | Return a `Headers` containing nothing.
|
||||
empty :: Headers
|
||||
empty = Headers StrMap.empty
|
||||
|
||||
-- | Convert an `Array` of `Tuples` of 2 `Strings` to a `Headers` object.
|
||||
headers :: Array (Tuple.Tuple String String) -> Headers
|
||||
headers = StrMap.fromFoldable >>> Headers
|
||||
|
||||
-- | Create a singleton header from a key-value pair.
|
||||
header :: String -> String -> Headers
|
||||
header key = StrMap.singleton key >>> Headers
|
||||
|
@ -129,7 +129,7 @@ response' status headers = response status headers $ ""
|
||||
|
||||
-- | 100
|
||||
continue :: forall e. ResponseM e
|
||||
continue = continue' $ Headers.headers []
|
||||
continue = continue' Headers.empty
|
||||
|
||||
-- | 100 with headers
|
||||
continue' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -137,7 +137,7 @@ continue' = response' Status.continue
|
||||
|
||||
-- | 101
|
||||
switchingProtocols :: forall e. ResponseM e
|
||||
switchingProtocols = switchingProtocols' $ Headers.headers []
|
||||
switchingProtocols = switchingProtocols' Headers.empty
|
||||
|
||||
-- | 101 with headers
|
||||
switchingProtocols' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -145,7 +145,7 @@ switchingProtocols' = response' Status.switchingProtocols
|
||||
|
||||
-- | 102
|
||||
processing :: forall e. ResponseM e
|
||||
processing = processing' $ Headers.headers []
|
||||
processing = processing' Headers.empty
|
||||
|
||||
-- | 102 with headers
|
||||
processing' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -157,7 +157,7 @@ processing' = response' Status.processing
|
||||
|
||||
-- | 200
|
||||
ok :: forall e. Body.Body -> ResponseM e
|
||||
ok = ok' $ Headers.headers []
|
||||
ok = ok' Headers.empty
|
||||
|
||||
-- | 200 with headers
|
||||
ok' :: forall e. Headers.Headers -> Body.Body -> ResponseM e
|
||||
@ -165,7 +165,7 @@ ok' = response Status.ok
|
||||
|
||||
-- | 201
|
||||
created :: forall e. ResponseM e
|
||||
created = created' $ Headers.headers []
|
||||
created = created' Headers.empty
|
||||
|
||||
-- | 201 with headers
|
||||
created' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -173,7 +173,7 @@ created' = response' Status.created
|
||||
|
||||
-- | 202
|
||||
accepted :: forall e. ResponseM e
|
||||
accepted = accepted' $ Headers.headers []
|
||||
accepted = accepted' Headers.empty
|
||||
|
||||
-- | 202 with headers
|
||||
accepted' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -181,7 +181,7 @@ accepted' = response' Status.accepted
|
||||
|
||||
-- | 203
|
||||
nonAuthoritativeInformation :: forall e. Body.Body -> ResponseM e
|
||||
nonAuthoritativeInformation = nonAuthoritativeInformation' $ Headers.headers []
|
||||
nonAuthoritativeInformation = nonAuthoritativeInformation' Headers.empty
|
||||
|
||||
-- | 203 with headers
|
||||
nonAuthoritativeInformation' :: forall e.
|
||||
@ -192,7 +192,7 @@ nonAuthoritativeInformation' = response Status.nonAuthoritativeInformation
|
||||
|
||||
-- | 204
|
||||
noContent :: forall e. ResponseM e
|
||||
noContent = noContent' $ Headers.headers []
|
||||
noContent = noContent' Headers.empty
|
||||
|
||||
-- | 204 with headers
|
||||
noContent' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -200,7 +200,7 @@ noContent' = response' Status.noContent
|
||||
|
||||
-- | 205
|
||||
resetContent :: forall e. ResponseM e
|
||||
resetContent = resetContent' $ Headers.headers []
|
||||
resetContent = resetContent' Headers.empty
|
||||
|
||||
-- | 205 with headers
|
||||
resetContent' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -208,7 +208,7 @@ resetContent' = response' Status.resetContent
|
||||
|
||||
-- | 206
|
||||
partialContent :: forall e. Body.Body -> ResponseM e
|
||||
partialContent = partialContent' $ Headers.headers []
|
||||
partialContent = partialContent' Headers.empty
|
||||
|
||||
-- | 206 with headers
|
||||
partialContent' :: forall e. Headers.Headers -> Body.Body -> ResponseM e
|
||||
@ -216,7 +216,7 @@ partialContent' = response Status.partialContent
|
||||
|
||||
-- | 207
|
||||
multiStatus :: forall e. Body.Body -> ResponseM e
|
||||
multiStatus = multiStatus' $ Headers.headers []
|
||||
multiStatus = multiStatus' Headers.empty
|
||||
|
||||
-- | 207 with headers
|
||||
multiStatus' :: forall e. Headers.Headers -> Body.Body -> ResponseM e
|
||||
@ -224,7 +224,7 @@ multiStatus' = response Status.multiStatus
|
||||
|
||||
-- | 208
|
||||
alreadyReported :: forall e. ResponseM e
|
||||
alreadyReported = alreadyReported' $ Headers.headers []
|
||||
alreadyReported = alreadyReported' Headers.empty
|
||||
|
||||
-- | 208 with headers
|
||||
alreadyReported' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -232,7 +232,7 @@ alreadyReported' = response' Status.alreadyReported
|
||||
|
||||
-- | 226
|
||||
iMUsed :: forall e. Body.Body -> ResponseM e
|
||||
iMUsed = iMUsed' $ Headers.headers []
|
||||
iMUsed = iMUsed' Headers.empty
|
||||
|
||||
-- | 226 with headers
|
||||
iMUsed' :: forall e. Headers.Headers -> Body.Body -> ResponseM e
|
||||
@ -244,7 +244,7 @@ iMUsed' = response Status.iMUsed
|
||||
|
||||
-- | 300
|
||||
multipleChoices :: forall e. Body.Body -> ResponseM e
|
||||
multipleChoices = multipleChoices' $ Headers.headers []
|
||||
multipleChoices = multipleChoices' Headers.empty
|
||||
|
||||
-- | 300 with headers
|
||||
multipleChoices' :: forall e. Headers.Headers -> Body.Body -> ResponseM e
|
||||
@ -252,7 +252,7 @@ multipleChoices' = response Status.multipleChoices
|
||||
|
||||
-- | 301
|
||||
movedPermanently :: forall e. Body.Body -> ResponseM e
|
||||
movedPermanently = movedPermanently' $ Headers.headers []
|
||||
movedPermanently = movedPermanently' Headers.empty
|
||||
|
||||
-- | 301 with headers
|
||||
movedPermanently' :: forall e. Headers.Headers -> Body.Body -> ResponseM e
|
||||
@ -260,7 +260,7 @@ movedPermanently' = response Status.movedPermanently
|
||||
|
||||
-- | 302
|
||||
found :: forall e. Body.Body -> ResponseM e
|
||||
found = found' $ Headers.headers []
|
||||
found = found' Headers.empty
|
||||
|
||||
-- | 302 with headers
|
||||
found' :: forall e. Headers.Headers -> Body.Body -> ResponseM e
|
||||
@ -268,7 +268,7 @@ found' = response Status.found
|
||||
|
||||
-- | 303
|
||||
seeOther :: forall e. Body.Body -> ResponseM e
|
||||
seeOther = seeOther' $ Headers.headers []
|
||||
seeOther = seeOther' Headers.empty
|
||||
|
||||
-- | 303 with headers
|
||||
seeOther' :: forall e. Headers.Headers -> Body.Body -> ResponseM e
|
||||
@ -276,7 +276,7 @@ seeOther' = response Status.seeOther
|
||||
|
||||
-- | 304
|
||||
notModified :: forall e. ResponseM e
|
||||
notModified = notModified' $ Headers.headers []
|
||||
notModified = notModified' Headers.empty
|
||||
|
||||
-- | 304 with headers
|
||||
notModified' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -284,7 +284,7 @@ notModified' = response' Status.notModified
|
||||
|
||||
-- | 305
|
||||
useProxy :: forall e. Body.Body -> ResponseM e
|
||||
useProxy = useProxy' $ Headers.headers []
|
||||
useProxy = useProxy' Headers.empty
|
||||
|
||||
-- | 305 with headers
|
||||
useProxy' :: forall e. Headers.Headers -> Body.Body -> ResponseM e
|
||||
@ -292,7 +292,7 @@ useProxy' = response Status.useProxy
|
||||
|
||||
-- | 307
|
||||
temporaryRedirect :: forall e. Body.Body -> ResponseM e
|
||||
temporaryRedirect = temporaryRedirect' $ Headers.headers []
|
||||
temporaryRedirect = temporaryRedirect' Headers.empty
|
||||
|
||||
-- | 307 with headers
|
||||
temporaryRedirect' :: forall e. Headers.Headers -> Body.Body -> ResponseM e
|
||||
@ -300,7 +300,7 @@ temporaryRedirect' = response Status.temporaryRedirect
|
||||
|
||||
-- | 308
|
||||
permanentRedirect :: forall e. Body.Body -> ResponseM e
|
||||
permanentRedirect = permanentRedirect' $ Headers.headers []
|
||||
permanentRedirect = permanentRedirect' Headers.empty
|
||||
|
||||
-- | 308 with headers
|
||||
permanentRedirect' :: forall e. Headers.Headers -> Body.Body -> ResponseM e
|
||||
@ -313,7 +313,7 @@ permanentRedirect' = response Status.permanentRedirect
|
||||
|
||||
-- | 400
|
||||
badRequest :: forall e. Body.Body -> ResponseM e
|
||||
badRequest = badRequest' $ Headers.headers []
|
||||
badRequest = badRequest' Headers.empty
|
||||
|
||||
-- | 400 with headers
|
||||
badRequest' :: forall e. Headers.Headers -> Body.Body -> ResponseM e
|
||||
@ -321,7 +321,7 @@ badRequest' = response Status.badRequest
|
||||
|
||||
-- | 401
|
||||
unauthorized :: forall e. ResponseM e
|
||||
unauthorized = unauthorized' $ Headers.headers []
|
||||
unauthorized = unauthorized' Headers.empty
|
||||
|
||||
-- | 401 with headers
|
||||
unauthorized' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -329,7 +329,7 @@ unauthorized' = response' Status.unauthorized
|
||||
|
||||
-- | 402
|
||||
paymentRequired :: forall e. ResponseM e
|
||||
paymentRequired = paymentRequired' $ Headers.headers []
|
||||
paymentRequired = paymentRequired' Headers.empty
|
||||
|
||||
-- | 402 with headers
|
||||
paymentRequired' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -337,7 +337,7 @@ paymentRequired' = response' Status.paymentRequired
|
||||
|
||||
-- | 403
|
||||
forbidden :: forall e. ResponseM e
|
||||
forbidden = forbidden' $ Headers.headers []
|
||||
forbidden = forbidden' Headers.empty
|
||||
|
||||
-- | 403 with headers
|
||||
forbidden' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -345,7 +345,7 @@ forbidden' = response' Status.forbidden
|
||||
|
||||
-- | 404
|
||||
notFound :: forall e. ResponseM e
|
||||
notFound = notFound' $ Headers.headers []
|
||||
notFound = notFound' Headers.empty
|
||||
|
||||
-- | 404 with headers
|
||||
notFound' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -353,7 +353,7 @@ notFound' = response' Status.notFound
|
||||
|
||||
-- | 405
|
||||
methodNotAllowed :: forall e. ResponseM e
|
||||
methodNotAllowed = methodNotAllowed' $ Headers.headers []
|
||||
methodNotAllowed = methodNotAllowed' Headers.empty
|
||||
|
||||
-- | 405 with headers
|
||||
methodNotAllowed' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -361,7 +361,7 @@ methodNotAllowed' = response' Status.methodNotAllowed
|
||||
|
||||
-- | 406
|
||||
notAcceptable :: forall e. ResponseM e
|
||||
notAcceptable = notAcceptable' $ Headers.headers []
|
||||
notAcceptable = notAcceptable' Headers.empty
|
||||
|
||||
-- | 406 with headers
|
||||
notAcceptable' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -369,7 +369,7 @@ notAcceptable' = response' Status.notAcceptable
|
||||
|
||||
-- | 407
|
||||
proxyAuthenticationRequired :: forall e. ResponseM e
|
||||
proxyAuthenticationRequired = proxyAuthenticationRequired' $ Headers.headers []
|
||||
proxyAuthenticationRequired = proxyAuthenticationRequired' Headers.empty
|
||||
|
||||
-- | 407 with headers
|
||||
proxyAuthenticationRequired' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -377,7 +377,7 @@ proxyAuthenticationRequired' = response' Status.proxyAuthenticationRequired
|
||||
|
||||
-- | 408
|
||||
requestTimeout :: forall e. ResponseM e
|
||||
requestTimeout = requestTimeout' $ Headers.headers []
|
||||
requestTimeout = requestTimeout' Headers.empty
|
||||
|
||||
-- | 408 with headers
|
||||
requestTimeout' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -385,7 +385,7 @@ requestTimeout' = response' Status.requestTimeout
|
||||
|
||||
-- | 409
|
||||
conflict :: forall e. Body.Body -> ResponseM e
|
||||
conflict = conflict' $ Headers.headers []
|
||||
conflict = conflict' Headers.empty
|
||||
|
||||
-- | 409 with headers
|
||||
conflict' :: forall e. Headers.Headers -> Body.Body -> ResponseM e
|
||||
@ -393,7 +393,7 @@ conflict' = response Status.conflict
|
||||
|
||||
-- | 410
|
||||
gone :: forall e. ResponseM e
|
||||
gone = gone' $ Headers.headers []
|
||||
gone = gone' Headers.empty
|
||||
|
||||
-- | 410 with headers
|
||||
gone' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -401,7 +401,7 @@ gone' = response' Status.gone
|
||||
|
||||
-- | 411
|
||||
lengthRequired :: forall e. ResponseM e
|
||||
lengthRequired = lengthRequired' $ Headers.headers []
|
||||
lengthRequired = lengthRequired' Headers.empty
|
||||
|
||||
-- | 411 with headers
|
||||
lengthRequired' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -409,7 +409,7 @@ lengthRequired' = response' Status.lengthRequired
|
||||
|
||||
-- | 412
|
||||
preconditionFailed :: forall e. ResponseM e
|
||||
preconditionFailed = preconditionFailed' $ Headers.headers []
|
||||
preconditionFailed = preconditionFailed' Headers.empty
|
||||
|
||||
-- | 412 with headers
|
||||
preconditionFailed' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -417,7 +417,7 @@ preconditionFailed' = response' Status.preconditionFailed
|
||||
|
||||
-- | 413
|
||||
payloadTooLarge :: forall e. ResponseM e
|
||||
payloadTooLarge = payloadTooLarge' $ Headers.headers []
|
||||
payloadTooLarge = payloadTooLarge' Headers.empty
|
||||
|
||||
-- | 413 with headers
|
||||
payloadTooLarge' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -425,7 +425,7 @@ payloadTooLarge' = response' Status.payloadTooLarge
|
||||
|
||||
-- | 414
|
||||
uRITooLong :: forall e. ResponseM e
|
||||
uRITooLong = uRITooLong' $ Headers.headers []
|
||||
uRITooLong = uRITooLong' Headers.empty
|
||||
|
||||
-- | 414 with headers
|
||||
uRITooLong' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -433,7 +433,7 @@ uRITooLong' = response' Status.uRITooLong
|
||||
|
||||
-- | 415
|
||||
unsupportedMediaType :: forall e. ResponseM e
|
||||
unsupportedMediaType = unsupportedMediaType' $ Headers.headers []
|
||||
unsupportedMediaType = unsupportedMediaType' Headers.empty
|
||||
|
||||
-- | 415 with headers
|
||||
unsupportedMediaType' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -441,7 +441,7 @@ unsupportedMediaType' = response' Status.unsupportedMediaType
|
||||
|
||||
-- | 416
|
||||
rangeNotSatisfiable :: forall e. ResponseM e
|
||||
rangeNotSatisfiable = rangeNotSatisfiable' $ Headers.headers []
|
||||
rangeNotSatisfiable = rangeNotSatisfiable' Headers.empty
|
||||
|
||||
-- | 416 with headers
|
||||
rangeNotSatisfiable' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -449,7 +449,7 @@ rangeNotSatisfiable' = response' Status.rangeNotSatisfiable
|
||||
|
||||
-- | 417
|
||||
expectationFailed :: forall e. ResponseM e
|
||||
expectationFailed = expectationFailed' $ Headers.headers []
|
||||
expectationFailed = expectationFailed' Headers.empty
|
||||
|
||||
-- | 417 with headers
|
||||
expectationFailed' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -457,7 +457,7 @@ expectationFailed' = response' Status.expectationFailed
|
||||
|
||||
-- | 418
|
||||
imATeapot :: forall e. ResponseM e
|
||||
imATeapot = imATeapot' $ Headers.headers []
|
||||
imATeapot = imATeapot' Headers.empty
|
||||
|
||||
-- | 418 with headers
|
||||
imATeapot' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -465,7 +465,7 @@ imATeapot' = response' Status.imATeapot
|
||||
|
||||
-- | 421
|
||||
misdirectedRequest :: forall e. ResponseM e
|
||||
misdirectedRequest = misdirectedRequest' $ Headers.headers []
|
||||
misdirectedRequest = misdirectedRequest' Headers.empty
|
||||
|
||||
-- | 421 with headers
|
||||
misdirectedRequest' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -473,7 +473,7 @@ misdirectedRequest' = response' Status.misdirectedRequest
|
||||
|
||||
-- | 422
|
||||
unprocessableEntity :: forall e. ResponseM e
|
||||
unprocessableEntity = unprocessableEntity' $ Headers.headers []
|
||||
unprocessableEntity = unprocessableEntity' Headers.empty
|
||||
|
||||
-- | 422 with headers
|
||||
unprocessableEntity' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -481,7 +481,7 @@ unprocessableEntity' = response' Status.unprocessableEntity
|
||||
|
||||
-- | 423
|
||||
locked :: forall e. ResponseM e
|
||||
locked = locked' $ Headers.headers []
|
||||
locked = locked' Headers.empty
|
||||
|
||||
-- | 423 with headers
|
||||
locked' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -489,7 +489,7 @@ locked' = response' Status.locked
|
||||
|
||||
-- | 424
|
||||
failedDependency :: forall e. ResponseM e
|
||||
failedDependency = failedDependency' $ Headers.headers []
|
||||
failedDependency = failedDependency' Headers.empty
|
||||
|
||||
-- | 424 with headers
|
||||
failedDependency' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -497,7 +497,7 @@ failedDependency' = response' Status.failedDependency
|
||||
|
||||
-- | 426
|
||||
upgradeRequired :: forall e. ResponseM e
|
||||
upgradeRequired = upgradeRequired' $ Headers.headers []
|
||||
upgradeRequired = upgradeRequired' Headers.empty
|
||||
|
||||
-- | 426 with headers
|
||||
upgradeRequired' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -505,7 +505,7 @@ upgradeRequired' = response' Status.upgradeRequired
|
||||
|
||||
-- | 428
|
||||
preconditionRequired :: forall e. ResponseM e
|
||||
preconditionRequired = preconditionRequired' $ Headers.headers []
|
||||
preconditionRequired = preconditionRequired' Headers.empty
|
||||
|
||||
-- | 428 with headers
|
||||
preconditionRequired' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -513,7 +513,7 @@ preconditionRequired' = response' Status.preconditionRequired
|
||||
|
||||
-- | 429
|
||||
tooManyRequests :: forall e. ResponseM e
|
||||
tooManyRequests = tooManyRequests' $ Headers.headers []
|
||||
tooManyRequests = tooManyRequests' Headers.empty
|
||||
|
||||
-- | 429 with headers
|
||||
tooManyRequests' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -521,7 +521,7 @@ tooManyRequests' = response' Status.tooManyRequests
|
||||
|
||||
-- | 431
|
||||
requestHeaderFieldsTooLarge :: forall e. ResponseM e
|
||||
requestHeaderFieldsTooLarge = requestHeaderFieldsTooLarge' $ Headers.headers []
|
||||
requestHeaderFieldsTooLarge = requestHeaderFieldsTooLarge' Headers.empty
|
||||
|
||||
-- | 431 with headers
|
||||
requestHeaderFieldsTooLarge' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -529,7 +529,7 @@ requestHeaderFieldsTooLarge' = response' Status.requestHeaderFieldsTooLarge
|
||||
|
||||
-- | 451
|
||||
unavailableForLegalReasons :: forall e. ResponseM e
|
||||
unavailableForLegalReasons = unavailableForLegalReasons' $ Headers.headers []
|
||||
unavailableForLegalReasons = unavailableForLegalReasons' Headers.empty
|
||||
|
||||
-- | 451 with headers
|
||||
unavailableForLegalReasons' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -541,7 +541,7 @@ unavailableForLegalReasons' = response' Status.unavailableForLegalReasons
|
||||
|
||||
-- | 500
|
||||
internalServerError :: forall e. Body.Body -> ResponseM e
|
||||
internalServerError = internalServerError' $ Headers.headers []
|
||||
internalServerError = internalServerError' Headers.empty
|
||||
|
||||
-- | 500 with headers
|
||||
internalServerError' :: forall e. Headers.Headers -> Body.Body -> ResponseM e
|
||||
@ -549,7 +549,7 @@ internalServerError' = response Status.internalServerError
|
||||
|
||||
-- | 501
|
||||
notImplemented :: forall e. ResponseM e
|
||||
notImplemented = notImplemented' $ Headers.headers []
|
||||
notImplemented = notImplemented' Headers.empty
|
||||
|
||||
-- | 501 with headers
|
||||
notImplemented' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -557,7 +557,7 @@ notImplemented' = response' Status.notImplemented
|
||||
|
||||
-- | 502
|
||||
badGateway :: forall e. ResponseM e
|
||||
badGateway = badGateway' $ Headers.headers []
|
||||
badGateway = badGateway' Headers.empty
|
||||
|
||||
-- | 502 with headers
|
||||
badGateway' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -565,7 +565,7 @@ badGateway' = response' Status.badGateway
|
||||
|
||||
-- | 503
|
||||
serviceUnavailable :: forall e. ResponseM e
|
||||
serviceUnavailable = serviceUnavailable' $ Headers.headers []
|
||||
serviceUnavailable = serviceUnavailable' Headers.empty
|
||||
|
||||
-- | 503 with headers
|
||||
serviceUnavailable' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -573,7 +573,7 @@ serviceUnavailable' = response' Status.serviceUnavailable
|
||||
|
||||
-- | 504
|
||||
gatewayTimeout :: forall e. ResponseM e
|
||||
gatewayTimeout = gatewayTimeout' $ Headers.headers []
|
||||
gatewayTimeout = gatewayTimeout' Headers.empty
|
||||
|
||||
-- | 504 with headers
|
||||
gatewayTimeout' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -581,7 +581,7 @@ gatewayTimeout' = response' Status.gatewayTimeout
|
||||
|
||||
-- | 505
|
||||
hTTPVersionNotSupported :: forall e. ResponseM e
|
||||
hTTPVersionNotSupported = hTTPVersionNotSupported' $ Headers.headers []
|
||||
hTTPVersionNotSupported = hTTPVersionNotSupported' Headers.empty
|
||||
|
||||
-- | 505 with headers
|
||||
hTTPVersionNotSupported' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -589,7 +589,7 @@ hTTPVersionNotSupported' = response' Status.hTTPVersionNotSupported
|
||||
|
||||
-- | 506
|
||||
variantAlsoNegotiates :: forall e. ResponseM e
|
||||
variantAlsoNegotiates = variantAlsoNegotiates' $ Headers.headers []
|
||||
variantAlsoNegotiates = variantAlsoNegotiates' Headers.empty
|
||||
|
||||
-- | 506 with headers
|
||||
variantAlsoNegotiates' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -597,7 +597,7 @@ variantAlsoNegotiates' = response' Status.variantAlsoNegotiates
|
||||
|
||||
-- | 507
|
||||
insufficientStorage :: forall e. ResponseM e
|
||||
insufficientStorage = insufficientStorage' $ Headers.headers []
|
||||
insufficientStorage = insufficientStorage' Headers.empty
|
||||
|
||||
-- | 507 with headers
|
||||
insufficientStorage' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -605,7 +605,7 @@ insufficientStorage' = response' Status.insufficientStorage
|
||||
|
||||
-- | 508
|
||||
loopDetected :: forall e. ResponseM e
|
||||
loopDetected = loopDetected' $ Headers.headers []
|
||||
loopDetected = loopDetected' Headers.empty
|
||||
|
||||
-- | 508 with headers
|
||||
loopDetected' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -613,7 +613,7 @@ loopDetected' = response' Status.loopDetected
|
||||
|
||||
-- | 510
|
||||
notExtended :: forall e. ResponseM e
|
||||
notExtended = notExtended' $ Headers.headers []
|
||||
notExtended = notExtended' Headers.empty
|
||||
|
||||
-- | 510 with headers
|
||||
notExtended' :: forall e. Headers.Headers -> ResponseM e
|
||||
@ -621,8 +621,7 @@ notExtended' = response' Status.notExtended
|
||||
|
||||
-- | 511
|
||||
networkAuthenticationRequired :: forall e. ResponseM e
|
||||
networkAuthenticationRequired =
|
||||
networkAuthenticationRequired' $ Headers.headers []
|
||||
networkAuthenticationRequired = networkAuthenticationRequired' Headers.empty
|
||||
|
||||
-- | 511 with headers
|
||||
networkAuthenticationRequired' :: forall e. Headers.Headers -> ResponseM e
|
||||
|
@ -17,83 +17,60 @@ lookupSpec = Spec.describe "lookup" do
|
||||
Spec.describe "when the string is in the header set" do
|
||||
Spec.describe "when searching with lowercase" do
|
||||
Spec.it "is the string" do
|
||||
mockHeaders !! "x-test" ?= "test"
|
||||
Headers.header "x-test" "test" !! "x-test" ?= "test"
|
||||
Spec.describe "when searching with uppercase" do
|
||||
Spec.it "is the string" do
|
||||
mockHeaders !! "X-Test" ?= "test"
|
||||
Headers.header "x-test" "test" !! "X-Test" ?= "test"
|
||||
Spec.describe "when the string is not in the header set" do
|
||||
Spec.it "is an empty string" do
|
||||
(Headers.headers []) !! "X-Test" ?= ""
|
||||
where
|
||||
mockHeaders = Headers.headers [Tuple.Tuple "x-test" "test"]
|
||||
Headers.empty !! "X-Test" ?= ""
|
||||
|
||||
showSpec :: SpecHelpers.Test
|
||||
showSpec = Spec.describe "show" do
|
||||
Spec.it "is a string representing the headers in HTTP format" do
|
||||
show mockHeaders ?= "Test1: test1\nTest2: test2\n\n"
|
||||
where
|
||||
mockHeaders =
|
||||
Headers.headers
|
||||
[ Tuple.Tuple "Test1" "test1"
|
||||
, Tuple.Tuple "Test2" "test2"
|
||||
]
|
||||
let mock = Headers.header "Test1" "1" <> Headers.header "Test2" "2"
|
||||
show mock ?= "Test1: 1\nTest2: 2\n\n"
|
||||
|
||||
eqSpec :: SpecHelpers.Test
|
||||
eqSpec = Spec.describe "eq" do
|
||||
Spec.describe "when the two Headers contain the same keys and values" do
|
||||
Spec.it "is true" do
|
||||
eq mockHeaders1 mockHeaders2 ?= true
|
||||
Headers.header "Test1" "test1" == Headers.header "Test1" "test1" ?= true
|
||||
Spec.describe "when the two Headers contain different keys and values" do
|
||||
Spec.it "is false" do
|
||||
eq mockHeaders1 mockHeaders3 ?= false
|
||||
Headers.header "Test1" "test1" == Headers.header "Test2" "test2" ?= false
|
||||
Spec.describe "when the two Headers contain only different values" do
|
||||
Spec.it "is false" do
|
||||
Headers.header "Test1" "test1" == Headers.header "Test1" "test2" ?= false
|
||||
Spec.describe "when the one Headers contains additional keys and values" do
|
||||
Spec.it "is false" do
|
||||
eq mockHeaders1 mockHeaders4 ?= false
|
||||
where
|
||||
mockHeaders1 = Headers.headers [ Tuple.Tuple "Test1" "test1" ]
|
||||
mockHeaders2 = Headers.headers [ Tuple.Tuple "Test1" "test1" ]
|
||||
mockHeaders3 = Headers.headers [ Tuple.Tuple "Test2" "test2" ]
|
||||
mockHeaders4 =
|
||||
Headers.headers
|
||||
[ Tuple.Tuple "Test1" "test1"
|
||||
, Tuple.Tuple "Test2" "test2"
|
||||
]
|
||||
let mock = Headers.header "Test1" "1" <> Headers.header "Test2" "2"
|
||||
Headers.header "Test1" "1" == mock ?= false
|
||||
|
||||
appendSpec :: SpecHelpers.Test
|
||||
appendSpec = Spec.describe "append" do
|
||||
Spec.describe "when there are multiple keys" do
|
||||
Spec.it "appends the headers correctly" do
|
||||
mockHeaders1 <> mockHeaders2 ?= mockHeaders3
|
||||
let mock1 = Headers.header "Test1" "1" <> Headers.header "Test2" "2"
|
||||
let mock2 = Headers.header "Test3" "3" <> Headers.header "Test4" "4"
|
||||
let mock3 = Headers.headers
|
||||
[ Tuple.Tuple "Test1" "1"
|
||||
, Tuple.Tuple "Test2" "2"
|
||||
, Tuple.Tuple "Test3" "3"
|
||||
, Tuple.Tuple "Test4" "4"
|
||||
]
|
||||
mock1 <> mock2 ?= mock3
|
||||
Spec.describe "when there is a duplicated key" do
|
||||
Spec.it "uses the last appended value" do
|
||||
mockHeadersDupe1 <> mockHeadersDupe2 ?= mockHeadersDupe2
|
||||
where
|
||||
mockHeadersDupe1 = Headers.headers [ Tuple.Tuple "Test" "foo" ]
|
||||
mockHeadersDupe2 = Headers.headers [ Tuple.Tuple "Test" "bar" ]
|
||||
mockHeaders1 =
|
||||
Headers.headers
|
||||
[ Tuple.Tuple "Test1" "test1"
|
||||
, Tuple.Tuple "Test2" "test2"
|
||||
]
|
||||
mockHeaders2 =
|
||||
Headers.headers
|
||||
[ Tuple.Tuple "Test3" "test3"
|
||||
, Tuple.Tuple "Test4" "test4"
|
||||
]
|
||||
mockHeaders3 =
|
||||
Headers.headers
|
||||
[ Tuple.Tuple "Test1" "test1"
|
||||
, Tuple.Tuple "Test2" "test2"
|
||||
, Tuple.Tuple "Test3" "test3"
|
||||
, Tuple.Tuple "Test4" "test4"
|
||||
]
|
||||
let mock = Headers.header "Test" "foo" <> Headers.header "Test" "bar"
|
||||
mock ?= Headers.header "Test" "bar"
|
||||
|
||||
readSpec :: SpecHelpers.Test
|
||||
readSpec = Spec.describe "read" do
|
||||
Spec.describe "with no headers" do
|
||||
Spec.it "is an empty StrMap" do
|
||||
request <- SpecHelpers.mockRequest "" "" "" []
|
||||
Headers.read request ?= Headers.headers []
|
||||
Headers.read request ?= Headers.empty
|
||||
Spec.describe "with headers" do
|
||||
Spec.it "is an StrMap with the contents of the headers" do
|
||||
let testHeader = [Tuple.Tuple "X-Test" "test"]
|
||||
@ -105,10 +82,32 @@ writeSpec = Spec.describe "write" do
|
||||
Spec.it "writes the headers to the response" do
|
||||
header <- EffClass.liftEff do
|
||||
mock <- SpecHelpers.mockResponse
|
||||
Headers.write mock $ Headers.headers [Tuple.Tuple "X-Test" "test"]
|
||||
Headers.write mock $ Headers.header "X-Test" "test"
|
||||
pure $ SpecHelpers.getResponseHeader "X-Test" mock
|
||||
header ?= "test"
|
||||
|
||||
emptySpec :: SpecHelpers.Test
|
||||
emptySpec = Spec.describe "empty" do
|
||||
Spec.it "is a empty StrMap in an empty Headers" do
|
||||
show Headers.empty ?= "\n"
|
||||
|
||||
headerSpec :: SpecHelpers.Test
|
||||
headerSpec = Spec.describe "header" do
|
||||
Spec.it "creates a singleton Headers" do
|
||||
show (Headers.header "X-Test" "test") ?= "X-Test: test\n\n"
|
||||
|
||||
headersFunctionSpec :: SpecHelpers.Test
|
||||
headersFunctionSpec = Spec.describe "headers" do
|
||||
Spec.it "is equivalent to using Headers.header with <>" do
|
||||
test ?= expected
|
||||
where
|
||||
test =
|
||||
Headers.headers
|
||||
[ Tuple.Tuple "X-Test-1" "1"
|
||||
, Tuple.Tuple "X-Test-2" "2"
|
||||
]
|
||||
expected = Headers.header "X-Test-1" "1" <> Headers.header "X-Test-2" "2"
|
||||
|
||||
headersSpec :: SpecHelpers.Test
|
||||
headersSpec = Spec.describe "Headers" do
|
||||
lookupSpec
|
||||
@ -117,3 +116,6 @@ headersSpec = Spec.describe "Headers" do
|
||||
appendSpec
|
||||
readSpec
|
||||
writeSpec
|
||||
emptySpec
|
||||
headerSpec
|
||||
headersFunctionSpec
|
||||
|
@ -3,8 +3,6 @@ module HTTPure.ResponseSpec where
|
||||
import Prelude
|
||||
|
||||
import Control.Monad.Eff.Class as EffClass
|
||||
import Data.Tuple as Tuple
|
||||
|
||||
import Test.Spec as Spec
|
||||
|
||||
import HTTPure.Headers as Headers
|
||||
@ -34,7 +32,7 @@ sendSpec = Spec.describe "send" do
|
||||
pure $ SpecHelpers.getResponseBody httpResponse
|
||||
body ?= "test"
|
||||
where
|
||||
mockHeaders = Headers.headers [ Tuple.Tuple "Test" "test" ]
|
||||
mockHeaders = Headers.header "Test" "test"
|
||||
mockResponse = { status: 123, headers: mockHeaders, body: "test" }
|
||||
|
||||
responseFunctionSpec :: SpecHelpers.Test
|
||||
@ -49,7 +47,7 @@ responseFunctionSpec = Spec.describe "response" do
|
||||
resp <- mockResponse
|
||||
resp.body ?= "test"
|
||||
where
|
||||
mockHeaders = Headers.headers [ Tuple.Tuple "Test" "test" ]
|
||||
mockHeaders = Headers.header "Test" "test"
|
||||
mockResponse = Response.response 123 mockHeaders "test"
|
||||
|
||||
response'Spec :: SpecHelpers.Test
|
||||
@ -64,7 +62,7 @@ response'Spec = Spec.describe "response'" do
|
||||
resp <- mockResponse
|
||||
resp.body ?= ""
|
||||
where
|
||||
mockHeaders = Headers.headers [ Tuple.Tuple "Test" "test" ]
|
||||
mockHeaders = Headers.header "Test" "test"
|
||||
mockResponse = Response.response' 123 mockHeaders
|
||||
|
||||
responseSpec :: SpecHelpers.Test
|
||||
|
Loading…
Reference in New Issue
Block a user