Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unfreeze HTTPMethod #2901

Merged
merged 2 commits into from
Aug 13, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions Source/HTTPMethod.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,32 @@
/// HTTP method definitions.
///
/// See https://tools.ietf.org/html/rfc7231#section-4.3
public enum HTTPMethod: String {
public struct HTTPMethod: RawRepresentable, Equatable, Hashable {
/// `CONNECT` method.
case connect = "CONNECT"
public static let connect = HTTPMethod(rawValue: "CONNECT")
/// `DELETE` method.
case delete = "DELETE"
public static let delete = HTTPMethod(rawValue: "DELETE")
/// `GET` method.
case get = "GET"
public static let get = HTTPMethod(rawValue: "GET")
/// `HEAD` method.
case head = "HEAD"
public static let head = HTTPMethod(rawValue: "HEAD")
/// `OPTIONS` method.
case options = "OPTIONS"
public static let options = HTTPMethod(rawValue: "OPTIONS")
/// `PATCH` method.
case patch = "PATCH"
public static let patch = HTTPMethod(rawValue: "PATCH")
/// `POST` method.
case post = "POST"
public static let post = HTTPMethod(rawValue: "POST")
/// `PUT` method.
case put = "PUT"
public static let put = HTTPMethod(rawValue: "PUT")
/// `TRACE` method.
case trace = "TRACE"
public static let trace = HTTPMethod(rawValue: "TRACE")

public let rawValue: String

/// Creates a new instance with the `uppercased()` version of the specified `rawValue`.
///
/// - Parameter rawValue: The raw `String` value, stored `uppercased`.
public init(rawValue: String) {
self.rawValue = rawValue.uppercased()
jshier marked this conversation as resolved.
Show resolved Hide resolved
}
}
2 changes: 1 addition & 1 deletion Source/ParameterEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ open class URLEncodedFormParameterEncoder: ParameterEncoder {
throw AFError.parameterEncoderFailed(reason: .missingRequiredComponent(.url))
}

guard let rawMethod = request.httpMethod, let method = HTTPMethod(rawValue: rawMethod) else {
guard let method = request.method else {
let rawValue = request.httpMethod ?? "nil"
throw AFError.parameterEncoderFailed(reason: .missingRequiredComponent(.httpMethod(rawValue: rawValue)))
}
Expand Down