Questions tagged [nsurlprotocol]

NSURLProtocol is an abstract class that provides the basic structure for performing protocol-specific loading of URL data.

NSURLProtocol is available in iOS 2.0 and later with iOS and available in OS X v10.2 with Safari 1.0 installed ,available in OS X v10.2.7 and later with OSX.

An NSURLProtocol object handles the loading of protocol-specific URL data. The NSURLProtocol class itself is an abstract class that provides the infrastructure for processing URLs with a specific URL scheme. You create subclasses for any custom protocols or URL schemes that your app supports.

Apps never need to instantiate an NSURLProtocol subclass directly. When a download starts, the system creates the appropriate protocol object to handle the corresponding URL request. All you have to do is define your protocol class and call the registerClass: class method during your app’s launch time so that the system is aware of your protocol.

Source : NSURLProtocol Class Reference

NOTE

You cannot use this class to define custom URL schemes and protocols in watchOS 2 and later.
142 questions
0
votes
0 answers

Unit testing SSL pinning with URLProtocol

Aim: Unit test app's ssl pinning Approximate implementation aimed for: subclass URLProtocol Insert custom URLProtocol into Session's configuration Use session with custom config when generating requests catch the request and generate response with…
0
votes
1 answer

WKWebView lost body in NSURLProtocol

When I use NSURLProtocol to catch the requests from WKWebView, the body is lost. Any way to fix this issue?
Jerrold
  • 47
  • 1
  • 3
0
votes
2 answers

Why did writing with URLSessionStreamTask time out?

I'm practicing making a URLProtocol subclass. I'm using URLSessionStreamTask to do the reading & writing. When trying out the subclass, I got a time-out. I thought I messed up my reading routine, but adding logging showed I didn't get past the…
CTMacUser
  • 1,996
  • 1
  • 16
  • 27
0
votes
0 answers

Store pointer inside NSNumber

I implementing custom subclass of the NSURLProtocol. I need to store my NSURLProtocol instance inside NSMutableURLRequest. Since [NSURLProtocol setProperty:forKey:inRequest:] raises warning Invalid protocol-property list if you try to store…
KY1VSTAR
  • 395
  • 4
  • 16
0
votes
1 answer

How to get custom NSURLProtocol working with SNI

First the server side: There is an internal reachable apache server with several virtual hosts. For http (sans 's'!) requests, I use the IP for the URL and add the hostname in the Host-Headerfield. That works quite good. But when I make an SSL…
MatzeLoCal
  • 392
  • 3
  • 14
0
votes
1 answer

NSURLProtocol chain?

Can we use such a chain? for example, I know urls like abc://wwww.example.com will be handled by a subclass of NSURLProtocol. But it is from a third party library and I do not have the source code to modify the response. So I provide another…
Rao
  • 51
  • 7
0
votes
1 answer

NSURLSession request HTTPBody becomes nil in Custom NSURLProtocol

In my application, I am performing POST using NSURLSession. Steps followed: Setting Header Setting HTTPBody Making POST request using NSURLSession. The code is: NSDictionary *parameters = @{ @"searchTerm": @"shampoo", @"sort": @"Most Reviewed"…
0
votes
2 answers

Swift - Log all requests in mac app

I have tried to use NSURLProtocol to log all requests in a Swift 2.3 project. However not all URL requests are being logged. Specifically all the Alamofire requests are not being recorded. Sample code class AppDelegate: NSObject,…
datinc
  • 3,404
  • 3
  • 24
  • 33
0
votes
0 answers

Swift 3: UrlProtocol didCompleteWithError delegate never be called

As title, I'm trying to build a custom url protocol. I found this and I followed the code provided completely. However, this delegate func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) is never be…
0
votes
1 answer

NSURLProtocol is not getting all requests

So I have implemented my own NSURLProtocol sub class. I registered it when app launches. I tried to print all requests in canInitWithRequest:, however while running, it's not getting all the requests, just a few domains. Is there anything I should…
Wingzero
  • 9,644
  • 10
  • 39
  • 80
0
votes
1 answer

Auth challenge for NSURLSession not working with Custom protocol

I have implemented custom protocol with session delegate as below - - (void)startLoading { NSMutableURLRequest *mReq = [self.request mutableCopy]; NSURL *url = [[self request] URL]; NSURLSessionConfiguration *config = [NSURLSessionConfiguration…
sona
  • 11
  • 2
0
votes
1 answer

iOS How to differentiate a UIWebView's request?

How to differentiate a NSURLRequest between UIWebView and NSURLConnection in NSURLProtocol or NSURLCache? I want to monitor a UIWebView's request without NSURLConnection, how to do? The UIWebView's content has resource: js, image, href. How to…
fyxrhyry
  • 135
  • 1
  • 8
0
votes
1 answer

NSURLProtocol not responding to UIWebviews

I am having an issue with UIWebviews and a couple of custom NSURLProtocols that I have in my app. All my non web view request are invoked with NSURLSession, so in order for those request to go through the protocols I need to set the…
iOSAddicted
  • 389
  • 1
  • 17
0
votes
1 answer

Using NSURLSession inside NSURLProtocol

I'm trying to create a transparent NSURLProtocol for http:// and https:// connections using NSURLSession. However at the moment, even though the completion handler is being run, URL requests with the app (UIWebView) are coming back blank. Does…
Sam Heather
  • 1,493
  • 3
  • 19
  • 42
0
votes
2 answers

Custom NSURLProtocol caused __psynch_mutexwait

I am subclassing NSURLProtocol to intercept HTTP request. Here is the custom NSURLProtocol class. + (BOOL)canInitWithRequest:(NSURLRequest *)request { if (NSOrderedSame != [request.URL.scheme caseInsensitiveCompare:@"http"] && …
Weizhi
  • 174
  • 4
  • 22