Lecture Notes for Client-Server Interfaces
29 March 2001 - The Common Gateway Interface (CGI)
- a uri can refer to any resource on a server's host - not just files
- databases, devices, running programs, . . .
- how does the server know about them
- how does the server deal with them
- cuts into server portability, simplicity
- responsibility for non-file uris is handled off to the server's host
- a program acts as an intermediary between the server and the host
- the common gateway interface (cgi) describes how the intermediary and
server interact
- interaction between the intermediary and the host is left up to the
parties involved.
- the intermediary can be any program that conforms to the cgi
- basic interaction between the intermediary (or gateway) and the server
- the server sends information to the gateway via environment variables,
command-line arguments, and std-in.
- the gateway sends information to the server via std-out
- environment variables
- name-value pairs stored in a program's operating environment
- accessed via
$name
notation in shells or via getenv("name")
calls in programs
- some environment variables are set by the server - GATEWAY_INTERFACE
- some are extracted from the request - QUERY_STRING, REQUEST_METHOD
- some are copied from the request - HTTP_ACCEPT, CONTENT_LENGTH,
CONTENT_TYPE
- command-line arguments - obscure and not often used
- std-in input - used in the post method
- request prefix must contain a Content-Length: header - Content-Type:
is not necessary but useful
- data appears after the blank line ending the request prefix
- the server puts the content length in the CONTENT_LENGTH environment
variable
- the data appear at the gateway's std-in - not necessarily ending in
a newline
- gateway std-out to the server
- the server reads the gateway's output and ships if off to the client
- the gateway starts with a mini-prefix describing the content type,
followed by a blank line, followed by the content
- the server creates a full response from the gateway's output
- the gateway can also redirect and indicate status
- that's pretty much it for the cgi
- cgi programming is dangerous because it relies on arbirary other data
from arbitrary other clients
- data-transmission details
- the post method
- get method
- extra information can be placed in a get uri
- GET uri?data HTTP/1.0
- the data is arbitrary, but cannot contain any white space
- the url encoding of
+
for space and %xx characters
- the data shows up in the query_string environment variable
- Content-Type: application/x-www-form-urlencoded
- header lines
- attribute-value pairs may appear after the media type in a
Content-Type: header line
This page last modified on 3 April 2001.