out.html 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <html><head><title>CGI Script output</title></head><body><h1><img alt="" src="out_files/CGIlogo.gif"> CGI Script Output</h1>
  2. <hr>
  3. <h2>Script output</h2>
  4. The script sends its output to stdout. This output can either be a
  5. document generated by the script, or instructions to the server for
  6. retrieving the desired output. <p>
  7. </p><hr>
  8. <h2>Script naming conventions</h2>
  9. Normally, scripts produce output which is interpreted and sent back to
  10. the client. An advantage of this is that the scripts do not need to
  11. send a full HTTP/1.0 header for every request. <p>
  12. <a name="nph">
  13. Some scripts may want to avoid the extra overhead of the server
  14. parsing their output, and talk directly to the client. In order to
  15. distinguish these scripts from the other scripts, CGI requires that
  16. the script name begins with nph- if a script does not want the server
  17. to parse its header. In this case, it is the script's responsibility
  18. to return a valid HTTP/1.0 (or HTTP/0.9) response to the client. </a></p><p>
  19. </p><hr>
  20. <h2><a name="nph">Parsed headers</a></h2>
  21. <a name="nph">The output of scripts begins with a small header. This header consists
  22. of text lines, in the same format as an </a><a href="http://www.w3.org/hypertext/WWW/Protocols/HTTP/Object_Headers.html">
  23. HTTP header</a>, terminated by a blank line (a line with only a
  24. linefeed or CR/LF). <p>
  25. Any headers which are not server directives are sent directly back to
  26. the client. Currently, this specification defines three server
  27. directives:</p><p>
  28. </p><ul>
  29. <li> <code>Content-type</code> <p>
  30. This is the MIME type of the document you are returning. </p><p>
  31. </p></li><li> <code>Location</code> <p>
  32. This is used to specify to the server that you are returning a
  33. reference to a document rather than an actual document. </p><p>
  34. If the argument to this is a URL, the server will issue a redirect
  35. to the client. </p><p>
  36. If the argument to this is a virtual path, the server will
  37. retrieve the document specified as if the client had requested
  38. that document originally. ? directives will work in here, but #
  39. directives must be redirected back to the client.</p><p>
  40. </p></li><li> <a name="status"><code>Status</code></a><p>
  41. This is used to give the server an HTTP/1.0 <a href="http://www.w3.org/hypertext/WWW/Protocols/HTTP/HTRESP.html">status
  42. line</a> to send to the client. The format is <code>nnn xxxxx</code>,
  43. where <code>nnn</code> is the 3-digit status code, and
  44. <code>xxxxx</code> is the reason string, such as "Forbidden".</p><p>
  45. </p></li></ul>
  46. <hr>
  47. <h2>Examples</h2>
  48. Let's say I have a fromgratz to HTML converter. When my converter is
  49. finished with its work, it will output the following on stdout (note
  50. that the lines beginning and ending with --- are just for illustration
  51. and would not be output): <p>
  52. </p><pre>--- start of output ---
  53. Content-type: text/html
  54. --- end of output ---
  55. </pre>
  56. Note the blank line after Content-type. <p>
  57. Now, let's say I have a script which, in certain instances, wants to
  58. return the document <code>/path/doc.txt</code> from this server just
  59. as if the user had actually requested
  60. <code>http://server:port/path/doc.txt</code> to begin with. In this
  61. case, the script would output: </p><p>
  62. </p><pre>--- start of output ---
  63. Location: /path/doc.txt
  64. --- end of output ---
  65. </pre>
  66. The server would then perform the request and send it to the client.
  67. <p>
  68. Let's say that I have a script which wants to reference our gopher
  69. server. In this case, if the script wanted to refer the user to
  70. <code>gopher://gopher.ncsa.uiuc.edu/</code>, it would output: </p><p>
  71. </p><pre>--- start of output ---
  72. Location: gopher://gopher.ncsa.uiuc.edu/
  73. --- end of output ---
  74. </pre>
  75. Finally, I have a script which wants to talk to the client directly.
  76. 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,
  77. the script would output the following HTTP/1.0 response: <p>
  78. </p><pre>--- start of output ---
  79. HTTP/1.0 200 OK
  80. Server: NCSA/1.0a6
  81. Content-type: text/plain
  82. This is a plaintext document generated on the fly just for you.
  83. --- end of output ---
  84. </pre>
  85. <hr>
  86. <a href="http://hoohoo.ncsa.uiuc.edu/cgi/interface.html"><img alt="[Back]" src="out_files/back.gif">Return to the
  87. interface specification</a> <p>
  88. CGI - Common Gateway Interface
  89. </p><address><a href="http://hoohoo.ncsa.uiuc.edu/cgi/mailtocgi.html">cgi@ncsa.uiuc.edu</a></address>
  90. </body></html>