diff --git a/Sources/RealHTTP/Client/HTTPRequest/HTTPRequest.swift b/Sources/RealHTTP/Client/HTTPRequest/HTTPRequest.swift index 168337b..d3c17d8 100644 --- a/Sources/RealHTTP/Client/HTTPRequest/HTTPRequest.swift +++ b/Sources/RealHTTP/Client/HTTPRequest/HTTPRequest.swift @@ -142,7 +142,7 @@ public class HTTPRequest: CustomStringConvertible { public var allowsCellularAccess: Bool = true /// Request's body. - public var body: HTTPBody = .empty + public var body: HTTPBody? /// Description of the request public var description: String { @@ -460,7 +460,7 @@ extension HTTPRequest { // - client's common headers (user defined) // - specific body's headers (automatically set) // - request's custom headers set by the user (user defined) - let requestHeaders = (client.headers + self.body.headers + self.headers) + let requestHeaders = (client.headers + (self.body?.headers ?? HTTPHeaders()) + self.headers) // Prepare the request var urlRequest = try URLRequest(url: fullURL, @@ -470,7 +470,9 @@ extension HTTPRequest { headers: requestHeaders) urlRequest.httpShouldHandleCookies = true urlRequest.allowsCellularAccess = allowsCellularAccess - try urlRequest.setHTTPBody(body) // setup the body + if let body = self.body { + try urlRequest.setHTTPBody(body) // setup the body + } return urlRequest } diff --git a/Sources/RealHTTP/Client/Internal/HTTPDataLoader/HTTPDataLoader.swift b/Sources/RealHTTP/Client/Internal/HTTPDataLoader/HTTPDataLoader.swift index c791c97..14d4aa1 100644 --- a/Sources/RealHTTP/Client/Internal/HTTPDataLoader/HTTPDataLoader.swift +++ b/Sources/RealHTTP/Client/Internal/HTTPDataLoader/HTTPDataLoader.swift @@ -364,7 +364,7 @@ internal class HTTPDataLoader: NSObject, return } - if let streamContent = request.body.content as? HTTPBody.StreamContent, + if let streamContent = request.body?.content as? HTTPBody.StreamContent, let inputStream = streamContent.inputStream(recreate: true).stream { inputStream.open() // open the stream completionHandler(inputStream)