Skip to content
This repository has been archived by the owner on Apr 7, 2022. It is now read-only.

Conform HTTPMethod to RawRepresentable #348

Closed
calebkleveter opened this issue Mar 13, 2019 · 2 comments
Closed

Conform HTTPMethod to RawRepresentable #348

calebkleveter opened this issue Mar 13, 2019 · 2 comments
Labels
enhancement New feature or request

Comments

@calebkleveter
Copy link
Member

extension HTTPMethod: RawRepresentable {
    public typealias RawValue = String
    
    public init?(rawValue: String) {
        switch rawValue {
        case "GET": self = .GET
        case "PUT": self = .PUT
        case "ACL": self = .ACL
        case "HEAD": self = .HEAD
        case "POST": self = .POST
        case "COPY": self = .COPY
        case "LOCK": self = .LOCK
        case "MOVE": self = .MOVE
        case "BIND": self = .BIND
        case "LINK": self = .LINK
        case "PATCH": self = .PATCH
        case "TRACE": self = .TRACE
        case "MKCOL": self = .MKCOL
        case "MERGE": self = .MERGE
        case "PURGE": self = .PURGE
        case "NOTIFY": self = .NOTIFY
        case "SEARCH": self = .SEARCH
        case "UNLOCK": self = .UNLOCK
        case "REBIND": self = .REBIND
        case "UNBIND": self = .UNBIND
        case "REPORT": self = .REPORT
        case "DELETE": self = .DELETE
        case "UNLINK": self = .UNLINK
        case "CONNECT": self = .CONNECT
        case "MSEARCH": self = .MSEARCH
        case "OPTIONS": self = .OPTIONS
        case "PROPFIND": self = .PROPFIND
        case "CHECKOUT": self = .CHECKOUT
        case "PROPPATCH": self = .PROPPATCH
        case "SUBSCRIBE": self = .SUBSCRIBE
        case "MKCALENDAR": self = .MKCALENDAR
        case "MKACTIVITY": self = .MKACTIVITY
        case "UNSUBSCRIBE": self = .UNSUBSCRIBE
        default: self = .RAW(value: rawValue)
        }
    }
    
    public var rawValue: String {
        switch self {
        case .GET: return "GET"
        case .PUT: return "PUT"
        case .ACL: return "ACL"
        case .HEAD: return "HEAD"
        case .POST: return "POST"
        case .COPY: return "COPY"
        case .LOCK: return "LOCK"
        case .MOVE: return "MOVE"
        case .BIND: return "BIND"
        case .LINK: return "LINK"
        case .PATCH: return "PATCH"
        case .TRACE: return "TRACE"
        case .MKCOL: return "MKCOL"
        case .MERGE: return "MERGE"
        case .PURGE: return "PURGE"
        case .NOTIFY: return "NOTIFY"
        case .SEARCH: return "SEARCH"
        case .UNLOCK: return "UNLOCK"
        case .REBIND: return "REBIND"
        case .UNBIND: return "UNBIND"
        case .REPORT: return "REPORT"
        case .DELETE: return "DELETE"
        case .UNLINK: return "UNLINK"
        case .CONNECT: return "CONNECT"
        case .MSEARCH: return "MSEARCH"
        case .OPTIONS: return "OPTIONS"
        case .PROPFIND: return "PROPFIND"
        case .CHECKOUT: return "CHECKOUT"
        case .PROPPATCH: return "PROPPATCH"
        case .SUBSCRIBE: return "SUBSCRIBE"
        case .MKCALENDAR: return "MKCALENDAR"
        case .MKACTIVITY: return "MKACTIVITY"
        case .UNSUBSCRIBE: return "UNSUBSCRIBE"
        case let .RAW(value: method): return method
        }
    }
}
@tanner0101 tanner0101 transferred this issue from vapor/async-kit Mar 14, 2019
@tanner0101
Copy link
Member

@calebkleveter transferring this to HTTPKit since I think that's where you meant it to be 👍

@tanner0101 tanner0101 added the enhancement New feature or request label Mar 14, 2019
@JaapWijnen
Copy link

this is already added in NIOHTTP1 :) can be closed

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants