// // GeminiResponseHeader.swift // Gemini // // Created by Shadowfacts on 7/12/20. // import Foundation public struct GeminiResponseHeader { public let status: StatusCode public let meta: String } public extension GeminiResponseHeader { enum StatusCode: Int { // All statuses and subtypes case input = 10 case sensitiveInput = 11 case success = 20 case temporaryRedirect = 30 case permanentRedirect = 31 case temporaryFailure = 40 case serverUnavailable = 41 case cgiError = 42 case proxyError = 43 case slowDown = 44 case permanentFailure = 50 case notFound = 51 case gone = 52 case proxyRequestRefused = 53 case badRequest = 59 case clientCertificateRequested = 60 case certificateNotAuthorised = 61 case certificateNotValid = 62 // Status type helpers var isInput: Bool { rawValue / 10 == 1 } var isSuccess: Bool { rawValue / 10 == 2 } var isRedirect: Bool { rawValue / 10 == 3 } var isTemporaryFailure: Bool { rawValue / 10 == 4 } var isPermanentFailure: Bool { rawValue / 10 == 5 } var isClientCertificateRequired: Bool { rawValue / 10 == 6 } // Other helpers var isFailure: Bool { isTemporaryFailure || isPermanentFailure } } } extension GeminiResponseHeader.StatusCode: CustomStringConvertible { public var description: String { switch self { case .input: return "\(rawValue): input" case .sensitiveInput: return "\(rawValue): sensitiveInput" case .success: return "\(rawValue): success" case .temporaryRedirect: return "\(rawValue): temporaryRedirect" case .permanentRedirect: return "\(rawValue): permanentRedirect" case .temporaryFailure: return "\(rawValue): temporaryFailure" case .serverUnavailable: return "\(rawValue): serverUnavailable" case .cgiError: return "\(rawValue): cgiError" case .proxyError: return "\(rawValue): proxyError" case .slowDown: return "\(rawValue): slowDown" case .permanentFailure: return "\(rawValue): permanentFailure" case .notFound: return "\(rawValue): notFound" case .gone: return "\(rawValue): gone" case .proxyRequestRefused: return "\(rawValue): proxyRequestRefused" case .badRequest: return "\(rawValue): badRequest" case .clientCertificateRequested: return "\(rawValue): clientCertificateRequested" case .certificateNotAuthorised: return "\(rawValue): certificateNotAuthorised" case .certificateNotValid: return "\(rawValue): certificateNotValid" } } }