Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-5516] Upload tasks don't call the urlSession(_:task:didSendBodyData...) delegate method #3829

Closed
pushkarnk opened this issue Jul 20, 2017 · 1 comment

Comments

@pushkarnk
Copy link
Collaborator

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

@pushkarnk
Copy link
Collaborator Author

#1121

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant