Skip to content

Commit 64f5359

Browse files
seabayleaparkera
authored andcommitted
If present, pass URLRequest.httpBody to the dataTask (#633)
1 parent 1d56e6b commit 64f5359

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Foundation/NSURLSession/NSURLSessionTask.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,13 @@ open class URLSessionTask : NSObject, NSCopying {
9090
self.tempFileURL = URL(fileURLWithPath: fileName)
9191
super.init()
9292
}
93-
/// Create a data task, i.e. with no body
93+
/// Create a data task. If there is a httpBody in the URLRequest, use that as a parameter
9494
internal convenience init(session: URLSession, request: URLRequest, taskIdentifier: Int) {
95-
self.init(session: session, request: request, taskIdentifier: taskIdentifier, body: .none)
95+
if let bodyData = request.httpBody {
96+
self.init(session: session, request: request, taskIdentifier: taskIdentifier, body: _Body.data(createDispatchData(bodyData)))
97+
} else {
98+
self.init(session: session, request: request, taskIdentifier: taskIdentifier, body: .none)
99+
}
96100
}
97101
internal init(session: URLSession, request: URLRequest, taskIdentifier: Int, body: _Body) {
98102
self.session = session

0 commit comments

Comments
 (0)