Skip to content
Browse files

add mkStatus

  • Loading branch information...
1 parent 5f84ad4 commit 8d287072adccd90af437ae75e2912f4c25eb9321 @aristidb committed Aug 22, 2012
Showing with 50 additions and 41 deletions.
  1. +1 −0 Network/HTTP/Types.hs
  2. +49 −41 Network/HTTP/Types/Status.hs
View
1 Network/HTTP/Types.hs
@@ -24,6 +24,7 @@ module Network.HTTP.Types
, http11
-- * Status
, Status(..)
+, mkStatus
, status100
, continue100
, status101
View
90 Network/HTTP/Types/Status.hs
@@ -2,6 +2,7 @@
module Network.HTTP.Types.Status
(
Status(..)
+, mkStatus
, status100
, continue100
, status101
@@ -99,6 +100,9 @@ import Data.ByteString.Char8 () {- IsString -}
--
-- Only the 'statusCode' is used for comparisons.
--
+-- Please use 'mkStatus' to create status codes from code and message, or the 'Enum' instance or the
+-- status code constants (like 'ok200'). There might be additional record members in the future.
+--
-- Note that the Show instance is only for debugging.
data Status
= Status {
@@ -157,329 +161,333 @@ instance Enum Status where
toEnum 505 = status505
toEnum c = Status c B.empty
+-- | Create a Status from status code and message.
+mkStatus :: Int -> B.ByteString -> Status
+mkStatus = Status
+
-- | Continue 100
status100 :: Status
-status100 = Status 100 "Continue"
+status100 = mkStatus 100 "Continue"
-- | Continue 100
continue100 :: Status
continue100 = status100
-- | Switching Protocols 101
status101 :: Status
-status101 = Status 101 "Switching Protocols"
+status101 = mkStatus 101 "Switching Protocols"
-- | Switching Protocols 101
switchingProtocols101 :: Status
switchingProtocols101 = status101
-- | OK 200
status200 :: Status
-status200 = Status 200 "OK"
+status200 = mkStatus 200 "OK"
-- | OK 200
ok200 :: Status
ok200 = status200
-- | Created 201
status201 :: Status
-status201 = Status 201 "Created"
+status201 = mkStatus 201 "Created"
-- | Created 201
created201 :: Status
created201 = status201
-- | Accepted 202
status202 :: Status
-status202 = Status 202 "Accepted"
+status202 = mkStatus 202 "Accepted"
-- | Accepted 202
accepted202 :: Status
accepted202 = status202
-- | Non-Authoritative Information 203
status203 :: Status
-status203 = Status 203 "Non-Authoritative Information"
+status203 = mkStatus 203 "Non-Authoritative Information"
-- | Non-Authoritative Information 203
nonAuthoritative203 :: Status
nonAuthoritative203 = status203
-- | No Content 204
status204 :: Status
-status204 = Status 204 "No Content"
+status204 = mkStatus 204 "No Content"
-- | No Content 204
noContent204 :: Status
noContent204 = status204
-- | Reset Content 205
status205 :: Status
-status205 = Status 205 "Reset Content"
+status205 = mkStatus 205 "Reset Content"
-- | Reset Content 205
resetContent205 :: Status
resetContent205 = status205
-- | Partial Content 206
status206 :: Status
-status206 = Status 206 "Partial Content"
+status206 = mkStatus 206 "Partial Content"
-- | Partial Content 206
partialContent206 :: Status
partialContent206 = status206
-- | Multiple Choices 300
status300 :: Status
-status300 = Status 300 "Multiple Choices"
+status300 = mkStatus 300 "Multiple Choices"
-- | Multiple Choices 300
multipleChoices300 :: Status
multipleChoices300 = status300
-- | Moved Permanently 301
status301 :: Status
-status301 = Status 301 "Moved Permanently"
+status301 = mkStatus 301 "Moved Permanently"
-- | Moved Permanently 301
movedPermanently301 :: Status
movedPermanently301 = status301
-- | Found 302
status302 :: Status
-status302 = Status 302 "Found"
+status302 = mkStatus 302 "Found"
-- | Found 302
found302 :: Status
found302 = status302
-- | See Other 303
status303 :: Status
-status303 = Status 303 "See Other"
+status303 = mkStatus 303 "See Other"
-- | See Other 303
seeOther303 :: Status
seeOther303 = status303
-- | Not Modified 304
status304 :: Status
-status304 = Status 304 "Not Modified"
+status304 = mkStatus 304 "Not Modified"
-- | Not Modified 304
notModified304 :: Status
notModified304 = status304
-- | Use Proxy 305
status305 :: Status
-status305 = Status 305 "Use Proxy"
+status305 = mkStatus 305 "Use Proxy"
-- | Use Proxy 305
useProxy305 :: Status
useProxy305 = status305
-- | Temporary Redirect 307
status307 :: Status
-status307 = Status 307 "Temporary Redirect"
+status307 = mkStatus 307 "Temporary Redirect"
-- | Temporary Redirect 307
temporaryRedirect307 :: Status
temporaryRedirect307 = status307
-- | Bad Request 400
status400 :: Status
-status400 = Status 400 "Bad Request"
+status400 = mkStatus 400 "Bad Request"
-- | Bad Request 400
badRequest400 :: Status
badRequest400 = status400
-- | Unauthorized 401
status401 :: Status
-status401 = Status 401 "Unauthorized"
+status401 = mkStatus 401 "Unauthorized"
-- | Unauthorized 401
unauthorized401 :: Status
unauthorized401 = status401
-- | Payment Required 402
status402 :: Status
-status402 = Status 402 "Payment Required"
+status402 = mkStatus 402 "Payment Required"
-- | Payment Required 402
paymentRequired402 :: Status
paymentRequired402 = status402
-- | Forbidden 403
status403 :: Status
-status403 = Status 403 "Forbidden"
+status403 = mkStatus 403 "Forbidden"
-- | Forbidden 403
forbidden403 :: Status
forbidden403 = status403
-- | Not Found 404
status404 :: Status
-status404 = Status 404 "Not Found"
+status404 = mkStatus 404 "Not Found"
-- | Not Found 404
notFound404 :: Status
notFound404 = status404
-- | Method Not Allowed 405
status405 :: Status
-status405 = Status 405 "Method Not Allowed"
+status405 = mkStatus 405 "Method Not Allowed"
-- | Method Not Allowed 405
methodNotAllowed405 :: Status
methodNotAllowed405 = status405
-- | Not Acceptable 406
status406 :: Status
-status406 = Status 406 "Not Acceptable"
+status406 = mkStatus 406 "Not Acceptable"
-- | Not Acceptable 406
notAcceptable406 :: Status
notAcceptable406 = status406
-- | Proxy Authentication Required 407
status407 :: Status
-status407 = Status 407 "Proxy Authentication Required"
+status407 = mkStatus 407 "Proxy Authentication Required"
-- | Proxy Authentication Required 407
proxyAuthenticationRequired407 :: Status
proxyAuthenticationRequired407 = status407
-- | Request Timeout 408
status408 :: Status
-status408 = Status 408 "Request Timeout"
+status408 = mkStatus 408 "Request Timeout"
-- | Request Timeout 408
requestTimeout408 :: Status
requestTimeout408 = status408
-- | Conflict 409
status409 :: Status
-status409 = Status 409 "Conflict"
+status409 = mkStatus 409 "Conflict"
-- | Conflict 409
conflict409 :: Status
conflict409 = status409
-- | Gone 410
status410 :: Status
-status410 = Status 410 "Gone"
+status410 = mkStatus 410 "Gone"
-- | Gone 410
gone410 :: Status
gone410 = status410
-- | Length Required 411
status411 :: Status
-status411 = Status 411 "Length Required"
+status411 = mkStatus 411 "Length Required"
-- | Length Required 411
lengthRequired411 :: Status
lengthRequired411 = status411
-- | Precondition Failed 412
status412 :: Status
-status412 = Status 412 "Precondition Failed"
+status412 = mkStatus 412 "Precondition Failed"
-- | Precondition Failed 412
preconditionFailed412 :: Status
preconditionFailed412 = status412
-- | Request Entity Too Large 413
status413 :: Status
-status413 = Status 413 "Request Entity Too Large"
+status413 = mkStatus 413 "Request Entity Too Large"
-- | Request Entity Too Large 413
requestEntityTooLarge413 :: Status
requestEntityTooLarge413 = status413
-- | Request-URI Too Long 414
status414 :: Status
-status414 = Status 414 "Request-URI Too Long"
+status414 = mkStatus 414 "Request-URI Too Long"
-- | Request-URI Too Long 414
requestURITooLong414 :: Status
requestURITooLong414 = status414
-- | Unsupported Media Type 415
status415 :: Status
-status415 = Status 415 "Unsupported Media Type"
+status415 = mkStatus 415 "Unsupported Media Type"
-- | Unsupported Media Type 415
unsupportedMediaType415 :: Status
unsupportedMediaType415 = status415
-- | Requested Range Not Satisfiable 416
status416 :: Status
-status416 = Status 416 "Requested Range Not Satisfiable"
+status416 = mkStatus 416 "Requested Range Not Satisfiable"
-- | Requested Range Not Satisfiable 416
requestedRangeNotSatisfiable416 :: Status
requestedRangeNotSatisfiable416 = status416
-- | Expectation Failed 417
status417 :: Status
-status417 = Status 417 "Expectation Failed"
+status417 = mkStatus 417 "Expectation Failed"
-- | Expectation Failed 417
expectationFailed417 :: Status
expectationFailed417 = status417
-- | I'm a teapot 418
status418 :: Status
-status418 = Status 418 "I'm a teapot"
+status418 = mkStatus 418 "I'm a teapot"
-- | I'm a teapot 418
imATeaPot418 :: Status
imATeaPot418 = status418
-- | Internal Server Error 500
status500 :: Status
-status500 = Status 500 "Internal Server Error"
+status500 = mkStatus 500 "Internal Server Error"
-- | Internal Server Error 500
internalServerError500 :: Status
internalServerError500 = status500
-- | Not Implemented 501
status501 :: Status
-status501 = Status 501 "Not Implemented"
+status501 = mkStatus 501 "Not Implemented"
-- | Not Implemented 501
notImplemented501 :: Status
notImplemented501 = status501
-- | Bad Gateway 502
status502 :: Status
-status502 = Status 502 "Bad Gateway"
+status502 = mkStatus 502 "Bad Gateway"
-- | Bad Gateway 502
badGateway502 :: Status
badGateway502 = status502
-- | Service Unavailable 503
status503 :: Status
-status503 = Status 503 "Service Unavailable"
+status503 = mkStatus 503 "Service Unavailable"
-- | Service Unavailable 503
serviceUnavailable503 :: Status
serviceUnavailable503 = status503
-- | Gateway Timeout 504
status504 :: Status
-status504 = Status 504 "Gateway Timeout"
+status504 = mkStatus 504 "Gateway Timeout"
-- | Gateway Timeout 504
gatewayTimeout504 :: Status
gatewayTimeout504 = status504
-- | HTTP Version Not Supported 505
status505 :: Status
-status505 = Status 505 "HTTP Version Not Supported"
+status505 = mkStatus 505 "HTTP Version Not Supported"
-- | HTTP Version Not Supported 505
httpVersionNotSupported505 :: Status

0 comments on commit 8d28707

Please sign in to comment.
Something went wrong with that request. Please try again.