@@ -67,33 +67,36 @@ public struct URLSessionTransport: ClientTransport {
67
67
public var session : URLSession
68
68
69
69
/// 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
+ }
73
81
/// 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
+
75
88
/// Processes the HTTP body incrementally as bytes become available.
76
89
///
77
90
/// Use this mode to handle large payloads efficiently or to begin processing
78
91
/// before the entire body has been received. Will throw a `URLSessionTransportError.streamingNotSupported`
79
92
/// error if not available on the platform.
80
- case streamed
81
-
93
+ public static let streamed = HTTPBodyProcessingMode ( . defaultStreaming)
82
94
/// Waits until the entire HTTP body has been received before processing begins.
83
95
///
84
96
/// 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)
97
100
}
98
101
99
102
enum Implementation {
@@ -103,13 +106,6 @@ public struct URLSessionTransport: ClientTransport {
103
106
104
107
var implementation : Implementation
105
108
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
- }
113
109
}
114
110
115
111
/// A set of configuration values used by the transport.
0 commit comments