Fix reasonPhrase, update API.md

This commit is contained in:
Helge Hess
2017-06-01 13:33:41 +02:00
parent 9fdf40ff74
commit 885d1f1ec4
2 changed files with 69 additions and 86 deletions
+64 -79
View File
@@ -72,90 +72,75 @@ public enum HTTPTransferEncoding {
}
/// Response status (200 ok, 404 not found, etc)
public enum HTTPResponseStatus: UInt16, RawRepresentable {
/* The original spec used custom if you want to use a non-standard response code or
have it available in a (UInt, String) pair from a higher-level web framework.
Can't do custom if we want rawRepresentable. TODO: Consider making these constants
*/
//case custom(code: UInt, reasonPhrase: String)
public enum HTTPResponseStatus: RawRepresentable, Equatable {
/* be future-proof, new status codes can appear */
case other(statusCode: UInt16, reasonPhrase: String)
/* all the codes from http://www.iana.org/assignments/http-status-codes */
case `continue` = 100
case switchingProtocols = 101
case processing = 102
case ok = 200
case created = 201
case accepted = 202
case nonAuthoritativeInformation = 203
case noContent = 204
case resetContent = 205
case partialContent = 206
case multiStatus = 207
case alreadyReported = 208
case imUsed = 226
case multipleChoices = 300
case movedPermanently = 301
case found = 302
case seeOther = 303
case notModified = 304
case useProxy = 305
case temporaryRedirect = 307
case permanentRedirect = 308
case badRequest = 400
case unauthorized = 401
case paymentRequired = 402
case forbidden = 403
case notFound = 404
case methodNotAllowed = 405
case notAcceptable = 406
case proxyAuthenticationRequired = 407
case requestTimeout = 408
case conflict = 409
case gone = 410
case lengthRequired = 411
case preconditionFailed = 412
case payloadTooLarge = 413
case uriTooLong = 414
case unsupportedMediaType = 415
case rangeNotSatisfiable = 416
case expectationFailed = 417
case misdirectedRequest = 421
case unprocessableEntity = 422
case locked = 423
case failedDependency = 424
case upgradeRequired = 426
case preconditionRequired = 428
case tooManyRequests = 429
case requestHeaderFieldsTooLarge = 431
case unavailableForLegalReasons = 451
case internalServerError = 500
case notImplemented = 501
case badGateway = 502
case serviceUnavailable = 503
case gatewayTimeout = 504
case httpVersionNotSupported = 505
case variantAlsoNegotiates = 506
case insufficientStorage = 507
case loopDetected = 508
case notExtended = 510
case networkAuthenticationRequired = 511
case `continue`
case switchingProtocols
case processing
case ok
case created
case accepted
case nonAuthoritativeInformation
case noContent
case resetContent
case partialContent
case multiStatus
case alreadyReported
case imUsed
case multipleChoices
case movedPermanently
case found
case seeOther
case notModified
case useProxy
case temporaryRedirect
case permanentRedirect
case badRequest
case unauthorized
case paymentRequired
case forbidden
case notFound
case methodNotAllowed
case notAcceptable
case proxyAuthenticationRequired
case requestTimeout
case conflict
case gone
case lengthRequired
case preconditionFailed
case payloadTooLarge
case uriTooLong
case unsupportedMediaType
case rangeNotSatisfiable
case expectationFailed
case misdirectedRequest
case unprocessableEntity
case locked
case failedDependency
case upgradeRequired
case preconditionRequired
case tooManyRequests
case requestHeaderFieldsTooLarge
case unavailableForLegalReasons
case internalServerError
case notImplemented
case badGateway
case serviceUnavailable
case gatewayTimeout
case httpVersionNotSupported
case variantAlsoNegotiates
case insufficientStorage
case loopDetected
case notExtended
case networkAuthenticationRequired
}
extension HTTPResponseStatus {
public var reasonPhrase: String {
switch(self) {
// Can't do custom if we want rawRepresentable. TODO: Consider making these constants
// case .custom(_, let reasonPhrase):
// return reasonPhrase
case .`continue`:
return "CONTINUE"
default:
return String(describing: self)
}
}
public var code: UInt16
public var reasonPhrase: String { get }
public var code: UInt16 { get }
public static func from(code: UInt16) -> HTTPResponseStatus?
+5 -7
View File
@@ -256,13 +256,11 @@ public enum HTTPResponseStatus: RawRepresentable, Equatable {
extension HTTPResponseStatus {
public var reasonPhrase: String {
switch(self) {
// Can't do custom if we want rawRepresentable. TODO: Consider making these constants
// case .custom(_, let reasonPhrase):
// return reasonPhrase
case .`continue`:
return "CONTINUE"
default:
return String(describing: self)
case .other(_, let reasonPhrase): return reasonPhrase
case .`continue`:
return "CONTINUE"
default:
return String(describing: self)
}
}