home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

HTML 4.0 Sourcebook
(Publisher: John Wiley & Sons, Inc.)
Author(s): Ian S. Graham
ISBN: 0471257249
Publication Date: 04/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


Such fields tell the browser that the downloaded data is an attached file and that it should be assigned the indicated filename. For example, the message:

content-type: application/x-gzip
content-length: 1232123
content-disposition: attachment; filename=archive.gz

tells the browser that the downloaded file (a GZIP archive) has the name archive.gz. Since Netscape cannot view this type of file, it will prompt the user to save the file and will offer to save it under the name archive.gz.

If the content-disposition field is not present, the browser generally uses the last part of the URL (minus the query string) as the default filename, which in this case would likely be the name of the program that generated the response.

This is a convenient way to use a single CGI program for downloading a variety of stored archive files. However, there is an important caveat—the content-disposition header field is only understood by Netscape Navigator, and is not understood by Internet Explorer.

Example 22: Environment Variables

The preceding examples would imply that the server passes very little information to a gateway program. In fact, the server is not so ungenerous. Before launching a gateway program, the server initializes several environment variables that are subsequently accessible to the gateway. In particular, this mechanism passes any extra path and query string information to a gateway program. Table 10.2 lists the environment variables defined as part of the CGI standard, while Figures 10.7 and 10.8 illustrate the most common variables in an example application. Figure 10.7 shows the gateway script srch-example-2; this is the same ISINDEX script listed in Figure 10.2, modified to print out environment variable contents. The HTML document generated upon accessing this script at the URL

<http://leonardo.utirc.utoronto.ca:8080/cgi-bin/srch-example-
2/dir/file?ian+bradley>

is shown in Figure 10.8. Accessing this URL passes both query string (ian+bradley) and extra path information (/dir/file) to the referenced gateway program.

Most of the environment variables in Figure 10.8 are easy to understand. Some are set by default and do not depend on the nature of the request, while others are set only when particular client-server-gateway interactions are involved.

Standard Environment Variables

Table 10.2 lists the standard environment variables that are passed to a gateway program by an HTTP server. Not all variables are defined in all cases; for example, the variables associated with user authentication are only defined when authentication is being used.

Request Header–Based Environment Variables

As noted in Table 10.2, every piece of information in the HTTP request header (the headers sent from the client to the server) not contained within a standard CGI environment variable is passed to the gateway program within an environment variable of the form HTTP_ NAME, where NAME is related to the name of the request header fields. These environment variable names are constructed by:

1.  capitalizing the name in the request header field (e.g., User-agent to USER-AGENT)
2.  converting dash (-) characters into underscores (_) (e.g., USER-AGENT to USER_AGENT)
3.  adding the prefix HTTP_ (e.g., USER_AGENT to HTTP_USER_AGENT)


Figure 10.7 Bourne-shell script srch-example-2. This is essentially the same script shown in Figure 10.2, but modified to explicitly print out the environment variables and the command-line arguments.

#!/bin/sh
echo Content-TYPE:  text/html
echo
 if [ $# = 0 ]   # is the number of arguments == 0 ?
then             # do this part if there are NO arguments
      echo “<HEAD>”
      echo “<TITLE>Local Phonebook Search</TITLE>”
      echo “<ISINDEX>”
      echo “</HEAD>”
      echo “<BODY>”
      echo “<H1>Local Phonebook Search</H1>”
      echo “Enter your search in the search field.<P>”
      echo “This is a case-insensitive substring search: thus”
      echo “searching for ‘ian’ will find ‘Ian’ and Adriana’.”
      echo “</BODY>”
else             # this part if there ARE arguments
      echo “<HEAD>”
      echo “<TITLE>Result of search for \”$*\“.</TITLE>”
      echo “</HEAD>”
      echo “<BODY>”
      echo “<P> Number of Command-line Arguments = $#.   They are:”
      for i in $*
      do
            echo “ <code> $i </code> ”
      done
      echo “<h2> The Environment Variables </h2>”
      echo “<pre>”     # print the environment variables
      echo “ SERVER_SOFTWARE = $SERVER_SOFTWARE”
      echo “ SERVER_NAME = $SERVER_NAME”
      echo “ GATEWAY_INTERFACE = $GATEWAY_INTERFACE”
      echo “ SERVER_PROTOCOL = $SERVER_PROTOCOL”
      echo “ SERVER_PORT = $SERVER_PORT”
      echo “ REQUEST_METHOD = $REQUEST_METHOD”
      echo “ HTTP_ACCEPT = $HTTP_ACCEPT”
      echo “ PATH_INFO = $PATH_INFO”
      echo “ PATH_TRANSLATED = $PATH_TRANSLATED”

      echo “ SCRIPT_NAME = $SCRIPT_NAME”
      echo “ QUERY_STRING = $QUERY_STRING”
      echo “ REMOTE_HOST = $REMOTE_HOST”
      echo “ REMOTE_ADDR = $REMOTE_ADDR”
      echo “ REMOTE_USER = $REMOTE_USER”
      echo “ AUTH_TYPE = $AUTH_TYPE”
      echo “ CONTENT_TYPE = $CONTENT_TYPE”
      echo “ CONTENT_LENGTH = $CONTENT_LENGTH”
      echo “</pre>”
      echo “<H2>Result of search for \”$*\“.</H2>”
      echo “<PRE>”
      for i in $*
      do
          grep -i $i /vast/igraham/Personnel
      done
      echo “</PRE>”
      echo “</BODY>”
fi


Figure 10.8  Document returned from the script in Figure 10.7 after accessing the URL.

<http://leonardo.utirc.utoronto.ca:8080/cgi-bin/srch-example->


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.