Inherits from | |
Conforms to | |
Framework | /System/Library/Frameworks/Foundation.framework |
Availability | Available in Mac OS X v10.2 with Safari 1.0 installed. Available in Mac OS X v10.2.7 and later. |
Companion guide | |
Declared in | NSURLProtocol.h |
NSURLProtocol
is an abstract class that provides the basic structure for performing protocol-specific loading of URL data. Concrete subclasses handle the specifics associated with one or more protocols or URL schemes.
An application should never need to directly instantiate an NSURLProtocol
subclass. The instance of the appropriate NSURLProtocol
subclass for an NSURLRequest
is created by NSURLConnection
when a download is started.
The NSURLProtocolClient
protocol describes the methods an implementation uses to drive the URL loading system from a NSURLProtocol
subclass.
To support customization of protocol-specific requests, protocol implementors are encouraged to provide categories on NSURLRequest
and NSMutableURLRequest
. Protocol implementors who need to extend the capabilities of NSURLRequest
and NSMutableURLRequest
in this way can store and retrieve protocol-specific request data by using NSURLProtocol
’s class methods propertyForKey:inRequest:
and setProperty:forKey:inRequest:
.
An essential responsibility for a protocol implementor is creating a NSURLResponse
for each request it processes successfully. A protocol implementor may wish to create a custom, mutable NSURLResponse
class to provide protocol specific information.
Returns whether the protocol subclass can handle the specified request.
+ (BOOL)canInitWithRequest:(NSURLRequest *)request
The request to be handled.
YES
if the protocol subclass can handle request, otherwise NO
.
A subclass should inspect request and determine whether or not the implementation can perform a load with that request.
This is an abstract method and subclasses must provide an implementation.
NSURLProtocol.h
Returns a canonical version of the specified request.
+ (NSURLRequest *)canonicalRequestForRequest:(NSURLRequest *)request
The request whose canonical version is desired.
The canonical form of request.
It is up to each concrete protocol implementation to define what “canonical” means. A protocol should guarantee that the same input request always yields the same canonical form.
Special consideration should be given when implementing this method, because the canonical form of a request is used to lookup objects in the URL cache, a process which performs equality checks between NSURLRequest
objects.
This is an abstract method and subclasses must provide an implementation.
NSURLProtocol.h
Returns the property associated with the specified key in the specified request.
+ (id)propertyForKey:(NSString *)key inRequest:(NSURLRequest *)request
The key of the desired property.
The request whose properties are to be queried.
The property associated with key, or nil
if no property has been stored for key.
This method provides an interface for protocol implementors to access protocol-specific information associated with NSURLRequest
objects.
NSURLProtocol.h
Attempts to register a subclass of NSURLProtocol
, making it visible to the URL loading system.
+ (BOOL)registerClass:(Class)protocolClass
The subclass of NSURLProtocol to register.
YES
if the registration is successful, NO
otherwise. The only failure condition is if protocolClass is not a subclass of NSURLProtocol.
When the URL loading system begins to load a request, each registered protocol class is consulted in turn to see if it can be initialized with the specified request. The first NSURLProtocol
subclass to return YES
when sent a canInitWithRequest:
message is used to perform the URL load. There is no guarantee that all registered protocol classes will be consulted.
Classes are consulted in the reverse order of their registration. A similar design governs the process to create the canonical form of a request with canonicalRequestForRequest:
.
NSURLProtocol.h
Removes the property associated with the specified key in the specified request.
+ (void)removePropertyForKey:((NSString *)key inRequest:(NSMutableURLRequest *)request
The key whose value should be removed.
The request from which to remove the property value.
This method is used to provide an interface for protocol implementors to customize protocol-specific information associated with NSMutableURLRequest
objects.
NSURLProtocol.h
Returns whether two requests are equivalent for cache purposes.
+ (BOOL)requestIsCacheEquivalent:(NSURLRequest *)aRequest toRequest:(NSURLRequest *)bRequest
The request to compare with bRequest.
The request to compare with aRequest.
YES
if aRequest and bRequest are equivalent for cache purposes, NO
otherwise. Requests are considered equivalent for cache purposes if and only if they would be handled by the same protocol and that protocol declares them equivalent after performing implementation-specific checks.
The NSURLProtocol
implementation of this method compares the URLs of the requests to determine if the requests should be considered equivalent. Subclasses can override this method to provide protocol-specific comparisons.
NSURLProtocol.h
Sets the property associated with the specified key in the specified request.
+ (void)setProperty:(id)value forKey:(NSString *)key inRequest:(NSMutableURLRequest *)request
The value to set for the specified property.
The key for the specified property.
The request for which to create the property.
This method is used to provide an interface for protocol implementors to customize protocol-specific information associated with NSMutableURLRequest
objects.
NSURLProtocol.h
Unregisters the specified subclass of NSURLProtocol
.
+ (void)unregisterClass:(Class)protocolClass
The subclass of NSURLProtocol to unregister.
After this method is invoked, protocolClass is no longer consulted by the URL loading system.
NSURLProtocol.h
Returns the receiver’s cached response.
- (NSCachedURLResponse *)cachedResponse
The receiver's cached response.
Subclasses must implement this method.
NSURLProtocol.h
Returns the object the receiver uses to communicate with the URL loading system.
- (id < NSURLProtocolClient >)client
The object the receiver uses to communicate with the URL loading system.
NSURLProtocol.h
Initializes an NSURLProtocol
object.
- (id)initWithRequest:(NSURLRequest *)request cachedResponse:(NSCachedURLResponse *)cachedResponse client:(id < NSURLProtocolClient >)client
The URL request for the URL protocol object.
A cached response for the request; may be nil
if there is no existing cached response for the request.
An object that provides an implementation of the NSURLProtocolClient protocol that the receiver uses to communicate with the URL loading system.
Subclasses should override this method to do any custom initialization. An application should never explicitly call this method.
This is the designated intializer for NSURLProtocol
.
NSURLProtocol.h
Returns the receiver’s request.
- (NSURLRequest *)request
The receiver's request.
NSURLProtocol.h
Starts protocol-specific loading of the request.
- (void)startLoading
When this method is called, the subclass implementation should start loading the request, providing feedback to the URL loading system via the NSURLProtocolClient
protocol.
Subclasses must implement this method.
NSURLProtocol.h
Stops protocol-specific loading of the request.
- (void)stopLoading
When this method is called, the subclass implementation should stop loading a request. This could be in response to a cancel operation, so protocol implementations must be able to handle this call while a load is in progress.
Subclasses must implement this method.
NSURLProtocol.h
© 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-04-01)