summaryrefslogtreecommitdiffhomepage
path: root/docs/cgi/out.html
blob: 2203ee5a0a7fffb63bc40f76f7b6e40e05bd3a06 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<html><head><title>CGI Script output</title></head><body><h1><img alt="" src="out_files/CGIlogo.gif"> CGI Script Output</h1>
<hr>

<h2>Script output</h2>

The script sends its output to stdout. This output can either be a
document generated by the script, or instructions to the server for
retrieving the desired output. <p>
</p><hr>

<h2>Script naming conventions</h2>

Normally, scripts produce output which is interpreted and sent back to
the client. An advantage of this is that the scripts do not need to
send a full HTTP/1.0 header for every request.  <p>
<a name="nph">
Some scripts may want to avoid the extra overhead of the server
parsing their output, and talk directly to the client. In order to
distinguish these scripts from the other scripts, CGI requires that
the script name begins with nph- if a script does not want the server
to parse its header. In this case, it is the script's responsibility
to return a valid HTTP/1.0 (or HTTP/0.9) response to the client.  </a></p><p>

</p><hr>
<h2><a name="nph">Parsed headers</a></h2>

<a name="nph">The output of scripts begins with a small header. This header consists
of text lines, in the same format as an </a><a href="http://www.w3.org/hypertext/WWW/Protocols/HTTP/Object_Headers.html">
HTTP header</a>, terminated by a blank line (a line with only a
linefeed or CR/LF). <p>

Any headers which are not server directives are sent directly back to
the client. Currently, this specification defines three server
directives:</p><p>

</p><ul>
<li> <code>Content-type</code> <p>

    This is the MIME type of the document you are returning.  </p><p>

</p></li><li> <code>Location</code> <p>

    This is used to specify to the server that you are returning a
    reference to a document rather than an actual document. </p><p>

    If the argument to this is a URL, the server will issue a redirect
    to the client. </p><p>

    If the argument to this is a virtual path, the server will
    retrieve the document specified as if the client had requested
    that document originally. ? directives will work in here, but #
    directives must be redirected back to the client.</p><p>


</p></li><li> <a name="status"><code>Status</code></a><p>

    This is used to give the server an HTTP/1.0 <a href="http://www.w3.org/hypertext/WWW/Protocols/HTTP/HTRESP.html">status
line</a> to send to the client. The format is <code>nnn xxxxx</code>,
where <code>nnn</code> is the 3-digit status code, and
<code>xxxxx</code> is the reason string, such as "Forbidden".</p><p>

</p></li></ul>

<hr>
<h2>Examples</h2>

Let's say I have a fromgratz to HTML converter. When my converter is
finished with its work, it will output the following on stdout (note
that the lines beginning and ending with --- are just for illustration
and would not be output): <p>

</p><pre>--- start of output ---
Content-type: text/html

--- end of output ---
</pre>

Note the blank line after Content-type. <p>

Now, let's say I have a script which, in certain instances, wants to
return the document <code>/path/doc.txt</code> from this server just
as if the user had actually requested
<code>http://server:port/path/doc.txt</code> to begin with. In this
case, the script would output: </p><p>
</p><pre>--- start of output ---
Location: /path/doc.txt

--- end of output ---
</pre>

The server would then perform the request and send it to the client.
<p>

Let's say that I have a script which wants to reference our gopher
server. In this case, if the script wanted to refer the user to
<code>gopher://gopher.ncsa.uiuc.edu/</code>, it would output: </p><p>

</p><pre>--- start of output ---
Location: gopher://gopher.ncsa.uiuc.edu/

--- end of output ---
</pre>

Finally, I have a script which wants to talk to the client directly.
In this case, if the script is referenced with <a href="http://hoohoo.ncsa.uiuc.edu/cgi/env.html#protocol"><code>SERVER_PROTOCOL</code></a> of HTTP/1.0,
the script would output the following HTTP/1.0 response: <p>

</p><pre>--- start of output ---
HTTP/1.0 200 OK
Server: NCSA/1.0a6
Content-type: text/plain

This is a plaintext document generated on the fly just for you.

--- end of output ---
</pre>


<hr>

<a href="http://hoohoo.ncsa.uiuc.edu/cgi/interface.html"><img alt="[Back]" src="out_files/back.gif">Return to the
interface specification</a> <p>

CGI - Common Gateway Interface
</p><address><a href="http://hoohoo.ncsa.uiuc.edu/cgi/mailtocgi.html">cgi@ncsa.uiuc.edu</a></address>
</body></html>