Six Plus One

Joe Gregorio

Previously I talked about the six different places there are to store information in an HTTP transaction. This is slightly misleading.

To review, the six places are:

  1. Request URI
  2. Request Headers
  3. Request Content
  4. Response Status Code
  5. Response Headers
  6. Response Content

This is slightly misleading because the URI is listed as a single storage location. This isn't the best characterization, as it really contains two different sets of information: the path, and the query parameters.

Now the path part of a URI usually corresponds to the directory structure on the server. But remember that the path structure of a server is completely controlled by that server and it need not corresponse to any file or directory strucure. While it is at times convenient to map it to a directory structure, this isn't required, and it is possible to pass path information to a CGI program. For example, if you do a GET on the following URL:

and there exists a program named in the cgi-bin directory then that program will be executed. The remaining path after the program is passed to the CGI program in the PATH_INFO environment variable. In contrast, if query parameters are passed in, they are passed to the CGI program via the QUERY_STRING environment variable.

For example, if this is the script

import os
print "Content-type: text/plain\n\n"
print "PATH_INFO = %s" % os.environ['PATH_INFO']
print "QUERY_STRING = %s" % os.environ['QUERY_STRING']

And it handles the GET for this URI:


It will display:

PATH_INFO = /reilly/12
QUERY_STRING = id=234454

Note how the piece of the path below has been stripped off and made available via PATH_INFO, while the query parameters are stored in the QUERY_STRING environment variable.

So HTTP, via the structure of a URI, gives you two distinct places to store information, one in the path and the second in the query parameters. This isn't even the full story, because if you are running Apache and have the ability to use .htaccess files you can use mod_rewrite and map URIs so that they appear as paths but show up in the CGI as query parameters, but we won't cover that now.

comments powered by Disqus