Skip to content

URLSessionTask with a delegate does not handle cookies properly #5294

@crazytonyli

Description

@crazytonyli

Let's say we have an HTTP request that returns a 302 response with cookies. When using NSURLSessionTask with a delegate, the cookies are not included in the redirect request.

let (data, response): (Data, URLResponse) = try await withCheckedThrowingContinuation { continuation in
    let task = session.dataTask(with: request) { (data, response, error) in
        if let error = error {
            continuation.resume(throwing: error)
        } else {
            continuation.resume(returning: (data!, response!))
        }
    }
    task.delegate = delegate
    task.resume()
}

The issue can be reproduced by this project.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions