Sun ONE Application Server 7 Developer's Guide to NSAPI |
Appendix E
HyperText Transfer ProtocolThe HyperText Transfer Protocol (HTTP) is a protocol (a set of rules that describes how information is exchanged) that allows a client (such as a web browser) and an application server to communicate with each other.
HTTP is based on a request/response model. The browser opens a connection to the server and sends a request to the server.
The server processes the request and generates a response which it sends to the browser. The server then closes the connection.
This appendix provides a short introduction to a few HTTP basics. For more information on HTTP, see the IETF home page at:
This appendix has the following sections:
ComplianceSun ONE Application Server 7 supports HTTP 1.1. Previous versions of the server supported HTTP 1.0. The server is conditionally compliant with the HTTP 1.1 proposed standard, as approved by the Internet Engineering Steering Group (IESG) and the Internet Engineering Task Force (IETF) HTTP working group.
For more information on the criteria for being conditionally compliant, see the Hypertext Transfer Protocol—HTTP/1.1 specification (RFC 2068) at:
http://www.ietf.org/rfc/rfc2068.txt?number=2068
RequestsA request from a browser to a server includes the following information:
Request Method, URI, and Protocol Version
A browser can request information using a number of methods. The commonly used methods include the following:
- GET—Requests the specified resource (such as a document or image)
- HEAD—Requests only the header information for the document
- POST—Requests that the server accept some data from the browser, such as form input for a CGI program
- PUT—Replaces the contents of a server’s document with data from the browser
Request Headers
The browser can send headers to the server. Most are optional.
The following table shows commonly used request headers. The left column lists request headers, and the right column lists descriptions of those headers.
Request Data
If the browser has made a POST or PUT request, it sends data after the blank line following the request headers. If the browser sends a GET or HEAD request, there is no data to send.
ResponsesThe server’s response includes the following:
HTTP Protocol Version, Status Code, and Reason Phrase
The server sends back a status code, which is a three-digit numeric code. The five categories of status codes are:
The following table shows commonly used HTTP status codes. The left column lists status codes, and the right column lists descriptions of those codes.
Response Headers
The response headers contain information about the server and the response data.
The following table shows commonly used response headers. The left column lists response headers, and the right column lists descriptions of those headers.
.
Response Data
The server sends a blank line after the last header. It then sends the response data such as an image or an HTML page.
Buffered StreamsBuffered streams improve the efficiency of network I/O (for example the exchange of HTTP requests and responses) especially for dynamic content generation. Buffered streams are implemented as transparent NSPR I/O layers, which means even existing NSAPI plugins can use them without any change.
The buffered streams layer adds following features to the Sun ONE Application Server:
- Enhanced keep-alive support: When the response is smaller than the buffer size, the buffering layer generates the content-length header so that client can detect the end of the response and re-use the connection for subsequent requests.
- Response length determination: If the buffering layer cannot determine the length of the response, it uses HTTP 1.1 chunked encoding instead of the content-length header to convey the delineation information. If the client only understands HTTP 1.0, the server must close the connection to indicate the end of the response.
- Deferred header writing: Response headers are written out as late as possible to give the servlets a chance to generate their own headers (for example, the session management header set-cookie).
- Ability to understand request entity bodies with chunked encoding: Though popular clients do not use chunked encoding for sending POST request data, this feature is mandatory for HTTP 1.1 compliance.
The improved connection handling and response length header generation provided by buffered streams also addresses the HTTP 1.1 protocol compliance issues where absence of the response length headers is regarded as a category 1 failure. In previous Enterprise Server versions it was the responsibility of the dynamic content generation programs to send the length headers. If a CGI script did not generate the content-length header, the server had to close the connection to indicate the end of the response, breaking the keep-alive mechanism. However, it is often very inconvenient to keep track of response length in CGI scripts or servlets, and as an application platform provider, the application server is expected to handle such low-level protocol issues.
Output buffering has been built in to the NSAPI functions that transmit data, such as net_write (see Chapter 6, "NSAPI Function Reference"). You can specify the following Service SAF parameters that affect stream buffering, which are described in detail in Chapter 2, "Predefined SAFs and the Request Handling Process".
The UseOutputStreamSize, ChunkedRequestBufferSize, and ChunkedRequestTimeout parameters also have the equivalent init.conf directives; see the Sun ONE Application Server Administrator’s Configuration File Reference. The obj.conf parameters override the init.conf directives.
Note
The UseOutputStreamSize parameter can be set to zero in the obj.conf file to disable output stream buffering. For the init.conf file, setting UseOutputStreamSize to zero has no effect.
To override the default behavior when invoking an SAF that uses one of the NSAPI functions net_read or netbuf_grab (see Chapter 6, "NSAPI Function Reference"), you can specify the value of the parameter in obj.conf, for example:
Service fn="my-service-saf" type=perf UseOutputStreamSize=8192