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

Malware protection 2: refactor APIClient #1092

Merged
merged 6 commits into from
Nov 28, 2024

Conversation

mallexxx
Copy link
Collaborator

Please review the release process for BrowserServicesKit here.

Required:

Task/Issue URL: https://app.asana.com/0/481882893211075/1208033567421351/f
iOS PR:
macOS PR:
What kind of version bump will this require?: Major

Optional:

Tech Design URL:
CC:

Description:

  • Refactor APIClient to use Networking.APIRequestV2; implement generic request/response
  • Fix query argument percent-encoding issue in APIRequestV2

Steps to test this PR:

  1. Validate Phishing Protection change sets and Match API calls work as before

OS Testing:

  • iOS 14
  • iOS 15
  • iOS 16
  • macOS 10.15
  • macOS 11
  • macOS 12

Internal references:

Software Engineering Expectations
Technical Design Template

@mallexxx mallexxx changed the base branch from main to alex/malware-protection-1 November 25, 2024 15:49
Copy link
Collaborator

@not-a-rootkit not-a-rootkit left a comment

Choose a reason for hiding this comment

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

LGTM. Just left a comment on cache policies and timeouts. I've noticed that the current production deployment has a very long cache policy of 1 year, which causes some issues right now in internal.

I don't think it's worth changing the cache policy on the client though, as I'm working on a task to fix the cache headers on the backend separately. Might be good to just add a stricter timeout on /matches calls.

}
return nil
public func matches(forHashPrefix hashPrefix: String) async throws -> APIClient.Response.Matches {
let result = try await load(.matches(hashPrefix: hashPrefix))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we pass a shorter timeout to the /matches endpoint? This could block navigation so we should favour navigation loading if the backend is degraded. On Android we're looking at a maximum 1 second timeout for this request. The other requests can be heavier but they are background tasks anyway so not as risky.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added parametrized Timeout

public func load<Request: APIRequestProtocol>(_ requestConfig: Request) async throws -> Request.ResponseType {
let requestType = requestConfig.requestType
let headers = environment.headers(for: requestType)
let url = environment.url(for: requestType)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are there any specific client caching configs we should consider here? The server should return a TTL of 10 minutes for the API so I imagine this will be automatically respected here, but just checking.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I‘d say no as the caching policies should be set on the backend side: if there‘s caching it should be fine as all of our requests are parametrized (i.e. revision, hash etc)

@mallexxx mallexxx changed the title Malware protection: refactor APIClient Malware protection 2: refactor APIClient Nov 27, 2024
@mallexxx mallexxx merged commit 49f022e into alex/malware-protection-1 Nov 28, 2024
7 checks passed
@mallexxx mallexxx deleted the alex/malware-protection-2 branch November 28, 2024 15:40
@mallexxx mallexxx restored the alex/malware-protection-2 branch November 28, 2024 16:19
@mallexxx mallexxx deleted the alex/malware-protection-2 branch November 28, 2024 16:20
mallexxx added a commit to duckduckgo/macos-browser that referenced this pull request Nov 28, 2024
Task/Issue URL:
https://app.asana.com/0/481882893211075/1208033567421351/f
BSK PR: duckduckgo/BrowserServicesKit#1092

**Description**:
- Refactor APIClient to use Networking.APIRequestV2; implement generic
request/response (BSK)

**Optional E2E tests**:
- [ ] Run PIR E2E tests
Check this to run the Personal Information Removal end to end tests. If
updating CCF, or any PIR related code, tick this.

**Steps to test this PR**:
1. Validate Phishing Protection change sets and Match API calls work as
before

<!--
Tagging instructions
If this PR isn't ready to be merged for whatever reason it should be
marked with the `DO NOT MERGE` label (particularly if it's a draft)
If it's pending Product Review/PFR, please add the `Pending Product
Review` label.

If at any point it isn't actively being worked on/ready for
review/otherwise moving forward (besides the above PR/PFR exception)
strongly consider closing it (or not opening it in the first place). If
you decide not to close it, make sure it's labelled to make it clear the
PRs state and comment with more information.
-->

**Definition of Done**:

* [ ] Does this PR satisfy our [Definition of
Done](https://app.asana.com/0/1202500774821704/1207634633537039/f)?

---
###### Internal references:
[Pull Request Review
Checklist](https://app.asana.com/0/1202500774821704/1203764234894239/f)
[Software Engineering
Expectations](https://app.asana.com/0/59792373528535/199064865822552)
[Technical Design
Template](https://app.asana.com/0/59792373528535/184709971311943)
[Pull Request
Documentation](https://app.asana.com/0/1202500774821704/1204012835277482/f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants