Skip to content

Commit

Permalink
Avoid disabling the DDG user agent for the Suggestions service.
Browse files Browse the repository at this point in the history
  • Loading branch information
samsymons committed Feb 25, 2022
1 parent aff032d commit 57aeab7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
12 changes: 2 additions & 10 deletions DuckDuckGo/Common/Extensions/URLRequestExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,15 @@ extension URLRequest {
case referer = "Referer"
}

// Note: Change the user agent to macOS version before the release
static func defaultRequest(with url: URL, useDuckDuckGoUserAgent: Bool = true) -> URLRequest {
static func defaultRequest(with url: URL) -> URLRequest {
var request = URLRequest(url: url)
request.setValue("gzip;q=1.0, compress;q=0.5",
forHTTPHeaderField: HeaderKey.acceptEncoding.rawValue)

let appVersion = AppVersion.shared.versionNumber
let appId = AppVersion.shared.identifier
let systemVersion = ProcessInfo.processInfo.operatingSystemVersion

let userAgent: String

if useDuckDuckGoUserAgent {
userAgent = "ddg_macos/\(appVersion) (\(appId); macOS \(systemVersion))"
} else {
userAgent = UserAgent.fallbackWebViewDefault
}
let userAgent = "ddg_macos/\(appVersion) (\(appId); macOS \(systemVersion))"

request.setValue(userAgent, forHTTPHeaderField: HeaderKey.userAgent.rawValue)

Expand Down
3 changes: 1 addition & 2 deletions DuckDuckGo/Suggestions/Model/SuggestionContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ extension SuggestionContainer: SuggestionLoadingDataSource {
}
}

// The DuckDuckGo user agent is disabled for AC requests until there is enough volume from the browser.
var request = URLRequest.defaultRequest(with: url, useDuckDuckGoUserAgent: false)
var request = URLRequest.defaultRequest(with: url)
request.timeoutInterval = 1

suggestionsURLSession.dataTask(with: request) { (data, _, error) in
Expand Down

0 comments on commit 57aeab7

Please sign in to comment.