Skip to content

Fix URLSessionProxy async uploads ignoring the task delegate - #381

Draft
ffittschen wants to merge 1 commit into
kean:mainfrom
ffittschen:fix/url-session-proxy-async-upload-delegate
Draft

ffittschen wants to merge 1 commit into
kean:mainfrom
ffittschen:fix/url-session-proxy-async-upload-delegate

Conversation

@ffittschen

Copy link
Copy Markdown

This PR fixes URLSessionProxy.upload(for:from:delegate:) and upload(for:fromFile:delegate:) ignoring the caller's delegate. The root cause was that both wrap the delegate in a URLSessionProxyDelegate but never pass it to URLSession. As a result, the caller's task delegate gets no callbacks, so an auth challenge goes unanswered and the call returns 401. The proxy also never sees the created task, so the upload stays pending in the console forever. The fix passes the delegate, as data(for:delegate:) and download(for:delegate:) already do.

Found while working on #378.

How to test

  • Upload with URLSessionProxy.upload(for:from:delegate:) to an endpoint that asks for Basic auth, with a delegate that answers the challenge. Assert that the delegate gets the challenge, the call returns 200, and the console shows the task as completed.
  • Repeat with upload(for:fromFile:delegate:).

URLSessionProxy.upload(for:from:delegate:) and
upload(for:fromFile:delegate:) create a URLSessionProxyDelegate that
wraps the caller's delegate, but never pass it to URLSession:
- the caller's task delegate was silently ignored, so it got no
  authentication challenges or progress callbacks;
- the proxy never saw the created task, so it never logged the
  completion: the upload stayed pending in the console, without its
  response.

Pass the delegate, like data(for:delegate:) and
download(for:delegate:) already do.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant