1 module Network.HTTP.Lucu.Response
4 , hPutResponse -- Handle -> Response -> IO ()
5 , isInformational -- StatusCode -> Bool
6 , isError -- StatusCode -> Bool
10 import Network.HTTP.Lucu.Headers
11 import Network.HTTP.Lucu.HttpVersion
15 data StatusCode = Continue
22 | NonAuthoritativeInformation
43 | ProxyAuthenticationRequired
49 | RequestEntityTooLarge
51 | UnsupportedMediaType
52 | RequestRangeNotSatisfiable
54 | UnprocessableEntitiy
63 | HttpVersionNotSupported
67 instance Show StatusCode where
68 show sc = let (num, msg) = statusCode sc
70 printf "%03d %s" num msg
73 data Response = Response {
74 resVersion :: HttpVersion
75 , resStatus :: StatusCode
76 , resHeaders :: Headers
80 instance HasHeaders Response where
81 getHeaders = resHeaders
82 setHeaders res hdr = res { resHeaders = hdr }
85 hPutResponse :: Handle -> Response -> IO ()
86 hPutResponse h res = do hPutHttpVersion h (resVersion res)
88 hPutStatus h (resStatus res)
90 hPutHeaders h (resHeaders res)
92 hPutStatus :: Handle -> StatusCode -> IO ()
93 hPutStatus h sc = let (num, msg) = statusCode sc
95 hPrintf h "%03d %s" num msg
98 isInformational :: StatusCode -> Bool
99 isInformational sc = let (num, _) = statusCode sc
102 isError :: StatusCode -> Bool
103 isError sc = let (num, _) = statusCode sc
107 statusCode :: StatusCode -> (Int, String)
108 statusCode Continue = (100, "Continue")
109 statusCode SwitchingProtocols = (101, "Switching Protocols")
110 statusCode Processing = (102, "Processing")
112 statusCode Ok = (200, "OK")
113 statusCode Created = (201, "Created")
114 statusCode Accepted = (202, "Accepted")
115 statusCode NonAuthoritativeInformation = (203, "Non Authoritative Information")
116 statusCode NoContent = (204, "No Content")
117 statusCode ResetContent = (205, "Reset Content")
118 statusCode PartialContent = (206, "Partial Content")
119 statusCode MultiStatus = (207, "Multi Status")
121 statusCode MultipleChoices = (300, "Multiple Choices")
122 statusCode MovedPermanently = (301, "Moved Permanently")
123 statusCode Found = (302, "Found")
124 statusCode SeeOther = (303, "See Other")
125 statusCode NotModified = (304, "Not Modified")
126 statusCode UseProxy = (305, "Use Proxy")
127 statusCode TemporaryRedirect = (306, "Temporary Redirect")
129 statusCode BadRequest = (400, "Bad Request")
130 statusCode Unauthorized = (401, "Unauthorized")
131 statusCode PaymentRequired = (402, "Payment Required")
132 statusCode Forbidden = (403, "Forbidden")
133 statusCode NotFound = (404, "Not Found")
134 statusCode MethodNotAllowed = (405, "Method Not Allowed")
135 statusCode NotAcceptable = (406, "Not Acceptable")
136 statusCode ProxyAuthenticationRequired = (407, "Proxy Authentication Required")
137 statusCode RequestTimeout = (408, "Request Timeout")
138 statusCode Conflict = (409, "Conflict")
139 statusCode Gone = (410, "Gone")
140 statusCode LengthRequired = (411, "Length Required")
141 statusCode PreconditionFailed = (412, "Precondition Failed")
142 statusCode RequestEntityTooLarge = (413, "Request Entity Too Large")
143 statusCode RequestURITooLarge = (414, "Request URI Too Large")
144 statusCode UnsupportedMediaType = (415, "Unsupported Media Type")
145 statusCode RequestRangeNotSatisfiable = (416, "Request Range Not Satisfiable")
146 statusCode ExpectationFailed = (417, "Expectation Failed")
147 statusCode UnprocessableEntitiy = (422, "Unprocessable Entity")
148 statusCode Locked = (423, "Locked")
149 statusCode FailedDependency = (424, "Failed Dependency")
151 statusCode InternalServerError = (500, "Internal Server Error")
152 statusCode NotImplemented = (501, "Not Implemented")
153 statusCode BadGateway = (502, "Bad Gateway")
154 statusCode ServiceUnavailable = (503, "Service Unavailable")
155 statusCode GatewayTimeout = (504, "Gateway Timeout")
156 statusCode HttpVersionNotSupported = (505, "HTTP Version Not Supported")
157 statusCode InsufficientStorage = (507, "Insufficient Storage")