Note that what the client eventually ends up with must not depend on what Instance Manipulations have been applied to the content of the server's response; given that the client can properly handle whatever IMs were applied.
A simple example of IM is compression (such as GZIP compression) -- the original content can be readily recovered by the client.
To clarify why IM should be considered as a distinct step in the process of fulfilling an http request, consider the following sequence:
In the context of SRE2003 -- steps 1 to 3 are handled by the filter.
In the context of SRE2003 -- the ETAG option of SRE_COMMAND can be used to automatically create an entity tag.
In the context of SRE2003 -- steps 5 is handled by an Instance Manipulation Module
In the context of SRE2003 -- on-the-fly GZIP compression as a transfer-encoding, and computation of Content-MD5 headers, are done in this step.
If range extraction were the only kind of IM available, it would be unneccessary to carefully define IM as a step within the process of fulfilling an http request. However, as mentioned above there are other kinds of IM (such as delta encoding). Given the possiblities that different kinds of instance manipulation that may become beneficial, SRE2003 implements IM through optional "IM Modules". These modules are "plugged into" SRE2003 at run-time -- hence they do not require any modification to the SRE2003 software. Moreover, they can be unplugged just as easily!
For example, SRE2003 comes with an eXtended Range module that supports a String based range extraction (as well as the standard byte based range extraction).
By default, SRE2003 supports standard range extraction, using a built-in IM module.In the next section we describe how to install an IM module. It's quite simple.
Given that the files, etc. comprising the desired IM module are where they should be, installing an IM module to SRE2003 simply requires modifying the IM_TYPES parameter in SRE2003.CFG. You can do this by hand, or with one of the on-line configuration tools.
IM_TYPES |
Syntax: IM_TYPES= im_name1 im_file1 , im_name2 im_file2 , .... where each (case insensitive) im_name1 & im_file1 pair are seperated by a comma: Example: |
That's it -- next time you start up SRE2003, the IM modules you specify in IM_TYPES will be available to SRE2003. The next step is to notify SRE2003 that you want to use one of them -- you can do this for all requests, or only for specific responses. That is, you can use one IM module for all requests, excepting requests for which you want to use a different one!
Note: | You can use listtypes=sre_value('IM_TYPES',,'SRESYS') to retrieve a listing of the
currently loaded IM modules. The syntax of listtypes will be: IM_name im_file , ... , IM_name IM_file |
---|
IM_DEFAULT |
Syntax: IM_DEFAULT= im_name
where the (case insensitive) im_name is one of the im_names specified in IM_TYPES,
IM_DEFAULT=DELTAS IM_DEFAULT=RANGE IM_DEFAULT=XRANGE IM_DEFAULT=0 |
IM option
of SRE_COMMAND |
Syntax: IM im_name where the (case insensitive) im_name is 0, RANGE, or one of the im_names specified in IM_TYPES, Reminder: If IM is not specified, the IM type specified in IM_DEFAULT is used Examples:
|
Warning: if the selected IM module is not available a 501 error response will be returned.
IM modules use several sources of information when deciding what to do:
IMINFO subcommand
of SRE_COMMAND |
Syntax: vv=sre_command('IMINFO [CLEAR| [PLACE] [READ] ',im_message) where one (or none) of the options may be used: Examples:bybbye=sre_command('IMINFO CLEAR') foo=sre_command('IMINFO ','Strings=Section+1 - Section+2') foo=sre_command('IMINFO PLACE ',' Strings=Section+1.5 - Section+1.8') Note: Each IMINFO invocation generates a new line of information -- yet this new line may contain CRLFs. Thus, it is up to the user of IMINFO to be sure to structure its usage in a manner that their IM module(s) can understand. We recommend that filter (or addon) authors use a "header" like format, with a varname: varvalue construct. Note that any IM module that is called will get the same extra information. |
As noted in the introduction, SRE2003 calls the IM module after recieving some contents from the filter. This contents may be encoded (it may have Content-Encoding applied). For example, it may have been compressed with GZIP. Although this may temper what IM should be done, the exact content-coding is more-or-less independent of the kinds of IM you can apply.
After checking some details (such as creating an ETAG, or checking for an If- condition), SRE2003 calls the IM module. The IM module will then:
len_file | 0 = fname is a variable >0 = fname is a filename, with size len_file |
fname | either contents of a variable, or a file name |
clientaddr | the clients ip address |
hostnick | the hostnickname to whom this request is addressed |
uri | the full request line WITHOUT url encoding |
ctype | the content-type (if explicitily specified) |
reqheaders | request headers, one per line, formatted as hdr_name: hdr_value
Note that if the client send multiple request headers with the same hdr_name, they will be concatenated onto one line (with commas seperating each new instance of the header). |
respheader | currently specified response headers. Same format as reqheaders |
extrainfo | The extra information specified in calls to SRE_COMMAND('IM ...) . Each message sent by (multiple calls) to SRE_COMMAND('IM ...) starts on a new line of extrainfo |
DEF opt_respheaders | This IM procedure is not applicable, so try the default (RANGE extraction). The opt_respheaders are optional response headers (see below for details on the structure of these response headers). | ||
0 | No change -- SRE2003 should use the contents as is.
Note that 0 is stronger then DEF -- it means this IM process was not applicable, and niether is the default (RANGE extraction) | ||
1 respline respheaders empty line modified_contents. | The respline should be a legitimate http response line. For example: HTTP/1.1 206 Partial Content ' The respheaders should consist of zero, one, or more response headers -- these will be added to, replace, or removed from already specified response headers. Note that an empty line signals the end of the response headers. Immediately following this empty line should be the modified contents (which can be arbitrarily long, and span multiple lines). This modified contents will be sent to the client as is (well, perhaps with on-the-fly GZIP as a transfer-encoding).
Note that each line of the respheaders should be structured like calls to SRE_COMMAND('HEADER ...').
|
Thus, when writing your IM module code, be sure to check for a value of !INIT in the first (the LEN_FILE argument). When you see it, you can then use the 2nd argument (the fname parameter) as the fully-qualified name of this file. Your IM procedure should should perform any first-time initializations it may require (such as checking for the existence of working directories and databases, or launching tasks). Upon successful initialization, your IM procedure must return a 1 -- any other return is interpreted as an error, and will cause SRE2003 to immediately shutdown.
NOTICE: | You can not use any SRE2003 procedure that provides
request specific values.
For example, do NOT use: If you use these verboten procedures -- you will hang the thread. To kill this thread, you'll either have to SNIPE the thread, or shutdown SRE2003. Note that the thread is transaction specific, so other transactions should proceed normally.
|
XRANGE is an extension of standard http/1.1 range extraction.
It's major difference is that it recognizes a Range: option of:
strings=string1 - string2
or, for multiple ranges:strings=string1 - string2, string1a- string2a , ...
as well the traditional
bytes=n1-n2
Each string should be a URL-encoded case-sensitive string. In particular, it must not contain spaces, hyphens, or characters not permitted in URIs. Instead, use URL-encoding pf hypens, etc. (and use + for spaces).
XRANGE searches for these strings in the contents provided by SRE2003. It will convert these to byte ranges, returning the (inclusive) range of the contents between the first occurences of these two strings (with the second string in a hyphenated pair always assumed to be after the first string of the pair).
Curious programmers are invited to examine XRANGE.RXX (in BIN\IM). Not only does it illustrate how to code an IM module, it contains a few useful procedures for "unpacking" the request and response headers.