Closed
Description
Previous ID | SR-5516 |
Radar | None |
Original Reporter | @pushkarnk |
Type | Bug |
Status | Closed |
Resolution | Done |
Additional Detail from JIRA
Votes | 0 |
Component/s | Foundation |
Labels | Bug, Linux |
Assignee | @pushkarnk |
Priority | Medium |
md5: 961cc02a2b082602c3cf7791b69806ca
Issue Description:
import Foundation
import Dispatch
class HTTPUploadDelegate: NSObject {
var totalBytesSent: Int64 = 0
}
extension HTTPUploadDelegate: URLSessionTaskDelegate {
func urlSession(_ session: URLSession, task: URLSessionTask, didSendBodyData bytesSent: Int64, totalBytesSent: Int64, totalBytesExpectedToSend: Int64) {
self.totalBytesSent = totalBytesSent
}
}
extension HTTPUploadDelegate: URLSessionDataDelegate {
func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data) {
print("totalBytesSent = \(totalBytesSent)")
exit(0)
}
}
let session = URLSession(configuration: .default, delegate: HTTPUploadDelegate(), delegateQueue: nil)
var request = URLRequest(url: URL(string: "http://posttestserver.com/post.php")!)
request.httpMethod = "POST"
let fileData = Data(count: 48*1024)
let task = session.uploadTask(with: request, from: fileData)
task.resume()
dispatchMain()
Expected output (also, output on Darwin):
totalBytesSent = 49152
Output on Linux:
totalBytesSent = 0