[cs631apue] About CGI Response Headers.

Jan Schaumann jschauma at stevens.edu
Tue Dec 11 22:14:33 EST 2012

byu1 <byu1 at stevens.edu> wrote:

> For the CGI Response, what kind of headers should we return? Are they  
> the same as GET/HEAD, such as  
> Date/Server/Last-Modified/Content-Type/Content-Length?

Since the server is not actually generating the response, it does not
return the Content-Type, nor Content-Length headers.  In fact, the
server can't know these -- it's the responsibility of the CGI to
generate these headers.  (In fact, when you write a cgi program and
neglect to generate a Content-Type header, a normal web server will
generate a 500 Internal Server Error.)

RFC3875 states that the CGI program should return a status header, but
in practice CGIs rarely do.  For this reason, web servers generally
assume a status of 200 if the CGI does not generate its own status.

To make your lifes easier, let's say that your server should generate:

- status code
- Date
- Server

and let the CGI generate the Content-Type and Content-Length headers.


More information about the cs631apue mailing list