NSURLProtocolClient Protocol Reference

Conforms to
Framework
/System/Library/Frameworks/Foundation.framework
Availability
Available in OS X v10.2 with Safari 1.0 installed.
Available in OS X v10.2.7 and later.
Companion guide
Declared in
NSURLProtocol.h

Overview

The NSURLProtocolClient protocol provides the interface used by NSURLProtocol subclasses to communicate with the URL loading system. An application should never have the need to implement this protocol.

Tasks

Protocol Methods

Instance Methods

URLProtocol:cachedResponseIsValid:

Sent to indicate to the URL loading system that a cached response is valid. (required)

- (void)URLProtocol:(NSURLProtocol *)protocol cachedResponseIsValid:(NSCachedURLResponse *)cachedResponse
Parameters
protocol

The URL protocol object sending the message.

cachedResponse

The cached response whose validity is being communicated.

Availability
  • Available in OS X v10.2 with Safari 1.0 installed.
  • Available in OS X v10.2.7 and later.
Declared In
NSURLProtocol.h

URLProtocol:didCancelAuthenticationChallenge:

Sent to indicate to the URL loading system that an authentication challenge has been canceled. (required)

- (void)URLProtocol:(NSURLProtocol *)protocol didCancelAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
Parameters
protocol

The URL protocol object sending the message.

challenge

The authentication challenge that was canceled.

Availability
  • Available in OS X v10.2 with Safari 1.0 installed.
  • Available in OS X v10.2.7 and later.
Declared In
NSURLProtocol.h

URLProtocol:didFailWithError:

Sent when the load request fails due to an error. (required)

- (void)URLProtocol:(NSURLProtocol *)protocol didFailWithError:(NSError *)error
Parameters
protocol

The URL protocol object sending the message.

error

The error that caused the failure of the load request.

Availability
  • Available in OS X v10.2 with Safari 1.0 installed.
  • Available in OS X v10.2.7 and later.
Declared In
NSURLProtocol.h

URLProtocol:didLoadData:

An NSURLProtocol subclass instance, protocol, sends this message to [protocol client] as it loads data. (required)

- (void)URLProtocol:(NSURLProtocol *)protocol didLoadData:(NSData *)data
Discussion

The data object must contain only new data loaded since the previous invocation of this method.

Availability
  • Available in OS X v10.2 with Safari 1.0 installed.
  • Available in OS X v10.2.7 and later.
Declared In
NSURLProtocol.h

URLProtocol:didReceiveAuthenticationChallenge:

Sent to indicate to the URL loading system that an authentication challenge has been received. (required)

- (void)URLProtocol:(NSURLProtocol *)protocol didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
Parameters
protocol

The URL protocol object sending the message.

challenge

The authentication challenge that has been received.

Discussion

The protocol client guarantees that it will answer the request on the same thread that called this method. The client may add a default credential to the challenge it issues to the connection delegate, if protocol did not provide one.

Availability
  • Available in OS X v10.2 with Safari 1.0 installed.
  • Available in OS X v10.2.7 and later.
Declared In
NSURLProtocol.h

URLProtocol:didReceiveResponse:cacheStoragePolicy:

Sent to indicate to the URL loading system that the protocol implementation has created a response object for the request. (required)

- (void)URLProtocol:(NSURLProtocol *)protocol didReceiveResponse:(NSURLResponse *)response cacheStoragePolicy:(NSURLCacheStoragePolicy)policy
Parameters
protocol

The URL protocol object sending the message.

response

The newly available response object.

policy

The cache storage policy for the response.

Discussion

The implementation should use the provided cache storage policy to determine whether to store the response in a cache.

Availability
  • Available in OS X v10.2 with Safari 1.0 installed.
  • Available in OS X v10.2.7 and later.
Declared In
NSURLProtocol.h

URLProtocol:wasRedirectedToRequest:redirectResponse:

Sent to indicate to the URL loading system that the protocol implementation has been redirected. (required)

- (void)URLProtocol:(NSURLProtocol *)protocol wasRedirectedToRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse
Parameters
protocol

The URL protocol object sending the message.

request

The new request that the original request was redirected to.

redirectResponse

The response from the original request that caused the redirect.

Availability
  • Available in OS X v10.2 with Safari 1.0 installed.
  • Available in OS X v10.2.7 and later.
Declared In
NSURLProtocol.h

URLProtocolDidFinishLoading:

Sent to indicate to the URL loading system that the protocol implementation has finished loading. (required)

- (void)URLProtocolDidFinishLoading:(NSURLProtocol *)protocol
Parameters
protocol

The URL protocol object sending the message.

Availability
  • Available in OS X v10.2 with Safari 1.0 installed.
  • Available in OS X v10.2.7 and later.
Declared In
NSURLProtocol.h