{-# LANGUAGE OverloadedStrings #-}
module Network.HTTP.Types.Status
(
Status(..)
, mkStatus
, status100
, continue100
, status101
, switchingProtocols101
, status200
, ok200
, status201
, created201
, status202
, accepted202
, status203
, nonAuthoritative203
, status204
, noContent204
, status205
, resetContent205
, status206
, partialContent206
, status300
, multipleChoices300
, status301
, movedPermanently301
, status302
, found302
, status303
, seeOther303
, status304
, notModified304
, status305
, useProxy305
, status307
, temporaryRedirect307
, status400
, badRequest400
, status401
, unauthorized401
, status402
, paymentRequired402
, status403
, forbidden403
, status404
, notFound404
, status405
, methodNotAllowed405
, status406
, notAcceptable406
, status407
, proxyAuthenticationRequired407
, status408
, requestTimeout408
, status409
, conflict409
, status410
, gone410
, status411
, lengthRequired411
, status412
, preconditionFailed412
, status413
, requestEntityTooLarge413
, status414
, requestURITooLong414
, status415
, unsupportedMediaType415
, status416
, requestedRangeNotSatisfiable416
, status417
, expectationFailed417
, status418
, imATeaPot418
, status428
, preconditionRequired428
, status429
, tooManyRequests429
, status431
, requestHeaderFieldsTooLarge431
, status500
, internalServerError500
, status501
, notImplemented501
, status502
, badGateway502
, status503
, serviceUnavailable503
, status504
, gatewayTimeout504
, status505
, status511
, networkAuthenticationRequired511
, httpVersionNotSupported505
, statusIsInformational
, statusIsSuccessful
, statusIsRedirection
, statusIsClientError
, statusIsServerError
)
where
import qualified Data.ByteString as B
data Status
= Status {
statusCode :: Int
, statusMessage :: B.ByteString
}
deriving (Show)
instance Eq Status where
Status { statusCode = a } == Status { statusCode = b } = a == b
instance Ord Status where
compare Status { statusCode = a } Status { statusCode = b } = a `compare` b
instance Enum Status where
fromEnum = statusCode
toEnum 100 = status100
toEnum 101 = status101
toEnum 200 = status200
toEnum 201 = status201
toEnum 202 = status202
toEnum 203 = status203
toEnum 204 = status204
toEnum 205 = status205
toEnum 206 = status206
toEnum 300 = status300
toEnum 301 = status301
toEnum 302 = status302
toEnum 303 = status303
toEnum 304 = status304
toEnum 305 = status305
toEnum 307 = status307
toEnum 400 = status400
toEnum 401 = status401
toEnum 402 = status402
toEnum 403 = status403
toEnum 404 = status404
toEnum 405 = status405
toEnum 406 = status406
toEnum 407 = status407
toEnum 408 = status408
toEnum 409 = status409
toEnum 410 = status410
toEnum 411 = status411
toEnum 412 = status412
toEnum 413 = status413
toEnum 414 = status414
toEnum 415 = status415
toEnum 416 = status416
toEnum 417 = status417
toEnum 500 = status500
toEnum 501 = status501
toEnum 502 = status502
toEnum 503 = status503
toEnum 504 = status504
toEnum 505 = status505
toEnum c = mkStatus c B.empty
mkStatus :: Int -> B.ByteString -> Status
mkStatus i m = Status i m
status100 :: Status
status100 = mkStatus 100 "Continue"
continue100 :: Status
continue100 = status100
status101 :: Status
status101 = mkStatus 101 "Switching Protocols"
switchingProtocols101 :: Status
switchingProtocols101 = status101
status200 :: Status
status200 = mkStatus 200 "OK"
ok200 :: Status
ok200 = status200
status201 :: Status
status201 = mkStatus 201 "Created"
created201 :: Status
created201 = status201
status202 :: Status
status202 = mkStatus 202 "Accepted"
accepted202 :: Status
accepted202 = status202
status203 :: Status
status203 = mkStatus 203 "Non-Authoritative Information"
nonAuthoritative203 :: Status
nonAuthoritative203 = status203
status204 :: Status
status204 = mkStatus 204 "No Content"
noContent204 :: Status
noContent204 = status204
status205 :: Status
status205 = mkStatus 205 "Reset Content"
resetContent205 :: Status
resetContent205 = status205
status206 :: Status
status206 = mkStatus 206 "Partial Content"
partialContent206 :: Status
partialContent206 = status206
status300 :: Status
status300 = mkStatus 300 "Multiple Choices"
multipleChoices300 :: Status
multipleChoices300 = status300
status301 :: Status
status301 = mkStatus 301 "Moved Permanently"
movedPermanently301 :: Status
movedPermanently301 = status301
status302 :: Status
status302 = mkStatus 302 "Found"
found302 :: Status
found302 = status302
status303 :: Status
status303 = mkStatus 303 "See Other"
seeOther303 :: Status
seeOther303 = status303
status304 :: Status
status304 = mkStatus 304 "Not Modified"
notModified304 :: Status
notModified304 = status304
status305 :: Status
status305 = mkStatus 305 "Use Proxy"
useProxy305 :: Status
useProxy305 = status305
status307 :: Status
status307 = mkStatus 307 "Temporary Redirect"
temporaryRedirect307 :: Status
temporaryRedirect307 = status307
status400 :: Status
status400 = mkStatus 400 "Bad Request"
badRequest400 :: Status
badRequest400 = status400
status401 :: Status
status401 = mkStatus 401 "Unauthorized"
unauthorized401 :: Status
unauthorized401 = status401
status402 :: Status
status402 = mkStatus 402 "Payment Required"
paymentRequired402 :: Status
paymentRequired402 = status402
status403 :: Status
status403 = mkStatus 403 "Forbidden"
forbidden403 :: Status
forbidden403 = status403
status404 :: Status
status404 = mkStatus 404 "Not Found"
notFound404 :: Status
notFound404 = status404
status405 :: Status
status405 = mkStatus 405 "Method Not Allowed"
methodNotAllowed405 :: Status
methodNotAllowed405 = status405
status406 :: Status
status406 = mkStatus 406 "Not Acceptable"
notAcceptable406 :: Status
notAcceptable406 = status406
status407 :: Status
status407 = mkStatus 407 "Proxy Authentication Required"
proxyAuthenticationRequired407 :: Status
proxyAuthenticationRequired407 = status407
status408 :: Status
status408 = mkStatus 408 "Request Timeout"
requestTimeout408 :: Status
requestTimeout408 = status408
status409 :: Status
status409 = mkStatus 409 "Conflict"
conflict409 :: Status
conflict409 = status409
status410 :: Status
status410 = mkStatus 410 "Gone"
gone410 :: Status
gone410 = status410
status411 :: Status
status411 = mkStatus 411 "Length Required"
lengthRequired411 :: Status
lengthRequired411 = status411
status412 :: Status
status412 = mkStatus 412 "Precondition Failed"
preconditionFailed412 :: Status
preconditionFailed412 = status412
status413 :: Status
status413 = mkStatus 413 "Request Entity Too Large"
requestEntityTooLarge413 :: Status
requestEntityTooLarge413 = status413
status414 :: Status
status414 = mkStatus 414 "Request-URI Too Long"
requestURITooLong414 :: Status
requestURITooLong414 = status414
status415 :: Status
status415 = mkStatus 415 "Unsupported Media Type"
unsupportedMediaType415 :: Status
unsupportedMediaType415 = status415
status416 :: Status
status416 = mkStatus 416 "Requested Range Not Satisfiable"
requestedRangeNotSatisfiable416 :: Status
requestedRangeNotSatisfiable416 = status416
status417 :: Status
status417 = mkStatus 417 "Expectation Failed"
expectationFailed417 :: Status
expectationFailed417 = status417
status418 :: Status
status418 = mkStatus 418 "I'm a teapot"
imATeaPot418 :: Status
imATeaPot418 = status418
status428 :: Status
status428 = mkStatus 428 "Precondition Required"
preconditionRequired428 :: Status
preconditionRequired428 = status428
status429 :: Status
status429 = mkStatus 429 "Too Many Requests"
tooManyRequests429 :: Status
tooManyRequests429 = status429
status431 :: Status
status431 = mkStatus 431 "Request Header Fields Too Large"
requestHeaderFieldsTooLarge431 :: Status
requestHeaderFieldsTooLarge431 = status431
status500 :: Status
status500 = mkStatus 500 "Internal Server Error"
internalServerError500 :: Status
internalServerError500 = status500
status501 :: Status
status501 = mkStatus 501 "Not Implemented"
notImplemented501 :: Status
notImplemented501 = status501
status502 :: Status
status502 = mkStatus 502 "Bad Gateway"
badGateway502 :: Status
badGateway502 = status502
status503 :: Status
status503 = mkStatus 503 "Service Unavailable"
serviceUnavailable503 :: Status
serviceUnavailable503 = status503
status504 :: Status
status504 = mkStatus 504 "Gateway Timeout"
gatewayTimeout504 :: Status
gatewayTimeout504 = status504
status505 :: Status
status505 = mkStatus 505 "HTTP Version Not Supported"
httpVersionNotSupported505 :: Status
httpVersionNotSupported505 = status505
status511 :: Status
status511 = mkStatus 511 "Network Authentication Required"
networkAuthenticationRequired511 :: Status
networkAuthenticationRequired511 = status511
statusIsInformational :: Status -> Bool
statusIsInformational (Status {statusCode=code}) = code >= 100 && code < 200
statusIsSuccessful :: Status -> Bool
statusIsSuccessful (Status {statusCode=code}) = code >= 200 && code < 300
statusIsRedirection :: Status -> Bool
statusIsRedirection (Status {statusCode=code}) = code >= 300 && code < 400
statusIsClientError :: Status -> Bool
statusIsClientError (Status {statusCode=code}) = code >= 400 && code < 500
statusIsServerError :: Status -> Bool
statusIsServerError (Status {statusCode=code}) = code >= 500 && code < 600