Browse Source

Audit - MultipartUpload ACL (#2805)

* Moved MultipartUpload to internal type and threshold to MultipartFormData

* Made MultipartUpload final class to prevent subclassing
Christian Noon 6 years ago
parent
commit
9361fd2bc0
4 changed files with 11 additions and 11 deletions
  1. 2 2
      Source/Alamofire.swift
  2. 3 0
      Source/MultipartFormData.swift
  3. 4 7
      Source/MultipartUpload.swift
  4. 2 2
      Source/Session.swift

+ 2 - 2
Source/Alamofire.swift

@@ -345,7 +345,7 @@ public enum AF {
     ///
     /// - Returns: The created `UploadRequest`.
     public static func upload(multipartFormData: @escaping (MultipartFormData) -> Void,
-                              usingThreshold encodingMemoryThreshold: UInt64 = MultipartUpload.encodingMemoryThreshold,
+                              usingThreshold encodingMemoryThreshold: UInt64 = MultipartFormData.encodingMemoryThreshold,
                               fileManager: FileManager = .default,
                               to url: URLConvertible,
                               method: HTTPMethod = .post,
@@ -385,7 +385,7 @@ public enum AF {
     /// - Returns: The `UploadRequest` created.
     @discardableResult
     public static func upload(multipartFormData: MultipartFormData,
-                              usingThreshold encodingMemoryThreshold: UInt64 = MultipartUpload.encodingMemoryThreshold,
+                              usingThreshold encodingMemoryThreshold: UInt64 = MultipartFormData.encodingMemoryThreshold,
                               with urlRequest: URLRequestConvertible,
                               interceptor: RequestInterceptor? = nil) -> UploadRequest {
         return Session.default.upload(multipartFormData: multipartFormData,

+ 3 - 0
Source/MultipartFormData.swift

@@ -91,6 +91,9 @@ open class MultipartFormData {
 
     // MARK: - Properties
 
+    /// Default memory threshold used when encoding `MultipartFormData`, in bytes.
+    public static let encodingMemoryThreshold: UInt64 = 10_000_000
+
     /// The `Content-Type` header value containing the boundary used to generate the `multipart/form-data`.
     open lazy var contentType: String = "multipart/form-data; boundary=\(self.boundary)"
 

+ 4 - 7
Source/MultipartUpload.swift

@@ -24,10 +24,7 @@
 
 import Foundation
 
-open class MultipartUpload {
-    /// Default memory threshold used when encoding `MultipartFormData`, in bytes.
-    public static let encodingMemoryThreshold: UInt64 = 10_000_000
-
+final class MultipartUpload {
     lazy var result = AFResult { try build() }
 
     let isInBackgroundSession: Bool
@@ -37,7 +34,7 @@ open class MultipartUpload {
     let fileManager: FileManager
 
     init(isInBackgroundSession: Bool,
-         encodingMemoryThreshold: UInt64 = MultipartUpload.encodingMemoryThreshold,
+         encodingMemoryThreshold: UInt64,
          request: URLRequestConvertible,
          multipartFormData: MultipartFormData) {
         self.isInBackgroundSession = isInBackgroundSession
@@ -79,11 +76,11 @@ open class MultipartUpload {
 }
 
 extension MultipartUpload: UploadConvertible {
-    public func asURLRequest() throws -> URLRequest {
+    func asURLRequest() throws -> URLRequest {
         return try result.get().request
     }
 
-    public func createUploadable() throws -> UploadRequest.Uploadable {
+    func createUploadable() throws -> UploadRequest.Uploadable {
         return try result.get().uploadable
     }
 }

+ 2 - 2
Source/Session.swift

@@ -316,7 +316,7 @@ open class Session {
     }
 
     open func upload(multipartFormData: @escaping (MultipartFormData) -> Void,
-                     usingThreshold encodingMemoryThreshold: UInt64 = MultipartUpload.encodingMemoryThreshold,
+                     usingThreshold encodingMemoryThreshold: UInt64 = MultipartFormData.encodingMemoryThreshold,
                      fileManager: FileManager = .default,
                      to url: URLConvertible,
                      method: HTTPMethod = .post,
@@ -334,7 +334,7 @@ open class Session {
     }
 
     open func upload(multipartFormData: MultipartFormData,
-                     usingThreshold encodingMemoryThreshold: UInt64 = MultipartUpload.encodingMemoryThreshold,
+                     usingThreshold encodingMemoryThreshold: UInt64 = MultipartFormData.encodingMemoryThreshold,
                      with request: URLRequestConvertible,
                      interceptor: RequestInterceptor? = nil) -> UploadRequest {
         let multipartUpload = MultipartUpload(isInBackgroundSession: (session.configuration.identifier != nil),