Forráskód Böngészése

Replace AF namespace with reference to Session.default. (#3059)

* Start AdvancedUsage updates.

* Start rewriting Session section.

* Cleanup.

* WIP.

* Finish Session docs.

* Cleanup.

* Cleanup

* Continue work.

* Progress.

* Further work.

* Add request pipeline docs, refactor security docs.

* Updates.

* Caching and redirect.

* Progress.

* Finish AdvancedUsage.

* Fix typo.

* Fix link.

* Really fix link.

* Cleanup.

* Additional fixes.

* Try to fix test reliability.

* Different test reliability fix.

* Ignore more Ulysses files.

* Another reliability fix.

* Add index, reorder reachability.

* Fix index links.

* Fix more links.

* Fix more links.

* Remove AF namespace, update Usage.

* Test reliability.
Jon Shier 5 éve
szülő
commit
bbd4b57e04
4 módosított fájl, 20 hozzáadás és 511 törlés
  1. 14 14
      Documentation/Usage.md
  2. 4 495
      Source/Alamofire.swift
  3. 1 1
      Source/HTTPHeaders.swift
  4. 1 1
      Tests/RequestTests.swift

+ 14 - 14
Documentation/Usage.md

@@ -1,23 +1,23 @@
 - [Using Alamofire](#using-alamofire)
   * [Introduction](#introduction)
-      - [Aside: The `AF` Namespace](#aside--the--af--namespace)
+      - [Aside: The `AF` Namespace](#aside--the-af-namespace-and-reference)
   * [Making Requests](#making-requests)
     + [HTTP Methods](#http-methods)
     + [Request Parameters and Parameter Encoders](#request-parameters-and-parameter-encoders)
-      - [`URLEncodedFormParameterEncoder`](#-urlencodedformparameterencoder-)
+      - [`URLEncodedFormParameterEncoder`](#urlencodedformparameterencoder)
         * [GET Request With URL-Encoded Parameters](#get-request-with-url-encoded-parameters)
         * [POST Request With URL-Encoded Parameters](#post-request-with-url-encoded-parameters)
         * [Configuring the Sorting of Encoded Parameters](#configuring-the-sorting-of-encoded-parameters)
-        * [Configuring the Encoding of `Array` Parameters](#configuring-the-encoding-of--array--parameters)
-        * [Configuring the Encoding of `Bool` Parameters](#configuring-the-encoding-of--bool--parameters)
-        * [Configuring the Encoding of `Data` Parameters](#configuring-the-encoding-of--data--parameters)
-        * [Configuring the Encoding of `Date` Parameters](#configuring-the-encoding-of--date--parameters)
+        * [Configuring the Encoding of `Array` Parameters](#configuring-the-encoding-of-array-parameters)
+        * [Configuring the Encoding of `Bool` Parameters](#configuring-the-encoding-of-bool-parameters)
+        * [Configuring the Encoding of `Data` Parameters](#configuring-the-encoding-of-data-parameters)
+        * [Configuring the Encoding of `Date` Parameters](#configuring-the-encoding-of-date-parameters)
         * [Configuring the Encoding of Coding Keys](#configuring-the-encoding-of-coding-keys)
         * [Configuring the Encoding of Spaces](#configuring-the-encoding-of-spaces)
-      - [`JSONParameterEncoder`](#-jsonparameterencoder-)
+      - [`JSONParameterEncoder`](#jsonparameterencoder)
         * [POST Request with JSON-Encoded Parameters](#post-request-with-json-encoded-parameters)
-        * [Configuring a Custom `JSONEncoder`](#configuring-a-custom--jsonencoder-)
-        * [Manual Parameter Encoding of a `URLRequest`](#manual-parameter-encoding-of-a--urlrequest-)
+        * [Configuring a Custom `JSONEncoder`](#configuring-a-custom-jsonencoder)
+        * [Manual Parameter Encoding of a `URLRequest`](#manual-parameter-encoding-of-a-urlrequest)
     + [HTTP Headers](#http-headers)
     + [Response Validation](#response-validation)
       - [Automatic Validation](#automatic-validation)
@@ -27,13 +27,13 @@
       - [Response Data Handler](#response-data-handler)
       - [Response String Handler](#response-string-handler)
       - [Response JSON Handler](#response-json-handler)
-      - [Response `Decodable` Handler](#response--decodable--handler)
+      - [Response `Decodable` Handler](#response-decodable-handler)
       - [Chained Response Handlers](#chained-response-handlers)
       - [Response Handler Queue](#response-handler-queue)
     + [Response Caching](#response-caching)
     + [Authentication](#authentication)
       - [HTTP Basic Authentication](#http-basic-authentication)
-      - [Authentication with `URLCredential`](#authentication-with--urlcredential-)
+      - [Authentication with `URLCredential`](#authentication-with-urlcredential)
       - [Manual Authentication](#manual-authentication)
     + [Downloading Data to a File](#downloading-data-to-a-file)
       - [Download File Destination](#download-file-destination)
@@ -45,7 +45,7 @@
       - [Uploading Multipart Form Data](#uploading-multipart-form-data)
       - [Upload Progress](#upload-progress)
     + [Statistical Metrics](#statistical-metrics)
-      - [`URLSessionTaskMetrics`](#-urlsessiontaskmetrics-)
+      - [`URLSessionTaskMetrics`](#urlsessiontaskmetrics)
     + [cURL Command Output](#curl-command-output)
 
 # Using Alamofire
@@ -55,8 +55,8 @@ Alamofire provides an elegant and composable interface to HTTP network requests.
 
 Additionally, networking in Alamofire (and the URL Loading System in general) is done _asynchronously_. Asynchronous programming may be a source of frustration to programmers unfamiliar with the concept, but there are [very good reasons](https://developer.apple.com/library/ios/qa/qa1693/_index.html) for doing it this way.
 
-#### Aside: The `AF` Namespace
-Previous versions of Alamofire's documentation used examples like `Alamofire.request()`. This API, while it appeared to require the `Alamofire` prefix, in fact worked fine without it. The `request` method and other functions were available globally in any file with `import Alamofire`. Starting in Alamofire 5, this functionality has been moved out of the global [namespace](https://en.wikipedia.org/wiki/Namespace) and into the `AF` enum, which acts as a namespace. This allows Alamofire to offer the same convenience functionality while not having to pollute the global namespace every time Alamofire is used. Similarly, types extended by Alamofire will use an `af` property extension to separate the functionality Alamofire adds from other extensions.
+#### Aside: The `AF` Namespace and Reference
+Previous versions of Alamofire's documentation used examples like `Alamofire.request()`. This API, while it appeared to require the `Alamofire` prefix, in fact worked fine without it. The `request` method and other functions were available globally in any file with `import Alamofire`. Starting in Alamofire 5, this functionality has been removed and instead the `AF` global is a reference to `Session.default`. This allows Alamofire to offer the same convenience functionality while not having to pollute the global namespace every time Alamofire is used and not having to duplicate the `Session` API globally. Similarly, types extended by Alamofire will use an `af` property extension to separate the functionality Alamofire adds from other extensions.
 
 ## Making Requests
 Alamofire provides a variety of convenience methods for making HTTP requests. At the simplest, just provide a `String` that can be converted into a `URL`:

+ 4 - 495
Source/Alamofire.swift

@@ -22,499 +22,8 @@
 //  THE SOFTWARE.
 //
 
-import Foundation
+/// Reference to `Session.default` for quick bootstrapping and examples.
+public let AF = Session.default
 
-/// Global namespace containing API for the `default` `Session` instance.
-public enum AF {
-    /// Current Alamofire version. Necessary since SPM doesn't use dynamic libraries. Plus this will be more accurate.
-    static let version = "5.0.0-rc.3"
-
-    // MARK: - Data Request
-
-    /// Creates a `DataRequest` using `Session.default` to retrieve the contents of the specified `url` using the
-    /// `method`, `parameters`, `encoding`, and `headers` provided.
-    ///
-    /// - Parameters:
-    ///   - url:           The `URLConvertible` value.
-    ///   - method:        The `HTTPMethod`, `.get` by default.
-    ///   - parameters:    The `Parameters`, `nil` by default.
-    ///   - encoding:      The `ParameterEncoding`, `URLEncoding.default` by default.
-    ///   - headers:       The `HTTPHeaders`, `nil` by default.
-    ///   - interceptor:   The `RequestInterceptor`, `nil` by default.
-    ///
-    /// - Returns: The created `DataRequest`.
-    public static func request(_ url: URLConvertible,
-                               method: HTTPMethod = .get,
-                               parameters: Parameters? = nil,
-                               encoding: ParameterEncoding = URLEncoding.default,
-                               headers: HTTPHeaders? = nil,
-                               interceptor: RequestInterceptor? = nil) -> DataRequest {
-        return Session.default.request(url,
-                                       method: method,
-                                       parameters: parameters,
-                                       encoding: encoding,
-                                       headers: headers,
-                                       interceptor: interceptor)
-    }
-
-    /// Creates a `DataRequest` using `Session.default` to retrieve the contents of the specified `url` using the
-    /// `method`, `parameters`, `encoding`, and `headers` provided.
-    ///
-    /// - Parameters:
-    ///   - url:           The `URLConvertible` value.
-    ///   - method:        The `HTTPMethod`, `.get` by default.
-    ///   - parameters:    The `Encodable` parameters, `nil` by default.
-    ///   - encoding:      The `ParameterEncoder`, `URLEncodedFormParameterEncoder.default` by default.
-    ///   - headers:       The `HTTPHeaders`, `nil` by default.
-    ///   - interceptor:   The `RequestInterceptor`, `nil` by default.
-    ///
-    /// - Returns: The created `DataRequest`.
-    public static func request<Parameters: Encodable>(_ url: URLConvertible,
-                                                      method: HTTPMethod = .get,
-                                                      parameters: Parameters? = nil,
-                                                      encoder: ParameterEncoder = URLEncodedFormParameterEncoder.default,
-                                                      headers: HTTPHeaders? = nil,
-                                                      interceptor: RequestInterceptor? = nil) -> DataRequest {
-        return Session.default.request(url,
-                                       method: method,
-                                       parameters: parameters,
-                                       encoder: encoder,
-                                       headers: headers,
-                                       interceptor: interceptor)
-    }
-
-    /// Creates a `DataRequest` using `Session.default` to execute the specified `urlRequest`.
-    ///
-    /// - Parameters:
-    ///   - urlRequest:    The `URLRequestConvertible` value.
-    ///   - interceptor:   The `RequestInterceptor`, `nil` by default.
-    ///
-    /// - Returns: The created `DataRequest`.
-    public static func request(_ urlRequest: URLRequestConvertible, interceptor: RequestInterceptor? = nil) -> DataRequest {
-        return Session.default.request(urlRequest, interceptor: interceptor)
-    }
-
-    // MARK: - Download Request
-
-    /// Creates a `DownloadRequest` using `Session.default` to download the contents of the specified `url` to
-    /// the provided `destination` using the `method`, `parameters`, `encoding`, and `headers` provided.
-    ///
-    /// If `destination` is not specified, the download will be moved to a temporary location determined by Alamofire.
-    ///
-    /// - Parameters:
-    ///   - url:           The `URLConvertible` value.
-    ///   - method:        The `HTTPMethod`, `.get` by default.
-    ///   - parameters:    The `Parameters`, `nil` by default.
-    ///   - encoding:      The `ParameterEncoding`, `URLEncoding.default` by default.
-    ///   - headers:       The `HTTPHeaders`, `nil` by default.
-    ///   - interceptor:   The `RequestInterceptor`, `nil` by default.
-    ///   - destination:   The `DownloadRequest.Destination` closure used the determine the destination of the
-    ///                    downloaded file. `nil` by default.
-    ///
-    /// - Returns: The created `DownloadRequest`.
-    public static func download(_ url: URLConvertible,
-                                method: HTTPMethod = .get,
-                                parameters: Parameters? = nil,
-                                encoding: ParameterEncoding = URLEncoding.default,
-                                headers: HTTPHeaders? = nil,
-                                interceptor: RequestInterceptor? = nil,
-                                to destination: DownloadRequest.Destination? = nil) -> DownloadRequest {
-        return Session.default.download(url,
-                                        method: method,
-                                        parameters: parameters,
-                                        encoding: encoding,
-                                        headers: headers,
-                                        interceptor: interceptor,
-                                        to: destination)
-    }
-
-    /// Creates a `DownloadRequest` using `Session.default` to download the contents of the specified `url` to the
-    /// provided `destination` using the `method`, encodable `parameters`, `encoder`, and `headers` provided.
-    ///
-    /// - Note: If `destination` is not specified, the download will be moved to a temporary location determined by
-    ///         Alamofire.
-    ///
-    /// - Parameters:
-    ///   - url:           The `URLConvertible` value.
-    ///   - method:        The `HTTPMethod`, `.get` by default.
-    ///   - parameters:    The `Encodable` parameters, `nil` by default.
-    ///   - encoder:       The `ParameterEncoder`, `URLEncodedFormParameterEncoder.default` by default.
-    ///   - headers:       The `HTTPHeaders`, `nil` by default.
-    ///   - interceptor:   The `RequestInterceptor`, `nil` by default.
-    ///   - destination:   The `DownloadRequest.Destination` closure used the determine the destination of the
-    ///                    downloaded file. `nil` by default.
-    ///
-    /// - Returns: The created `DownloadRequest`.
-    public static func download<Parameters: Encodable>(_ url: URLConvertible,
-                                                       method: HTTPMethod = .get,
-                                                       parameters: Parameters? = nil,
-                                                       encoder: ParameterEncoder = URLEncodedFormParameterEncoder.default,
-                                                       headers: HTTPHeaders? = nil,
-                                                       interceptor: RequestInterceptor? = nil,
-                                                       to destination: DownloadRequest.Destination? = nil) -> DownloadRequest {
-        return Session.default.download(url,
-                                        method: method,
-                                        parameters: parameters,
-                                        encoder: encoder,
-                                        headers: headers,
-                                        interceptor: interceptor,
-                                        to: destination)
-    }
-
-    // MARK: URLRequest
-
-    /// Creates a `DownloadRequest` using `Session.default` to execute the specified `urlRequest` and download
-    /// the result to the provided `destination`.
-    ///
-    /// - Parameters:
-    ///   - urlRequest:    The `URLRequestConvertible` value.
-    ///   - interceptor:   The `RequestInterceptor`, `nil` by default.
-    ///   - destination:   The `DownloadRequest.Destination` closure used the determine the destination of the
-    ///                    downloaded file. `nil` by default.
-    ///
-    /// - Returns: The created `DownloadRequest`.
-    public static func download(_ urlRequest: URLRequestConvertible,
-                                interceptor: RequestInterceptor? = nil,
-                                to destination: DownloadRequest.Destination? = nil) -> DownloadRequest {
-        return Session.default.download(urlRequest, interceptor: interceptor, to: destination)
-    }
-
-    // MARK: Resume Data
-
-    /// Creates a `DownloadRequest` using the `Session.default` from the `resumeData` produced from a previous
-    /// `DownloadRequest` cancellation to retrieve the contents of the original request and save them to the `destination`.
-    ///
-    /// - Note: If `destination` is not specified, the download will be moved to a temporary location determined by
-    ///         Alamofire.
-    ///
-    /// - Note: On some versions of all Apple platforms (iOS 10 - 10.2, macOS 10.12 - 10.12.2, tvOS 10 - 10.1, watchOS 3 - 3.1.1),
-    /// `resumeData` is broken on background URL session configurations. There's an underlying bug in the `resumeData`
-    /// generation logic where the data is written incorrectly and will always fail to resume the download. For more
-    /// information about the bug and possible workarounds, please refer to the [this Stack Overflow post](http://stackoverflow.com/a/39347461/1342462).
-    ///
-    /// - Parameters:
-    ///   - resumeData:    The resume `Data`. This is an opaque blob produced by `URLSessionDownloadTask` when a task is
-    ///                    cancelled. See [Apple's documentation](https://developer.apple.com/documentation/foundation/urlsessiondownloadtask/1411634-cancel)
-    ///                    for more information.
-    ///   - interceptor:   The `RequestInterceptor`, `nil` by default.
-    ///   - destination:   The `DownloadRequest.Destination` closure used to determine the destination of the downloaded
-    ///                    file. `nil` by default.
-    ///
-    /// - Returns:         The created `DownloadRequest`.
-    public static func download(resumingWith resumeData: Data,
-                                interceptor: RequestInterceptor? = nil,
-                                to destination: DownloadRequest.Destination? = nil) -> DownloadRequest {
-        return Session.default.download(resumingWith: resumeData, interceptor: interceptor, to: destination)
-    }
-
-    // MARK: - Upload Request
-
-    // MARK: Data
-
-    /// Creates an `UploadRequest` for the given `Data`, `URLRequest` components, and `RequestInterceptor`.
-    ///
-    /// - Parameters:
-    ///   - data:        The `Data` to upload.
-    ///   - convertible: `URLConvertible` value to be used as the `URLRequest`'s `URL`.
-    ///   - method:      `HTTPMethod` for the `URLRequest`. `.post` by default.
-    ///   - headers:     `HTTPHeaders` value to be added to the `URLRequest`. `nil` by default.
-    ///   - interceptor: `RequestInterceptor` value to be used by the returned `DataRequest`. `nil` by default.
-    ///   - fileManager: `FileManager` instance to be used by the returned `UploadRequest`. `.default` instance by
-    ///                  default.
-    ///
-    /// - Returns:       The created `UploadRequest`.
-    public static func upload(_ data: Data,
-                              to convertible: URLConvertible,
-                              method: HTTPMethod = .post,
-                              headers: HTTPHeaders? = nil,
-                              interceptor: RequestInterceptor? = nil,
-                              fileManager: FileManager = .default) -> UploadRequest {
-        return Session.default.upload(data,
-                                      to: convertible,
-                                      method: method,
-                                      headers: headers,
-                                      interceptor: interceptor,
-                                      fileManager: fileManager)
-    }
-
-    /// Creates an `UploadRequest` for the given `Data` using the `URLRequestConvertible` value and `RequestInterceptor`.
-    ///
-    /// - Parameters:
-    ///   - data:        The `Data` to upload.
-    ///   - convertible: `URLRequestConvertible` value to be used to create the `URLRequest`.
-    ///   - interceptor: `RequestInterceptor` value to be used by the returned `DataRequest`. `nil` by default.
-    ///   - fileManager: `FileManager` instance to be used by the returned `UploadRequest`. `.default` instance by
-    ///                  default.
-    ///
-    /// - Returns:       The created `UploadRequest`.
-    public static func upload(_ data: Data,
-                              with convertible: URLRequestConvertible,
-                              interceptor: RequestInterceptor? = nil,
-                              fileManager: FileManager = .default) -> UploadRequest {
-        return Session.default.upload(data, with: convertible, interceptor: interceptor, fileManager: fileManager)
-    }
-
-    // MARK: File
-
-    /// Creates an `UploadRequest` for the file at the given file `URL`, using a `URLRequest` from the provided
-    /// components and `RequestInterceptor`.
-    ///
-    /// - Parameters:
-    ///   - fileURL:     The `URL` of the file to upload.
-    ///   - convertible: `URLConvertible` value to be used as the `URLRequest`'s `URL`.
-    ///   - method:      `HTTPMethod` for the `URLRequest`. `.post` by default.
-    ///   - headers:     `HTTPHeaders` value to be added to the `URLRequest`. `nil` by default.
-    ///   - interceptor: `RequestInterceptor` value to be used by the returned `UploadRequest`. `nil` by default.
-    ///   - fileManager: `FileManager` instance to be used by the returned `UploadRequest`. `.default` instance by
-    ///                  default.
-    ///
-    /// - Returns:       The created `UploadRequest`.
-    public static func upload(_ fileURL: URL,
-                              to convertible: URLConvertible,
-                              method: HTTPMethod = .post,
-                              headers: HTTPHeaders? = nil,
-                              interceptor: RequestInterceptor? = nil,
-                              fileManager: FileManager = .default) -> UploadRequest {
-        return Session.default.upload(fileURL,
-                                      to: convertible,
-                                      method: method,
-                                      headers: headers,
-                                      interceptor: interceptor,
-                                      fileManager: fileManager)
-    }
-
-    /// Creates an `UploadRequest` for the file at the given file `URL` using the `URLRequestConvertible` value and
-    /// `RequestInterceptor`.
-    ///
-    /// - Parameters:
-    ///   - fileURL:     The `URL` of the file to upload.
-    ///   - convertible: `URLRequestConvertible` value to be used to create the `URLRequest`.
-    ///   - interceptor: `RequestInterceptor` value to be used by the returned `DataRequest`. `nil` by default.
-    ///   - fileManager: `FileManager` instance to be used by the returned `UploadRequest`. `.default` instance by
-    ///                  default.
-    ///
-    /// - Returns:       The created `UploadRequest`.
-    public static func upload(_ fileURL: URL,
-                              with convertible: URLRequestConvertible,
-                              interceptor: RequestInterceptor? = nil,
-                              fileManager: FileManager = .default) -> UploadRequest {
-        return Session.default.upload(fileURL, with: convertible, interceptor: interceptor, fileManager: fileManager)
-    }
-
-    // MARK: InputStream
-
-    /// Creates an `UploadRequest` from the `InputStream` provided using a `URLRequest` from the provided components and
-    /// `RequestInterceptor`.
-    ///
-    /// - Parameters:
-    ///   - stream:      The `InputStream` that provides the data to upload.
-    ///   - convertible: `URLConvertible` value to be used as the `URLRequest`'s `URL`.
-    ///   - method:      `HTTPMethod` for the `URLRequest`. `.post` by default.
-    ///   - headers:     `HTTPHeaders` value to be added to the `URLRequest`. `nil` by default.
-    ///   - interceptor: `RequestInterceptor` value to be used by the returned `DataRequest`. `nil` by default.
-    ///   - fileManager: `FileManager` instance to be used by the returned `UploadRequest`. `.default` instance by
-    ///                  default.
-    ///
-    /// - Returns:       The created `UploadRequest`.
-    public static func upload(_ stream: InputStream,
-                              to convertible: URLConvertible,
-                              method: HTTPMethod = .post,
-                              headers: HTTPHeaders? = nil,
-                              interceptor: RequestInterceptor? = nil,
-                              fileManager: FileManager = .default) -> UploadRequest {
-        return Session.default.upload(stream,
-                                      to: convertible,
-                                      method: method,
-                                      headers: headers,
-                                      interceptor: interceptor,
-                                      fileManager: fileManager)
-    }
-
-    /// Creates an `UploadRequest` from the provided `InputStream` using the `URLRequestConvertible` value and
-    /// `RequestInterceptor`.
-    ///
-    /// - Parameters:
-    ///   - stream:      The `InputStream` that provides the data to upload.
-    ///   - convertible: `URLRequestConvertible` value to be used to create the `URLRequest`.
-    ///   - interceptor: `RequestInterceptor` value to be used by the returned `DataRequest`. `nil` by default.
-    ///   - fileManager: `FileManager` instance to be used by the returned `UploadRequest`. `.default` instance by
-    ///                  default.
-    ///
-    /// - Returns:       The created `UploadRequest`.
-    public static func upload(_ stream: InputStream,
-                              with convertible: URLRequestConvertible,
-                              interceptor: RequestInterceptor? = nil,
-                              fileManager: FileManager = .default) -> UploadRequest {
-        return Session.default.upload(stream, with: convertible, interceptor: interceptor, fileManager: fileManager)
-    }
-
-    // MARK: MultipartFormData
-
-    /// Creates an `UploadRequest` for the multipart form data built using a closure and sent using the provided
-    /// `URLRequest` components and `RequestInterceptor`.
-    ///
-    /// It is important to understand the memory implications of uploading `MultipartFormData`. If the cumulative
-    /// payload is small, encoding the data in-memory and directly uploading to a server is the by far the most
-    /// efficient approach. However, if the payload is too large, encoding the data in-memory could cause your app to
-    /// be terminated. Larger payloads must first be written to disk using input and output streams to keep the memory
-    /// footprint low, then the data can be uploaded as a stream from the resulting file. Streaming from disk MUST be
-    /// used for larger payloads such as video content.
-    ///
-    /// The `encodingMemoryThreshold` parameter allows Alamofire to automatically determine whether to encode in-memory
-    /// or stream from disk. If the content length of the `MultipartFormData` is below the `encodingMemoryThreshold`,
-    /// encoding takes place in-memory. If the content length exceeds the threshold, the data is streamed to disk
-    /// during the encoding process. Then the result is uploaded as data or as a stream depending on which encoding
-    /// technique was used.
-    ///
-    /// - Parameters:
-    ///   - multipartFormData:       `MultipartFormData` building closure.
-    ///   - convertible:             `URLConvertible` value to be used as the `URLRequest`'s `URL`.
-    ///   - encodingMemoryThreshold: Byte threshold used to determine whether the form data is encoded into memory or
-    ///                              onto disk before being uploaded. `MultipartFormData.encodingMemoryThreshold` by
-    ///                              default.
-    ///   - method:                  `HTTPMethod` for the `URLRequest`. `.post` by default.
-    ///   - headers:                 `HTTPHeaders` value to be added to the `URLRequest`. `nil` by default.
-    ///   - interceptor:             `RequestInterceptor` value to be used by the returned `DataRequest`. `nil` by default.
-    ///   - fileManager:             `FileManager` to be used if the form data exceeds the memory threshold and is
-    ///                              written to disk before being uploaded. `.default` instance by default.
-    ///
-    /// - Returns:                   The created `UploadRequest`.
-    public static func upload(multipartFormData: @escaping (MultipartFormData) -> Void,
-                              to url: URLConvertible,
-                              usingThreshold encodingMemoryThreshold: UInt64 = MultipartFormData.encodingMemoryThreshold,
-                              method: HTTPMethod = .post,
-                              headers: HTTPHeaders? = nil,
-                              interceptor: RequestInterceptor? = nil,
-                              fileManager: FileManager = .default) -> UploadRequest {
-        return Session.default.upload(multipartFormData: multipartFormData,
-                                      to: url,
-                                      usingThreshold: encodingMemoryThreshold,
-                                      method: method,
-                                      headers: headers,
-                                      interceptor: interceptor,
-                                      fileManager: fileManager)
-    }
-
-    /// Creates an `UploadRequest` using a `MultipartFormData` building closure, the provided `URLRequestConvertible`
-    /// value, and a `RequestInterceptor`.
-    ///
-    /// It is important to understand the memory implications of uploading `MultipartFormData`. If the cumulative
-    /// payload is small, encoding the data in-memory and directly uploading to a server is the by far the most
-    /// efficient approach. However, if the payload is too large, encoding the data in-memory could cause your app to
-    /// be terminated. Larger payloads must first be written to disk using input and output streams to keep the memory
-    /// footprint low, then the data can be uploaded as a stream from the resulting file. Streaming from disk MUST be
-    /// used for larger payloads such as video content.
-    ///
-    /// The `encodingMemoryThreshold` parameter allows Alamofire to automatically determine whether to encode in-memory
-    /// or stream from disk. If the content length of the `MultipartFormData` is below the `encodingMemoryThreshold`,
-    /// encoding takes place in-memory. If the content length exceeds the threshold, the data is streamed to disk
-    /// during the encoding process. Then the result is uploaded as data or as a stream depending on which encoding
-    /// technique was used.
-    ///
-    /// - Parameters:
-    ///   - multipartFormData:       `MultipartFormData` building closure.
-    ///   - request:                 `URLRequestConvertible` value to be used to create the `URLRequest`.
-    ///   - encodingMemoryThreshold: Byte threshold used to determine whether the form data is encoded into memory or
-    ///                              onto disk before being uploaded. `MultipartFormData.encodingMemoryThreshold` by
-    ///                              default.
-    ///   - interceptor:             `RequestInterceptor` value to be used by the returned `DataRequest`. `nil` by default.
-    ///   - fileManager:             `FileManager` to be used if the form data exceeds the memory threshold and is
-    ///                              written to disk before being uploaded. `.default` instance by default.
-    ///
-    /// - Returns:                   The created `UploadRequest`.
-    public static func upload(multipartFormData: @escaping (MultipartFormData) -> Void,
-                              with request: URLRequestConvertible,
-                              usingThreshold encodingMemoryThreshold: UInt64 = MultipartFormData.encodingMemoryThreshold,
-                              interceptor: RequestInterceptor? = nil,
-                              fileManager: FileManager = .default) -> UploadRequest {
-        return Session.default.upload(multipartFormData: multipartFormData,
-                                      with: request,
-                                      usingThreshold: encodingMemoryThreshold,
-                                      interceptor: interceptor,
-                                      fileManager: fileManager)
-    }
-
-    /// Creates an `UploadRequest` for the prebuilt `MultipartFormData` value using the provided `URLRequest` components
-    /// and `RequestInterceptor`.
-    ///
-    /// It is important to understand the memory implications of uploading `MultipartFormData`. If the cumulative
-    /// payload is small, encoding the data in-memory and directly uploading to a server is the by far the most
-    /// efficient approach. However, if the payload is too large, encoding the data in-memory could cause your app to
-    /// be terminated. Larger payloads must first be written to disk using input and output streams to keep the memory
-    /// footprint low, then the data can be uploaded as a stream from the resulting file. Streaming from disk MUST be
-    /// used for larger payloads such as video content.
-    ///
-    /// The `encodingMemoryThreshold` parameter allows Alamofire to automatically determine whether to encode in-memory
-    /// or stream from disk. If the content length of the `MultipartFormData` is below the `encodingMemoryThreshold`,
-    /// encoding takes place in-memory. If the content length exceeds the threshold, the data is streamed to disk
-    /// during the encoding process. Then the result is uploaded as data or as a stream depending on which encoding
-    /// technique was used.
-    ///
-    /// - Parameters:
-    ///   - multipartFormData:       `MultipartFormData` instance to upload.
-    ///   - url:                     `URLConvertible` value to be used as the `URLRequest`'s `URL`.
-    ///   - encodingMemoryThreshold: Byte threshold used to determine whether the form data is encoded into memory or
-    ///                              onto disk before being uploaded. `MultipartFormData.encodingMemoryThreshold` by
-    ///                              default.
-    ///   - method:                  `HTTPMethod` for the `URLRequest`. `.post` by default.
-    ///   - headers:                 `HTTPHeaders` value to be added to the `URLRequest`. `nil` by default.
-    ///   - interceptor:             `RequestInterceptor` value to be used by the returned `DataRequest`. `nil` by default.
-    ///   - fileManager:             `FileManager` to be used if the form data exceeds the memory threshold and is
-    ///                              written to disk before being uploaded. `.default` instance by default.
-    ///
-    /// - Returns:                   The created `UploadRequest`.
-    public static func upload(multipartFormData: MultipartFormData,
-                              to url: URLConvertible,
-                              usingThreshold encodingMemoryThreshold: UInt64 = MultipartFormData.encodingMemoryThreshold,
-                              method: HTTPMethod = .post,
-                              headers: HTTPHeaders? = nil,
-                              interceptor: RequestInterceptor? = nil,
-                              fileManager: FileManager = .default) -> UploadRequest {
-        return Session.default.upload(multipartFormData: multipartFormData,
-                                      to: url,
-                                      usingThreshold: encodingMemoryThreshold,
-                                      method: method,
-                                      headers: headers,
-                                      interceptor: interceptor,
-                                      fileManager: fileManager)
-    }
-
-    /// Creates an `UploadRequest` for the prebuilt `MultipartFormData` value using the providing `URLRequestConvertible`
-    /// value and `RequestInterceptor`.
-    ///
-    /// It is important to understand the memory implications of uploading `MultipartFormData`. If the cumulative
-    /// payload is small, encoding the data in-memory and directly uploading to a server is the by far the most
-    /// efficient approach. However, if the payload is too large, encoding the data in-memory could cause your app to
-    /// be terminated. Larger payloads must first be written to disk using input and output streams to keep the memory
-    /// footprint low, then the data can be uploaded as a stream from the resulting file. Streaming from disk MUST be
-    /// used for larger payloads such as video content.
-    ///
-    /// The `encodingMemoryThreshold` parameter allows Alamofire to automatically determine whether to encode in-memory
-    /// or stream from disk. If the content length of the `MultipartFormData` is below the `encodingMemoryThreshold`,
-    /// encoding takes place in-memory. If the content length exceeds the threshold, the data is streamed to disk
-    /// during the encoding process. Then the result is uploaded as data or as a stream depending on which encoding
-    /// technique was used.
-    ///
-    /// - Parameters:
-    ///   - multipartFormData:       `MultipartFormData` instance to upload.
-    ///   - request:                 `URLRequestConvertible` value to be used to create the `URLRequest`.
-    ///   - encodingMemoryThreshold: Byte threshold used to determine whether the form data is encoded into memory or
-    ///                              onto disk before being uploaded. `MultipartFormData.encodingMemoryThreshold` by
-    ///                              default.
-    ///   - interceptor:             `RequestInterceptor` value to be used by the returned `DataRequest`. `nil` by default.
-    ///   - fileManager:             `FileManager` instance to be used by the returned `UploadRequest`. `.default` instance by
-    ///                              default.
-    ///
-    /// - Returns:                   The created `UploadRequest`.
-    public static func upload(multipartFormData: MultipartFormData,
-                              with request: URLRequestConvertible,
-                              usingThreshold encodingMemoryThreshold: UInt64 = MultipartFormData.encodingMemoryThreshold,
-                              interceptor: RequestInterceptor? = nil,
-                              fileManager: FileManager = .default) -> UploadRequest {
-        return Session.default.upload(multipartFormData: multipartFormData,
-                                      with: request,
-                                      usingThreshold: encodingMemoryThreshold,
-                                      interceptor: interceptor,
-                                      fileManager: fileManager)
-    }
-}
+/// Current Alamofire version. Necessary since SPM doesn't use dynamic libraries. Plus this will be more accurate.
+let version = "5.0.0-rc.3"

+ 1 - 1
Source/HTTPHeaders.swift

@@ -398,7 +398,7 @@ extension HTTPHeader {
                     return "\(osName) \(versionString)"
                 }()
 
-                let alamofireVersion = "Alamofire/\(AF.version)"
+                let alamofireVersion = "Alamofire/\(version)"
 
                 return "\(executable)/\(appVersion) (\(bundle); build:\(appBuild); \(osNameVersion)) \(alamofireVersion)"
             }

+ 1 - 1
Tests/RequestTests.swift

@@ -523,7 +523,7 @@ final class RequestResponseTestCase: BaseTestCase {
         eventMonitor.requestDidSuspendTask = { _, _ in expect.fulfill() }
 
         // When
-        let request = session.request(URLRequest.makeHTTPBinRequest()).response { _ in expect.fulfill() }
+        let request = session.request(URLRequest.makeHTTPBinRequest(path: "delay/5")).response { _ in expect.fulfill() }
         // Cancellation stops task creation, so don't cancel the request until the task has been created.
         eventMonitor.requestDidCreateTask = { _, _ in
             DispatchQueue.concurrentPerform(iterations: 100) { i in