Skip to content

Commit 4fb767c

Browse files
ianpartridgephausler
authored andcommitted
Implement NSHTTPURLResponse.localizedStringForStatusCode()
1 parent 6488630 commit 4fb767c

File tree

1 file changed

+69
-1
lines changed

1 file changed

+69
-1
lines changed

Foundation/NSURLResponse.swift

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,75 @@ public class NSHTTPURLResponse : NSURLResponse {
190190
@param the status code to use to produce a localized string.
191191
@result A localized string corresponding to the given status code.
192192
*/
193-
public class func localizedString(forStatusCode statusCode: Int) -> String { NSUnimplemented() }
193+
public class func localizedString(forStatusCode statusCode: Int) -> String {
194+
switch statusCode {
195+
case 100: return "Continue"
196+
case 101: return "Switching Protocols"
197+
case 102: return "Processing"
198+
case 100...199: return "Informational"
199+
case 200: return "OK"
200+
case 201: return "Created"
201+
case 202: return "Accepted"
202+
case 203: return "Non-Authoritative Information"
203+
case 204: return "No Content"
204+
case 205: return "Reset Content"
205+
case 206: return "Partial Content"
206+
case 207: return "Multi-Status"
207+
case 208: return "Already Reported"
208+
case 226: return "IM Used"
209+
case 200...299: return "Success"
210+
case 300: return "Multiple Choices"
211+
case 301: return "Moved Permanently"
212+
case 302: return "Found"
213+
case 303: return "See Other"
214+
case 304: return "Not Modified"
215+
case 305: return "Use Proxy"
216+
case 307: return "Temporary Redirect"
217+
case 308: return "Permanent Redirect"
218+
case 300...399: return "Redirection"
219+
case 400: return "Bad Request"
220+
case 401: return "Unauthorized"
221+
case 402: return "Payment Required"
222+
case 403: return "Forbidden"
223+
case 404: return "Not Found"
224+
case 405: return "Method Not Allowed"
225+
case 406: return "Not Acceptable"
226+
case 407: return "Proxy Authentication Required"
227+
case 408: return "Request Timeout"
228+
case 409: return "Conflict"
229+
case 410: return "Gone"
230+
case 411: return "Length Required"
231+
case 412: return "Precondition Failed"
232+
case 413: return "Payload Too Large"
233+
case 414: return "URI Too Long"
234+
case 415: return "Unsupported Media Type"
235+
case 416: return "Range Not Satisfiable"
236+
case 417: return "Expectation Failed"
237+
case 421: return "Misdirected Request"
238+
case 422: return "Unprocessable Entity"
239+
case 423: return "Locked"
240+
case 424: return "Failed Dependency"
241+
case 426: return "Upgrade Required"
242+
case 428: return "Precondition Required"
243+
case 429: return "Too Many Requests"
244+
case 431: return "Request Header Fields Too Large"
245+
case 451: return "Unavailable For Legal Reasons"
246+
case 400...499: return "Client Error"
247+
case 500: return "Internal Server Error"
248+
case 501: return "Not Implemented"
249+
case 502: return "Bad Gateway"
250+
case 503: return "Service Unavailable"
251+
case 504: return "Gateway Timeout"
252+
case 505: return "HTTP Version Not Supported"
253+
case 506: return "Variant Also Negotiates"
254+
case 507: return "Insufficient Storage"
255+
case 508: return "Loop Detected"
256+
case 510: return "Not Extended"
257+
case 511: return "Network Authentication Required"
258+
case 500...599: return "Server Error"
259+
default: return "Server Error"
260+
}
261+
}
194262
}
195263
/// Parses the expected content length from the headers.
196264
///

0 commit comments

Comments
 (0)