杨锴
2025-03-11 90dc3329d1973fda691e357cf4523d5c7c67fa1d
Pods/Alamofire/Source/Core/ParameterEncoding.swift
@@ -25,10 +25,10 @@
import Foundation
/// A dictionary of parameters to apply to a `URLRequest`.
public typealias Parameters = [String: Any]
public typealias Parameters = [String: any Any & Sendable]
/// A type used to define how a set of parameters are applied to a `URLRequest`.
public protocol ParameterEncoding {
public protocol ParameterEncoding: Sendable {
    /// Creates a `URLRequest` by encoding parameters and applying them on the passed request.
    ///
    /// - Parameters:
@@ -37,7 +37,7 @@
    ///
    /// - Returns:      The encoded `URLRequest`.
    /// - Throws:       Any `Error` produced during parameter encoding.
    func encode(_ urlRequest: URLRequestConvertible, with parameters: Parameters?) throws -> URLRequest
    func encode(_ urlRequest: any URLRequestConvertible, with parameters: Parameters?) throws -> URLRequest
}
// MARK: -
@@ -61,7 +61,7 @@
    /// Defines whether the url-encoded query string is applied to the existing query string or HTTP body of the
    /// resulting URL request.
    public enum Destination {
    public enum Destination: Sendable {
        /// Applies encoded query string result to existing query string for `GET`, `HEAD` and `DELETE` requests and
        /// sets as the HTTP body for requests with any other HTTP method.
        case methodDependent
@@ -72,15 +72,15 @@
        func encodesParametersInURL(for method: HTTPMethod) -> Bool {
            switch self {
            case .methodDependent: return [.get, .head, .delete].contains(method)
            case .queryString: return true
            case .httpBody: return false
            case .methodDependent: [.get, .head, .delete].contains(method)
            case .queryString: true
            case .httpBody: false
            }
        }
    }
    /// Configures how `Array` parameters are encoded.
    public enum ArrayEncoding {
    public enum ArrayEncoding: Sendable {
        /// An empty set of square brackets is appended to the key for every value. This is the default behavior.
        case brackets
        /// No brackets are appended. The key is encoded as is.
@@ -88,24 +88,24 @@
        /// Brackets containing the item index are appended. This matches the jQuery and Node.js behavior.
        case indexInBrackets
        /// Provide a custom array key encoding with the given closure.
        case custom((_ key: String, _ index: Int) -> String)
        case custom(@Sendable (_ key: String, _ index: Int) -> String)
        func encode(key: String, atIndex index: Int) -> String {
            switch self {
            case .brackets:
                return "\(key)[]"
                "\(key)[]"
            case .noBrackets:
                return key
                key
            case .indexInBrackets:
                return "\(key)[\(index)]"
                "\(key)[\(index)]"
            case let .custom(encoding):
                return encoding(key, index)
                encoding(key, index)
            }
        }
    }
    /// Configures how `Bool` parameters are encoded.
    public enum BoolEncoding {
    public enum BoolEncoding: Sendable {
        /// Encode `true` as `1` and `false` as `0`. This is the default behavior.
        case numeric
        /// Encode `true` and `false` as string literals.
@@ -114,9 +114,9 @@
        func encode(value: Bool) -> String {
            switch self {
            case .numeric:
                return value ? "1" : "0"
                value ? "1" : "0"
            case .literal:
                return value ? "true" : "false"
                value ? "true" : "false"
            }
        }
    }
@@ -160,7 +160,7 @@
    // MARK: Encoding
    public func encode(_ urlRequest: URLRequestConvertible, with parameters: Parameters?) throws -> URLRequest {
    public func encode(_ urlRequest: any URLRequestConvertible, with parameters: Parameters?) throws -> URLRequest {
        var urlRequest = try urlRequest.asURLRequest()
        guard let parameters else { return urlRequest }
@@ -272,7 +272,7 @@
    // MARK: Encoding
    public func encode(_ urlRequest: URLRequestConvertible, with parameters: Parameters?) throws -> URLRequest {
    public func encode(_ urlRequest: any URLRequestConvertible, with parameters: Parameters?) throws -> URLRequest {
        var urlRequest = try urlRequest.asURLRequest()
        guard let parameters else { return urlRequest }
@@ -304,7 +304,7 @@
    ///
    /// - Returns:      The encoded `URLRequest`.
    /// - Throws:       Any `Error` produced during encoding.
    public func encode(_ urlRequest: URLRequestConvertible, withJSONObject jsonObject: Any? = nil) throws -> URLRequest {
    public func encode(_ urlRequest: any URLRequestConvertible, withJSONObject jsonObject: Any? = nil) throws -> URLRequest {
        var urlRequest = try urlRequest.asURLRequest()
        guard let jsonObject else { return urlRequest }