Class: NSHTTPCookie

Inherits:
NSObject show all

Overview

An NSHTTPCookie object represents an HTTP cookie. It’s an immutable object initialized from a dictionary containing the cookie attributes.

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

+ (Array) cookiesWithResponseHeaderFields(headerFields, forURL:theURL)

Returns an array of NSHTTPCookie objects corresponding to the provided response header fields for the provided URL. This method ignores irrelevant header fields in headerFields, allowing dictionaries to contain additional data.If headerFields does not specify a domain for a given cookie, the cookie is created with a default domain value of theURL.If headerFields does not specify a path for a given cookie, the cookie is created with a default path value of “/”.

Parameters:

  • headerFields (Hash)

    The header fields used to create the NSHTTPCookie objects.

  • theURL (NSURL)

    The URL associated with the created cookies.

Returns:

  • (Array)

    The array of created cookies.

+ (Object) cookieWithProperties(properties)

Creates and initializes an NSHTTPCookie object using the provided properties. See “Constants” for more information on the available header field constants and the constraints imposed on the values in the dictionary.

Parameters:

  • properties (Hash)

    The properties for the new cookie object, expressed as key value pairs.

Returns:

  • (Object)

    The newly created cookie object. Returns nil if the provided properties are invalid.

+ (Hash) requestHeaderFieldsWithCookies(cookies)

Returns a dictionary of header fields corresponding to a provided array of cookies. See “Constants” for details on the header field keys and values in the returned dictionary.

Parameters:

  • cookies (Array)

    The cookies from which the header fields are created.

Returns:

  • (Hash)

    The dictionary of header fields created from the provided cookies. This dictionary can be used to add cookies to a request.

Instance Method Details

- (String) comment

Returns the receiver's comment string.

Returns:

  • (String)

    The receiver’s comment string or nil if the cookie has no comment. This string is suitable for presentation to the user, explaining the contents and purpose of this cookie.

- (NSURL) commentURL

Returns the receiver’s comment URL.

Returns:

  • (NSURL)

    The receiver’s comment URL or nil if the cookie has none. This value specifies a URL which is suitable for presentation to the user as a link for further information about this cookie.

- (String) domain

Returns the domain of the receiver’s cookie. If the domain does not start with a dot, then the cookie is only sent to the exact host specified by the domain. If the domain does start with a dot, then the cookie is sent to other hosts in that domain as well, subject to certain restrictions. See RFC 2965 for more detail.

Returns:

  • (String)

    The domain of the receiver’s cookie.

- (NSDate) expiresDate

Returns the receiver’s expiration date.

Returns:

  • (NSDate)

    The receiver’s expiration date, or nil if there is no specific expiration date such as in the case of “session-only” cookies. The expiration date is the date when the cookie should be deleted.

- (Object) initWithProperties(properties)

Returns an initialized NSHTTPCookie object using the provided properties. See “Constants” for more information on the available header field constants and the constraints imposed on the values in the dictionary.

Parameters:

  • properties (Hash)

    The properties for the new cookie object, expressed as key value pairs.

Returns:

  • (Object)

    The initialized cookie object. Returns nil if the provided properties are invalid.

- (Boolean) isHTTPOnly

Returns whether the receiver should only be sent to HTTP servers per RFC 2965. Cookies may be marked as HTTP only by a server (or by a javascript). Cookies marked as such must only be sent via HTTP Headers in HTTP requests for URL’s that match both the path and domain of the respective cookies. Important: Cookies specified as HTTP only should not be delivered to any javascript applications to prevent cross-site scripting vulnerabilities.

Returns:

  • (Boolean)

    Returns YES if this cookie should only be sent via HTTP headers, NO otherwise.

- (Boolean) isSecure

Returns whether his cookie should only be sent over secure channels.

Returns:

  • (Boolean)

    YES if this cookie should only be sent over secure channels, otherwise NO.

- (Boolean) isSessionOnly

Returns whether the receiver should be discarded at the end of the session (regardless of expiration date).

Returns:

  • (Boolean)

    YES if the receiver should be discarded at the end of the session (regardless of expiration date), otherwise NO.

- (String) name

Returns the receiver’s name.

Returns:

  • (String)

    The receiver’s name.

- (String) path

Returns the receiver’s path. The cookie will be sent with requests for this path in the cookie’s domain, and all paths that have this prefix. A path of “/” means the cookie will be sent for all URLs in the domain.

Returns:

  • (String)

    The receiver’s path.

- (Array) portList

Returns the receiver's port list.

Returns:

  • (Array)

    The list of ports for the cookie, returned as an array of NSNumber objects containing integers. If the cookie has no port list this method returns nil and the cookie will be sent to any port. Otherwise, the cookie is only sent to ports specified in the port list.

- (Hash) properties

Returns the receiver’s cookie properties. This dictionary can be used with initWithProperties: or cookieWithProperties: to create an equivalent NSHTTPCookie object.See initWithProperties: for more information on the constraints imposed on the properties dictionary.

Returns:

  • (Hash)

    A dictionary representation of the receiver’s cookie properties.

- (String) value

Returns the receiver’s value.

Returns:

  • (String)

    The receiver’s value.

- (Integer) version

Returns the receiver’s version.

Returns:

  • (Integer)

    The receiver’s version. Version 0 maps to “old-style” Netscape cookies. Version 1 maps to RFC 2965 cookies.