Daylight v4.9
Release Date: 1 February 2008

Object Synopsis

transfer -- HTTP transfer object

Description

A TRANSFER object represents a request and response for a HTTP client. A TRANSFER object is created with dt_http_get(3) when there is a request from a client (e.g., a browser) is received by a server (a HTTP object). For each request, a new TRANSFER object is created for handling the response. In conjunction with the HTTP object, the TRANSFER object encapsulates receiving a request and sending a response via HTTP.

Responses feature a status code, e.g., 200 (meaning okay), 404 (meaning not found), etc. For successful requests, i.e., code 200, data is also returned from server to client in formats which are identified by a MIME type, e.g., ASCII (text/plain), HTML (text/html), GIF (image/gif), PostScript (application/postscript), CEX (chemical/x-cex), etc.

Operation of TRANSFER objects are controlled via named properties which are set via dt_sethandle(3), dt_setinteger(3), dt_setstring(3) and dt_appendstring(3). Names for system-defined properties start with "htt_" and are listed below. The only property which is absolutely required is "htt_code" which is initially set to `404' when a TRANSFER object is returned from dt_http_get(3). All other properties have sensible defaults, so a call to dt_http_put(3) will result in a valid response.

READ-ONLY PROPERTIES

htt_agent

The information about the software used to make the request, e.g., "Mozilla/4.78 [en] (X11; U; Linux 2.4.7-10 i686)"

htt_authorize

The username & password used to authorize a request.

htt_from

The email address of the user.

htt_method

The request method, e.g., "GET", "HEAD", or "POST". Other values include "PUT", "DELETE", "LINK", and "UNLINK".

htt_method_id

The request method identifier of the request. Valid values for this property are:

DX_HTT_METHOD_HEAD means the request method is HEAD.

DX_HTT_METHOD_GET means the request method is GET.

DX_HTT_METHOD_POST means the request method is POST.

DX_HTT_METHOD_NONE means the request method is none of the above implemented methods. In this case, the request method can be determined using the htt_method property.

htt_path

The request URI or path, e.g., "http://www.daylight.com" or "/".

htt_post

Contains the request posts field/value pairs and is stored as a handle to a sequence of string objects. Each string object represents one header line from the request. The header field name is the string value of the string object and the header field value is the value of the "htt_value" property of the string object. There's an example on how to get a POST value below.

htt_protocol

The request protocol and version, e.g., "HTTP/1.0" or "HTTP/1.1".

htt_recv_

The property name prefix for receiving unimplemented request headers, and thus have no predefined property name. For such headers, this prefix is is concatinated with the header name to construct a property to store the header value. For example, the "Cookie" header is not implemented, so when a "Cookie" header is received, the htt_recv_Cookie> property will contain the "Cookie" header value. In this way, the toolkit can support any request header information. For information of cookies, see RFC 2965 at http://www.ietf.org/rfc/rfc2965.txt.

htt_referer

The URI of the referring resource.

htt_rips

The IP address of the remote host as viewed from the server using the accept(3socket) system call. The service is a CGI, the REMOTE_ADDR environment variable is used.

htt_since

The date upon which the request is conditional. The format is the same as the htt_date property. If the resource is older than this date, the resource is not requested.

The following source code shows how to get the value of the POST field named "smiles":

Example Source Code: Get POST Data

/* du_http_post - return the string object of a POST named property
**               return NULL_OB if the name is not found
*/
dt_Handle du_http_post(dt_Handle xfer, dt_Integer plen, dt_String pname) {
dt_Handle sequence, string;
dt_String propname;

/* get property */ sequence = dt_handle(xfer, 8, "htt_post");

/* loop over sequence, get strings */ while (NULL_OB != (string = dt_next(sequence))) { /* get propname */ propname = dt_stringvalue(&plen, string); /* check for match */ if (0 == strncmp(propname, pname, plen)) /* return string value */ return string; }

/* not found */ return NULL_OB; }

READ-WRITE PROPERTIES

htt_authenticate

The challenge for a client to authenticate itself and is used with status code 401. If this property is not set with status code 401, the toolkit will override the response with "500 Internal Server Error". When this property is not NULL, the value is used with the "WWW-Authenticate" header field.

htt_code

The response status code and is initialized to 404 (Not Found) when an object is returned from dt_http_get(3). This property should be set to 200 for response that are "OK".

htt_content

The content of the response. This property is the body of the response and is used to send program data from the server to the client. When this property is not NULL, the length in bytes of the content is used with the "Content-Length" header field.

htt_date

The response date & time, e.g., Mon, 02 Dec 2002 07:40:03 GMT. The format conforms to <A HREF=http://www.ietf.org/rfc/rfc822.txt>RFC 822</A> & <A HREF=http://www.ietf.org/rfc/rfc1123.txt>RFC1123</A>. When this property is NULL, it will be set by the toolkit in dt_http_put(3). This value is used with the "Date" header field.

htt_encoding

The encoding or compression performed on the content, e.g., base64 or gzip. When this property is not NULL, the value is used with the "Content-Encoding" header field.

htt_expires

The date & time the resource expires, e.g., Mon, 02 Dec 2002 07:40:03 GMT. The format conforms to <A HREF=http://www.ietf.org/rfc/rfc822.txt>RFC 822</A> & <A HREF=http://www.ietf.org/rfc/rfc1123.txt>RFC1123</A>. This value is used by caches and proxies to store and server responses until it expires. When this property is not NULL, the value is used with the "Expires" header field.

htt_location

The absolute URI for redirecting a request for a resource and is used with status codes 301 and 302. If this property is not set with status codes 301 and 302, the toolkit will override the response with "500 Internal Server Error". When this property is not NULL, the value is used with the "Location" header field.

htt_method_id

A bitwise OR of request method identifiers that are implemented by the service for the response content. When this property is not NULL, the value is used with the "Allow" header field. Valid values for this property are:

DX_HTT_METHOD_HEAD means the service implements the request method HEAD.

DX_HTT_METHOD_GET means the service implements the request method GET.

DX_HTT_METHOD_POST means the service implements the request method POST.

DX_HTT_METHOD_ALL is a bitwise OR of all of the above method identifiers.

DX_HTT_METHOD_ANY suppress sending the "Allow" header field.

htt_mime_type

The MIME type of the content, for example "text/html" or "image/gif", and is initialized to "text/html" when a TRANSFER object is returned from dt_http_get(3). The syntax conforms to RFC 1521 "<I>MIME (Multipurpose Internet Mail Extensions)</I>" avavilable at <A HREF=http://www.ietf.org/rfc/rfc1521.txt>http://www.ietf.org/rfc/rfc1521.txt</A>. When this property is not NULL, the value is used with the "Content-Type" header field.

htt_modified

The date & time the resource was last modified. When this property is not NULL, the value is used with the "Last-Modified" header field.

htt_pragma

The response implementation-specific directives that may apply to any recipient along the request/response chain. All pragma directives specify optional behavior from the viewpoint of the protocol; however, some systems may require that behavior be consistent with the directives.

htt_send_

The property name prefix for sending unimplemented response headers, and thus have no predefined property name. For such headers, this prefix should be concatinated with the header name to construct a property to store the header value. For example, the "Set-Cookie" header is not implemented, so when a "Set-Cookie" header should be sent, the programmer should set the htt_send_Set-Cookie property to contain the "Set-Cookie" header value. In this way, the toolkit can support any response header information. For information of cookies, see <A HREF=http://www.ietf.org/rfc/rfc2965.txt>RFC 2965</A>.

htt_service

The identifier of the service and is set when an object is returned from dt_http_get(3). This property is a free-form string and is set to the toolkit software version, e.g., "Daylight/4.81". When this property is not NULL, the value is used with the "Server" header field.

htt_version

The response protocol and version and is set when an object is returned from dt_http_get(3). The value is initialized to match the request protocol and version (htt_protocol property). So, HTTP/0.9 requests are sent HTTP/0.9 responses (no headers) and HTTP/1.0 requests are sent HTTP/1.0 responses (with headers). Requests that are received using HTTP/1.1 and higher will result in this property being initialized to "HTTP/1.0" within the call to dt_http_get(3). In order to respond to any other request protocol, the programmers must set this property (e.g., to "HTTP/1.1") and add appropiate headers using the htt_send_ property prefix prior to calling dt_http_put(3).

HTML Presentation

htm_autohtml

The HTML auto-generation flag. When this property is zero, all of the following properties are ignored.

htm_body_tag

The body tag. When this property is NULL, no BODY tag will be used unless one or both of htm_background or htm_bgcolor properties are non-NULL. An example of this property is:

<BODY BACKGROUND=sunlogo-gray.gif BGCOLOR=e0e0e0>

htm_body_bg_color

The body tag background color parameter. When this property is NULL, no BGCOLOR parameter will be used within a BODY tag unless specified in the htm_body> property, which overrides this property. An example of this property is:

e0e0e0

htm_body_bg_image

The body tag background parameter. When this property is NULL, no BACKGROUND parameter will be used within a BODY tag unless specified in the htm_body property, which overrides this property. An example of this property is:

sunlogo-gray.gif

htm_doctype_tag

The document tag. When this property is NULL, the following value is used:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 1.1//EN">

htm_head_tag

The head tag. When this property is NULL, no HEAD tag will be used unless any of htm_title, htm_script, or htm_style properties are non-NULL. An example of this property is:

<BR><TITLE>Auto-HTML Format Demo</TITLE>
<BR><SCRIPT LANGUAGE=JavaScript SRC=/application/x-javascript/loadJavaGrins.js></SCRIPT>
<BR><STYLE TYPE=text/css></STYLE>
<BR></HEAD>

htm_head_title

The title tag. When this property is NULL, no TITLE tag will be used unless specified in the htm_head property, which overrides this property. An example of this property is:

<TITLE>Auto-HTML Format Demo</TITLE>

htm_head_script

The script tag. When this property is NULL, no SCRIPT tag will be used unless specified in the htm_head property, which overrides this property. An example of this property is:

<SCRIPT LANGUAGE=JavaScript SRC=/application/x-javascript/loadJavaGrins.js></SCRIPT>

htm_head_style

The style tag. When this property is NULL, no STYLE will be used unless specified in the htm_head property, which overrides this property. An example of this property is:

<STYLE TYPE=text/css></STYLE>

htm_prefix

The content that prefixes the htt_content property in the response. This is useful for specifying a banner at the top of each page. An example of the property is:

<TABLE BORDER CELLSPACING CELLPADDING=4 WIDTH=100%%><TR>
<BR><TD ALIGN=CENTER WIDTH=100%%><A HREF=/>Auto-HTML Format Demo</A>
<BR></TABLE>

htm_postfix

The content that postfixes the htt_content property in the response. This is useful for specifying a banner at the bottom of each page. An example of the property is:

<TABLE BORDER CELLSPACING CELLPADDING=4 WIDTH=100%%><TR>
<BR><TD ALIGN=CENTER><A HREF=mailto:info@daylight.com>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;info@daylight.com</A>
<BR><TD ALIGN=CENTER VALIGN=MIDDLE WIDTH=100%%>
<BR>&nbsp;&nbsp;<A HREF=http://www.daylight.com>
<BR>&nbsp;&nbsp;Daylight Chemical Information Systems, Inc.</A>
<BR><TD ALIGN=CENTER VALIGN=MIDDLE><I>Daylight<BR>HTTP Toolkit</I>
<BR></TABLE>

Manipulation of the above properties makes it very convenient to respond to HTTP requests, especially to GET requests. POST requests are similar, but the htt_post sequence must be examined to obtain POSTed data, e.g., from a FORM. See the Daylight HTTP Toolkit Programmers Manual for more information and the $DY_ROOT/contrib/src/c/http/ directory for example code usage.

Related Topics

http(3ob)

dt_http_get(3) dt_http_put(3)