From 83840bd889f6f470235059dcee11366c978f109f Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 26 May 2024 20:59:14 -0700 Subject: [PATCH] Add User-Agent header. --- Web/Sources/Web/DownloadSession.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Web/Sources/Web/DownloadSession.swift b/Web/Sources/Web/DownloadSession.swift index ad98e4fd2..e160f772b 100755 --- a/Web/Sources/Web/DownloadSession.swift +++ b/Web/Sources/Web/DownloadSession.swift @@ -13,12 +13,19 @@ import os public protocol DownloadSessionDelegate: AnyObject { + // DownloadSession will add User-Agent header to request returned by delegate @MainActor func downloadSession(_ downloadSession: DownloadSession, requestForIdentifier: String) -> URLRequest? + @MainActor func downloadSession(_ downloadSession: DownloadSession, downloadDidCompleteForIdentifier: String, response: URLResponse?, data: Data?, error: Error?) + @MainActor func downloadSession(_ downloadSession: DownloadSession, shouldContinueAfterReceivingData: Data, identifier: String) -> Bool + @MainActor func downloadSession(_ downloadSession: DownloadSession, didReceiveUnexpectedResponse: URLResponse, identifier: String) + @MainActor func downloadSession(_ downloadSession: DownloadSession, didReceiveNotModifiedResponse: URLResponse, identifier: String) + @MainActor func downloadSession(_ downloadSession: DownloadSession, didDiscardDuplicateIdentifier: String) + @MainActor func downloadSessionDidComplete(_ downloadSession: DownloadSession) } @@ -207,6 +214,8 @@ private extension DownloadSession { } } + requestToUse.addValue(UserAgent.fromInfoPlist, forHTTPHeaderField: HTTPRequestHeader.userAgent) + let task = urlSession.dataTask(with: requestToUse) let info = DownloadInfo(identifier, urlRequest: requestToUse)