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

feat: Support to set ignored URLProtocol classes #155

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

HoaPham98
Copy link

I have an idea to prevent the duplicate records issue when using with URLProtocol. The issue has been mentioned in: #154

Copy link
Member

@NghiaTranUIT NghiaTranUIT left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, but may I ask whether or not you test it?

I tested and the bug hasn't fixed yet.

CleanShot.2024-11-07.at.13.20.13.mp4

Set a breakpoint, I confirmed that it jumps to the return nil. However, 2 requests are still appeared.

            if checkShouldIgnore(on: request) {
                return nil
            }

@HoaPham98
Copy link
Author

Thanks for the PR, but may I ask whether or not you test it?

I tested and the bug hasn't fixed yet.

CleanShot.2024-11-07.at.13.20.13.mp4
Set a breakpoint, I confirmed that it jumps to the return nil. However, 2 requests are still appeared.

            if checkShouldIgnore(on: request) {
                return nil
            }

Oh, I see. If with my above code, it won't work. But if you modify the request in method startLoading, it will work

override class func canonicalRequest(for request: URLRequest) -> URLRequest {
        return request
    }
    
  override func startLoading() {
      var request = request
      request.addValue("Test value", forHTTPHeaderField: "Custom-Header")
      URLSession.shared.dataTask(with: request) { data, response, error in
          if let error {
              self.client?.urlProtocol(self, didFailWithError: error)
          } else if let response {
              self.client?.urlProtocol(self, didReceive: response, cacheStoragePolicy: .notAllowed)
              if let data {
                  self.client?.urlProtocol(self, didLoad: data)
              }
          }
          self.client?.urlProtocolDidFinishLoading(self)
      }.resume()
  }

I will recheck my solution. Feel free to discuss with me :D

@HoaPham98 HoaPham98 marked this pull request as draft November 7, 2024 14:25
@HoaPham98 HoaPham98 marked this pull request as ready for review November 8, 2024 01:06
@HoaPham98
Copy link
Author

Screen.Recording.2024-11-08.at.08.08.57.mov

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