2020-07-13 03:09:37 +00:00
|
|
|
//
|
|
|
|
// GeminiResponseHeader.swift
|
|
|
|
// Gemini
|
|
|
|
//
|
|
|
|
// Created by Shadowfacts on 7/12/20.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
2020-07-13 22:22:36 +00:00
|
|
|
public struct GeminiResponseHeader {
|
2020-07-15 02:13:09 +00:00
|
|
|
public let status: StatusCode
|
2020-07-13 22:22:36 +00:00
|
|
|
public let meta: String
|
2020-07-15 02:13:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2020-07-16 02:34:15 +00:00
|
|
|
public var isInput: Bool { rawValue / 10 == 1 }
|
|
|
|
public var isSuccess: Bool { rawValue / 10 == 2 }
|
|
|
|
public var isRedirect: Bool { rawValue / 10 == 3 }
|
|
|
|
public var isTemporaryFailure: Bool { rawValue / 10 == 4 }
|
|
|
|
public var isPermanentFailure: Bool { rawValue / 10 == 5 }
|
|
|
|
public var isClientCertificateRequired: Bool { rawValue / 10 == 6 }
|
2020-07-15 02:13:09 +00:00
|
|
|
|
|
|
|
// Other helpers
|
2020-07-16 02:34:15 +00:00
|
|
|
public var isFailure: Bool { isTemporaryFailure || isPermanentFailure }
|
2020-07-15 02:13:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension GeminiResponseHeader.StatusCode: CustomStringConvertible {
|
|
|
|
public var description: String {
|
|
|
|
switch self {
|
|
|
|
case .input:
|
2020-07-15 02:39:38 +00:00
|
|
|
return "\(rawValue): input"
|
2020-07-15 02:13:09 +00:00
|
|
|
case .sensitiveInput:
|
2020-07-15 02:39:38 +00:00
|
|
|
return "\(rawValue): sensitiveInput"
|
2020-07-15 02:13:09 +00:00
|
|
|
case .success:
|
2020-07-15 02:39:38 +00:00
|
|
|
return "\(rawValue): success"
|
2020-07-15 02:13:09 +00:00
|
|
|
case .temporaryRedirect:
|
2020-07-15 02:39:38 +00:00
|
|
|
return "\(rawValue): temporaryRedirect"
|
2020-07-15 02:13:09 +00:00
|
|
|
case .permanentRedirect:
|
2020-07-15 02:39:38 +00:00
|
|
|
return "\(rawValue): permanentRedirect"
|
2020-07-15 02:13:09 +00:00
|
|
|
case .temporaryFailure:
|
2020-07-15 02:39:38 +00:00
|
|
|
return "\(rawValue): temporaryFailure"
|
2020-07-15 02:13:09 +00:00
|
|
|
case .serverUnavailable:
|
2020-07-15 02:39:38 +00:00
|
|
|
return "\(rawValue): serverUnavailable"
|
2020-07-15 02:13:09 +00:00
|
|
|
case .cgiError:
|
2020-07-15 02:39:38 +00:00
|
|
|
return "\(rawValue): cgiError"
|
2020-07-15 02:13:09 +00:00
|
|
|
case .proxyError:
|
2020-07-15 02:39:38 +00:00
|
|
|
return "\(rawValue): proxyError"
|
2020-07-15 02:13:09 +00:00
|
|
|
case .slowDown:
|
2020-07-15 02:39:38 +00:00
|
|
|
return "\(rawValue): slowDown"
|
2020-07-15 02:13:09 +00:00
|
|
|
case .permanentFailure:
|
2020-07-15 02:39:38 +00:00
|
|
|
return "\(rawValue): permanentFailure"
|
2020-07-15 02:13:09 +00:00
|
|
|
case .notFound:
|
2020-07-15 02:39:38 +00:00
|
|
|
return "\(rawValue): notFound"
|
2020-07-15 02:13:09 +00:00
|
|
|
case .gone:
|
2020-07-15 02:39:38 +00:00
|
|
|
return "\(rawValue): gone"
|
2020-07-15 02:13:09 +00:00
|
|
|
case .proxyRequestRefused:
|
2020-07-15 02:39:38 +00:00
|
|
|
return "\(rawValue): proxyRequestRefused"
|
2020-07-15 02:13:09 +00:00
|
|
|
case .badRequest:
|
2020-07-15 02:39:38 +00:00
|
|
|
return "\(rawValue): badRequest"
|
2020-07-15 02:13:09 +00:00
|
|
|
case .clientCertificateRequested:
|
2020-07-15 02:39:38 +00:00
|
|
|
return "\(rawValue): clientCertificateRequested"
|
2020-07-15 02:13:09 +00:00
|
|
|
case .certificateNotAuthorised:
|
2020-07-15 02:39:38 +00:00
|
|
|
return "\(rawValue): certificateNotAuthorised"
|
2020-07-15 02:13:09 +00:00
|
|
|
case .certificateNotValid:
|
2020-07-15 02:39:38 +00:00
|
|
|
return "\(rawValue): certificateNotValid"
|
2020-07-15 02:13:09 +00:00
|
|
|
}
|
|
|
|
}
|
2020-07-13 03:09:37 +00:00
|
|
|
}
|