A WOResponse object represents an HTTP response that an application returns to a Web server to complete a cycle of the request-response loop. The composition of a response occurs during the third and final phase of this loop, a phase marked by the propagation of the appendToResponse:inContext: message through the objects of the application. The WOApplication object first sends this message, passing in a newly-created WOResponse object as an argument. WOElement objects, which represent the dynamic and static HTML elements on a page, respond to the message by appending their HTML representation to the content of the WOResponse object. WOApplication, WOSession, and WOComponent objects can also respond to the message by adding information to the WOResponse object.
A WOResponse has two major parts: HTML content and HTTP information. The content is what is displayed in a Web browser; it can include escaped HTML, which is HTML code shown "as is," uninterpreted. The other information encapsulated by a WOResponse object is in the handling the response. This HTTP data includes headers, status codes, and version string. See the HTTP specification or HTTP documentation for descriptions of these items.
As you might expect, the methods of the WOResponse class can be divided into two groups, those that add to a response's HTML content and those that read and set HTTP information. The former group consists of methods that escape HTML (appendContentHTMLAttributeValue: and appendContentHTMLString:) and those that don't. For images and other binary data, you can use the appendContentData:. You can obtain and set the entire content of the response with content and setContent:. The following example shows a sequence of "appendContent" messages that compose an HTTP "POST" message:
[aResponse appendContentString:@"<form method=\"POST\" action=\""]; [aResponse appendContentHTMLAttributeValue:[aContext url]]; [aResponse appendContentCharacter:'"']; [aResponse.appendContentString:@">"];
Most of the remaining WOResponse methods set and read the response's HTTP headers, the HTTP status code, and the HTTP version.
Content Encodings
You can set the string encoding used for the response content with setContentEncoding: and you find out what the current encoding is with contentEncoding. An integer represents the type of encoding. The following table lists these integer values along with their OPENSTEP string-constant names.
int Value | OPENSTEP Name | Notes |
---|---|---|
1 | NSASCIIStringEncoding | 0 through 127 |
2 | NSNEXTSTEPStringEncoding | |
3 | NSJapaneseEUCStringEncoding | |
4 | NSUTF8StringEncoding | |
5 | NSISOLatin1StringEncoding | default |
6 | NSSymbolStringEncoding | |
7 | NSNonLossyASCIIStringEncoding | 7-bit verbose ASCII to represent all unichars |
8 | NSShiftJISStringEncoding | |
9 | NSISOLatin2StringEncoding | |
10 | NSUnicodeStringEncoding | |
11 | NSWindowsCP1251StringEncoding | Cyrillic; same as AdobeStandardCyrillic |
12 | NSWindowsCP1252StringEncoding | Windows Latin1 |
13 | NSWindowsCP1253StringEncoding | Windows Greek |
14 | NSWindowsCP1254StringEncoding | Windows Turkish |
15 | NSWindowsCP1250StringEncoding | Windows Latin2 |
21 | NSISO2022JPStringEncoding | ISO 2022 Japanese encoding for electronic mail |
Appends length number of bytes pointed to by someBytes to the HTTP response.
Appends a single ASCII character (aChar) to the HTTP response.
Example:
// ... if (aFlag) [aResponse appendContentCharacter:'Y']; else [aResponse appendContentCharacter:'N'];
Appends a data-encapsulating object (dataObject) to the HTTP response.
Appends an HTML attribute value to the HTTP content after transforming the string aValue into an NSData object using the receiver's content encoding. Special HTML characters ("<", ">", "&", and double quote) are escaped so that the browser does not interpret them. In other words, the message
aResponse.appendContentHTMLAttribute("<B>");
would transform the argument to "&lt;B&gt;".
See Also: - setContentEncoding:
Appends an HTML string to the HTTP response after transforming the string aString into an NSData object using the receiver's content encoding. Special HTML characters ("<", ">", "&", and double quote) are escaped so that the browser does not interpret them. For example, "<P>" becomes "&ltP&gt".
See Also: - setContentEncoding:
Appends a string to the content of the HTTP response. The string is transformed into an NSData object using the receiver's content encoding. The special HTML characters "<", ">", "&", and double-quote are not escaped so the browser can interpret them as HTML.
Returns the HTML content of the receiver as an NSData object. An exception is raised if you attempt to get the content when all elements of the page have not had their chance to append HTML to the response. Thus you should invoke this method only in the application object's appendToResponse:inContext: method, and then only after super's appendToResponse:inContext: has been invoked. (For scripted applications, the appendToResponse:inContext: is implemented in Application.wos).
See Also: - setContent:, - setContentEncoding:
Returns an integer representing the encoding used for the response content. See Content Encodings in the class description for a mapped list of supported encodings and their Objective-C names. Usually, you will want the response encoding to be the same as that used by the submitting form on the client browser. In this case it is preferable to use WORequest's formValueEncoding:
NSStringEncoding theEncoding = [[aContext request] formValueEncoding];
The default string encoding is ISO Latin1.
See Also: - setContent:, - setContentEncoding:
Returns the HTTP header information identified by aKey. If there are multiple headers associated with the one key, only the first one is returned. Returns nil if there are no headers for the key.
See Also: - setHeader:forKey:
Returns an array of string keys associated with the receiver's HTTP headers. Returns nil if there are no headers. You could easily test to see if a header is included by doing something similar to this:
NSArray *hKeys = [aResponse headerKeys]; if ([hKeys containsObject:@"expires"]) { // do something }
See Also: - setHeaders:forKey:
Returns all HTTP headers identified by aKey.
See Also: - setHeaders:forKey:
Returns the version of HTTP used for the response (for example, "HTTP/1.0").
See Also: - setHTTPVersion:
Initializes a WOResponse instance. HTTP status is set to 200 (OK), client caching is enabled, and the default string encoding is made ISO Latin 1.
Sets the HTML content of the HTTP response to someData.
See Also: - content
Sets the encoding used for the content of the HTTP response. See Content Encodings in the class description for a mapped list of supported encodings and their Objective-C names. The default string encoding is ISO Latin1.
See Also: - contentEncoding
Sets the HTTP header aHeader in the receiver and associates, for retrieval, the HTTP key aKey with the header. This method is commonly used to set the type of content in a response, for example:
aResponse.setHeader("text/html", "content-type");
See Also: - headerForKey:
Sets the list of HTTP headers headerList in the receiver and associates, for retrieval, the HTTP key aKey with the list of header elements.
See Also: - headerKeys, - headersForKey:
Sets the version of HTTP used for the response (for example, "HTTP/1.0").
See Also: - httpVersion
Sets the HTTP status to anInt. Consult the HTTP specification or HTTP documentation for the significance of status integers.
See Also: - status
Sets a dictionary in the WOResponse object that, as a convenience, can contain any kind of information related to the current response. Objects further down the appendToResponse:inContext: message "chain" can retrieve this information using userInfo.
Returns an integer code representing the HTTP status. Consult the HTTP specification or HTTP documentation for the significance of these status codes. By default, the status is 200 ("OK" status).
See Also: - setStatus:
Returns a dictionary that, as a convenience, can contain any kind of information related to the current response. An object further "upstream" in the appendToResponse:inContext: message "chain" can set this dictionary in the Response object as a way to pass information to other objects.
See Also: - setUserInfo: