Skip to content
This repository has been archived by the owner on Aug 10, 2024. It is now read-only.

Return an unexpected response if the redirect its the same that the original url #29

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions Sources/RSWeb/DownloadSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,21 @@ extension DownloadSession: URLSessionTaskDelegate {

if response.statusCode == 301 || response.statusCode == 308 {
if let oldURLString = task.originalRequest?.url?.absoluteString, let newURLString = request.url?.absoluteString {
cacheRedirect(oldURLString, newURLString)
guard oldURLString != newURLString else {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you rewrite this as if oldURLString == newURLString {? This would make it easier to understand for future people reading the code.

if let representedObject = infoForTask(task)?.representedObject {
delegate.downloadSession(self, didReceiveUnexpectedResponse: response, representedObject: representedObject)
}

completionHandler(nil)
removeTask(task)

return
}

cacheRedirect(oldURLString, newURLString)
}
}

completionHandler(request)
}
}
Expand Down Expand Up @@ -219,7 +230,7 @@ private extension DownloadSession {
taskIdentifierToInfoDictionary[task.taskIdentifier] = nil

addDataTaskFromQueueIfNecessary()

if tasksInProgress.count + tasksPending.count < 1 {
representedObjects.removeAllObjects()
delegate.downloadSessionDidCompleteDownloadObjects(self)
Expand Down