How exactly should scripts return a response?
Contributors:
- AFlavell flavell@mail.cern.ch
The easiest way of handling this is to use an appropriate CGI library or module for the script language that you use, e.g CGI.pm for Perl.
There are two distinct kinds of CGI script, the normal kind and the Non-Parsed Headers kind. How to distinguish between them is implementation-defined, so consult the documentation for the server that you use to discover which kind(s) it supports and how you tell the server which kind you want to use: with NCSA or Apache servers, NPH scripts are given names that begin with "nph-".
Normal (i.e non-NPH) scripts are easier to handle, but there may be unusual situations that can only be tackled by using NPH scripts. Familiarity with HTTP protocols is essential for successful use of the NPH scripts - that lies outside the scope of this FAQ.
The correct form of response from a CGI script is documented in the CGI specification. With normal, non-NPH, scripts, the CGI specification permits any of the common end-of-line conventions, so, for example in Perl you may use "\n" on any platform. It is the server's job to create the complete and correct HTTP protocol response on the basis of your CGI response.
In an NPH script you are required to produce correct HTTP protocol headers. The HTTP specification calls upon servers to use only CR+LF as the end-of-line representation (although it advises clients to be tolerant of other conventions), so it would seem advisable to use binary output mode, and to represent newline (for example in Perl) as "\015\012" on all platforms in this situation, to assure proper portability.
Do not confuse the CGI specification with the HTTP specification: the similarities are intentional, but can sometimes be misleading.
For authoritative specifications refer to the following documents (valid at the time of writing, Nov.1999). The original NCSA CGI specification,;the current draft RFC for CGI/1.1, presently at draft 3; and for HTTP specifications, HTTP/1.0: RFC1945 and HTTP/1.1: RFC2616, at any convenient RFC repository.
Previous | Table of Contents
Follow us on Twitter | Contact Us
Copyright 1994-2012 Boutell.Com, Inc. All Rights Reserved.