Declared in | OCFoundation/OCFResponse.h |
Base class | NSObject |
Guides | Request based ApplicationsRequest based Applications in Detail |
An OCFResponse
instance object represents an HTTP response. You usually create an instance of this class in response to an OCFRequest
.
A response consists of a header and a body. OCFResponse
offers convenient access to the header fields status, content type and cookies.
There is little reason to subclass OCFResponse
. If you do so, -initWithStatus:headers:body:cookies:
is the designated initializer.
-initWithStatus:headers:body:cookies:
-initWithStatus:headers:body:
-initWithProperties:
#OCFResponseAttributes
@headers
@status
@cookies
@body
Keys for the components of a response header.
const struct OCFResponseAttributes OCFResponseAttributes = {
.status = @"status",
.headers = @"headers",
.body = @"body",
}
Keys for the components status, header and body for the dictionary representation of an OCFResponse
instance.
The response body.
@property (copy, readonly) NSData *body
The body of the response as an instance of NSData
. The content length header field is automatically set.
The cookies set by the response.
@property (copy) NSArray *cookies
The property contains an instance of NSArray
containing instances of NSHTTPCookie
. The set cookies will be added to the HTTP response header, when it is send back to the client.
Header fields of the response.
@property (copy, readonly) NSDictionary *headers
A dictionary containing the header fields of the response as key-value pairs. The status line is not included.
The keys and the values has to be instances of NSString
.
The status of the response.
@property (assign, readonly) NSInteger status
The HTTP status code of the response as defined for HTTP and extensions. For further information refer to List of HTTP status codes on Wikipedia.
Returns an instance object initialized with the properties.
- (instancetype)initWithProperties:(NSDictionary *)properties
This method initializes an instance with the values stored in the passed dictionary. The dictionary can contain the keys OCFResponseAttributes.status
, OCFResponseAttributes.headers
, OCFResponseAttributes.body
.
The value for the key OCFResponseAttributes.status
has to be an instance of NSNumber
. If the key-value pair is missing, the status is 0.
The value for the key OCFResponseAttributes.headers
has to be a dictionary. If the key-value pair is missing, the method behaves as -initWithStatus:headers:body:
passing nil
for headers
.
The value for the key OCFResponseAttributes.body
has to be a instance of NSData
. If the key-value pair is missing, the method behaves as -initWithStatus:headers:body:
passing nil
for body
.
Returns an instance object initialized with status, header and body.
-(instancetype)initWithStatus:(NSInteger)status headers:(NSDictionary *)headers body:(NSData *)body
The receiver simply sends initWithStatus:headers:cookies:body:
to self, passing the received arguments and nil
for cookies.
Returns an instance object initialized with the passed arguments.
- (instancetype)initWithStatus:(NSInteger)status headers:(NSDictionary *)headers cookies:(NSArray *)cookies body:(NSData *)body
This method returns a complete header constructed from the passed arguments.
headers
and body
can nil
and will then be set to an empty dictionary resp. empty instance of NSData
.
Keys and values of the headers
dictionary has to be instances of NSString
.
The content-length header field will be calculated from the body.