Class: NSURLProtocol

Inherits:
NSObject show all

Overview

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.

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from NSObject

#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version

Constructor Details

This class inherits a constructor from NSObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class NSObject

Class Method Details

+ (Boolean) canInitWithRequest(request)

Returns whether the protocol subclass can handle the specified request. 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.

Parameters:

Returns:

  • (Boolean)

    YES if the protocol subclass can handle request, otherwise NO.

+ (NSURLRequest) canonicalRequestForRequest(request)

Returns a canonical version of the specified 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.

Parameters:

  • request (NSURLRequest)

    The request whose canonical version is desired.

Returns:

+ (Object) propertyForKey(key, inRequest:request)

Returns the property associated with the specified key in the specified request. This method provides an interface for protocol implementors to access protocol-specific information associated with NSURLRequest objects.

Parameters:

  • key (String)

    The key of the desired property.

  • request (NSURLRequest)

    The request whose properties are to be queried.

Returns:

  • (Object)

    The property associated with key, or nil if no property has been stored for key.

+ (Boolean) registerClass(protocolClass)

Attempts to register a subclass of NSURLProtocol, making it visible to the URL loading system. 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:.

Parameters:

Returns:

  • (Boolean)

    YES if the registration is successful, NO otherwise. The only failure condition is if protocolClass is not a subclass of NSURLProtocol.

+ (Object) removePropertyForKey(key, inRequest:request)

Removes the property associated with the specified key in the specified request. This method is used to provide an interface for protocol implementors to customize protocol-specific information associated with NSMutableURLRequest objects.

Parameters:

  • key (String)

    The key whose value should be removed.

  • request (NSMutableURLRequest)

    The request from which to remove the property value.

Returns:

+ (Boolean) requestIsCacheEquivalent(aRequest, toRequest:bRequest)

Returns whether two requests are equivalent for cache purposes. 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.

Parameters:

  • aRequest (NSURLRequest)

    The request to compare with bRequest.

  • bRequest (NSURLRequest)

    The request to compare with aRequest.

Returns:

  • (Boolean)

    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.

+ (Object) setProperty(value, forKey:key, inRequest:request)

Sets the property associated with the specified key in the specified request. This method is used to provide an interface for protocol implementors to customize protocol-specific information associated with NSMutableURLRequest objects.

Parameters:

  • value (Object)

    The value to set for the specified property.

  • key (String)

    The key for the specified property.

  • request (NSMutableURLRequest)

    The request for which to create the property.

Returns:

+ (Object) unregisterClass(protocolClass)

Unregisters the specified subclass of NSURLProtocol. After this method is invoked, protocolClass is no longer consulted by the URL loading system.

Parameters:

Returns:

Instance Method Details

- (NSCachedURLResponse) cachedResponse

Returns the receiver’s cached response. If not overridden in a subclass, this method returns the cached response stored at initialization time.

Returns:

- (Object) client

Returns the object the receiver uses to communicate with the URL loading system.

Returns:

  • (Object)

    The object the receiver uses to communicate with the URL loading system.

- (Object) initWithRequest(request, cachedResponse:cachedResponse, client:client)

Initializes an NSURLProtocol object. 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.

Parameters:

  • request (NSURLRequest)

    The URL request for the URL protocol object. This request is retained.

  • cachedResponse (NSCachedURLResponse)

    A cached response for the request; may be nil if there is no existing cached response for the request.

  • client (Object)

    An object that provides an implementation of the NSURLProtocolClient protocol that the receiver uses to communicate with the URL loading system. This client object is retained.

Returns:

- (NSURLRequest) request

Returns the receiver’s request.

Returns:

- (Object) startLoading

Starts protocol-specific loading of the request. 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.

Returns:

- (Object) stopLoading

Stops protocol-specific loading of the request. 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. When your protocol receives a call to this method, it should also stop sending notifications to the client.Subclasses must implement this method.

Returns: