Skip to content

Commit

Permalink
Session and task descriptions (apollographql/apollo-ios-dev#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
hishma authored and gh-action-runner committed Mar 8, 2024
1 parent 5068c44 commit 569f814
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions Sources/Apollo/URLSessionClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,17 @@ open class URLSessionClient: NSObject, URLSessionDelegate, URLSessionTaskDelegat
/// - Parameters:
/// - sessionConfiguration: The `URLSessionConfiguration` to use to set up the URL session.
/// - callbackQueue: [optional] The `OperationQueue` to tell the URL session to call back to this class on, which will in turn call back to your class. Defaults to `.main`.
/// - sessionDescription: [optional] A human-readable string that you can use for debugging purposes.
public init(sessionConfiguration: URLSessionConfiguration = .default,
callbackQueue: OperationQueue? = .main) {
callbackQueue: OperationQueue? = .main,
sessionDescription: String? = nil) {
super.init()
self.session = URLSession(configuration: sessionConfiguration,
delegate: self,
delegateQueue: callbackQueue)

let session = URLSession(configuration: sessionConfiguration,
delegate: self,
delegateQueue: callbackQueue)
session.sessionDescription = sessionDescription
self.session = session
}

/// Cleans up and invalidates everything related to this session client.
Expand Down Expand Up @@ -112,12 +117,14 @@ open class URLSessionClient: NSObject, URLSessionDelegate, URLSessionTaskDelegat
///
/// - Parameters:
/// - request: The request to perform.
/// - taskDescription: [optional] A description to add to the `URLSessionTask` for debugging purposes.
/// - rawTaskCompletionHandler: [optional] A completion handler to call once the raw task is done, so if an Error requires access to the headers, the user can still access these.
/// - completion: A completion handler to call when the task has either completed successfully or failed.
///
/// - Returns: The created URLSession task, already resumed, because nobody ever remembers to call `resume()`.
@discardableResult
open func sendRequest(_ request: URLRequest,
taskDescription: String? = nil,
rawTaskCompletionHandler: RawCompletion? = nil,
completion: @escaping Completion) -> URLSessionTask {
guard self.hasNotBeenInvalidated else {
Expand All @@ -126,6 +133,8 @@ open class URLSessionClient: NSObject, URLSessionDelegate, URLSessionTaskDelegat
}

let task = self.session.dataTask(with: request)
task.taskDescription = taskDescription

let taskData = TaskData(rawCompletion: rawTaskCompletionHandler,
completionBlock: completion)

Expand Down

0 comments on commit 569f814

Please sign in to comment.