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

Allow passing URLRequest as PathConfiguration source #127

Merged
merged 2 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions Source/Path Configuration/PathConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,6 @@ extension PathConfiguration {
case data(Data)
case file(URL)
case server(URL)
case serverRequest(URLRequest)
}
}
9 changes: 8 additions & 1 deletion Source/Path Configuration/PathConfigurationLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ final class PathConfigurationLoader {
loadFile(url)
case .server(let url):
download(from: url)
case .serverRequest(let request):
download(with: request)
}
}
}
Expand All @@ -32,12 +34,17 @@ final class PathConfigurationLoader {
private func download(from url: URL) {
precondition(!url.isFileURL, "URL provided for server is a file url")

download(with: URLRequest(url: url))
}

private func download(with request: URLRequest) {

// Immediately load most recent cached version if available
if let data = cachedData() {
loadData(data)
}

URLSession.shared.dataTask(with: url) { [weak self] data, response, error in
URLSession.shared.dataTask(with: request) { [weak self] data, response, error in
guard let data = data,
let httpResponse = response as? HTTPURLResponse,
httpResponse.statusCode == 200
Expand Down