Objective-C in the Cloud

OCFResponse Class Reference

Declared inOCFoundation/OCFResponse.h
Base classNSObject
GuidesRequest based Applications
Request based Applications in Detail

Overview

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.

Tasks

Creating a Response

-initWithStatus:headers:body:cookies:
-initWithStatus:headers:body:
-initWithProperties:
#OCFResponseAttributes

Parts

@headers
@status
@cookies
@body

Constants

OCFResponseAttributes

Keys for the components of a response header.

const struct OCFResponseAttributes OCFResponseAttributes = { .status = @"status", .headers = @"headers", .body = @"body", }

Discussion

Keys for the components status, header and body for the dictionary representation of an OCFResponse instance.

Declared Properties

body

The response body.

@property (copy, readonly) NSData *body

Discussion

The body of the response as an instance of NSData. The content length header field is automatically set.

cookies

The cookies set by the response.

@property (copy) NSArray *cookies

Discussion

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.

headers

Header fields of the response.

@property (copy, readonly) NSDictionary *headers

Discussion

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.

status

The status of the response.

@property (assign, readonly) NSInteger status

Discussion

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.

Instance Methods

initWithProperties:

Returns an instance object initialized with the properties.

- (instancetype)initWithProperties:(NSDictionary *)properties

Parameters

properties
A dictionary with one key-value pair for status, header and body each.

Discussion

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.

initWithStatus:headers:body:

Returns an instance object initialized with status, header and body.

-(instancetype)initWithStatus:(NSInteger)status headers:(NSDictionary *)headers body:(NSData *)body

Parameters

status
The HTTP status of the response.
headers
The HTTP header fields of the response.
body
The content of the response.

Discussion

The receiver simply sends initWithStatus:headers:cookies:body: to self, passing the received arguments and nilfor cookies.

initWithStatus:headers:cookies:body:

Returns an instance object initialized with the passed arguments.

- (instancetype)initWithStatus:(NSInteger)status headers:(NSDictionary *)headers cookies:(NSArray *)cookies body:(NSData *)body

Parameters

status
The HTTP status of the response.
headers
The HTTP header fields of the response.
cookies
An array containing instances of `NSHTTPCookie`.
body
The content of the response.

Discussion

This method returns a complete header constructed from the passed arguments.

headers and body can niland 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.