@@ -67,33 +67,36 @@ public struct URLSessionTransport: ClientTransport {
6767 public var session : URLSession
6868
6969 /// Creates a new configuration with the provided session.
70- /// - Parameter session: The URLSession used for performing HTTP operations.
71- /// If none is provided, the system uses the shared URLSession.
72- public init ( session: URLSession = . shared) { self . init ( session: session, implementation: . platformDefault) }
70+ /// - Parameters:
71+ /// - session: The URLSession used for performing HTTP operations.
72+ /// - httpBodyProcessingMode: The mode used to process HTTP request and response bodies.
73+ public init ( session: URLSession = . shared, httpBodyProcessingMode: HTTPBodyProcessingMode = . platformDefault) {
74+ self . session = session
75+ let implementation = httpBodyProcessingMode. implementation
76+ if case . streaming = implementation {
77+ precondition ( Implementation . platformSupportsStreaming, " Streaming not supported on platform " )
78+ }
79+ self . implementation = implementation
80+ }
7381 /// Specifies the mode in which HTTP request and response bodies are processed.
74- public enum HTTPBodyProcessingMode {
82+ public struct HTTPBodyProcessingMode {
83+ /// Exposing the internal implementation directly.
84+ fileprivate let implementation : Configuration . Implementation
85+
86+ private init ( _ implementation: Configuration . Implementation ) { self . implementation = implementation }
87+
7588 /// Processes the HTTP body incrementally as bytes become available.
7689 ///
7790 /// Use this mode to handle large payloads efficiently or to begin processing
7891 /// before the entire body has been received. Will throw a `URLSessionTransportError.streamingNotSupported`
7992 /// error if not available on the platform.
80- case streamed
81-
93+ public static let streamed = HTTPBodyProcessingMode ( . defaultStreaming)
8294 /// Waits until the entire HTTP body has been received before processing begins.
8395 ///
8496 /// Use this mode when it's necessary or simpler to handle complete data payloads at once.
85- case buffered
86- }
87- /// Creates a new configuration with the provided session.
88- /// - Parameters:
89- /// - session: The URLSession used for performing HTTP operations.
90- /// - httpBodyProcessingMode: The mode used to process HTTP request and response bodies.
91- public init ( session: URLSession = . shared, httpBodyProcessingMode: HTTPBodyProcessingMode ) {
92- self . session = session
93- switch httpBodyProcessingMode {
94- case . streamed: self . implementation = . defaultStreaming
95- case . buffered: self . implementation = . buffering
96- }
97+ public static let buffered = HTTPBodyProcessingMode ( . buffering)
98+ /// Automatically chooses the optimal transport mode, based on the platform being used.
99+ public static let platformDefault = HTTPBodyProcessingMode ( . platformDefault)
97100 }
98101
99102 enum Implementation {
@@ -103,13 +106,6 @@ public struct URLSessionTransport: ClientTransport {
103106
104107 var implementation : Implementation
105108
106- init ( session: URLSession = . shared, implementation: Implementation = . platformDefault) {
107- self . session = session
108- if case . streaming = implementation {
109- precondition ( Implementation . platformSupportsStreaming, " Streaming not supported on platform " )
110- }
111- self . implementation = implementation
112- }
113109 }
114110
115111 /// A set of configuration values used by the transport.
0 commit comments