| | @@ -1,12 +1,16 @@ |
| 1 | 1 | <title>How CGI Works In Fossil</title> |
| 2 | 2 | <h2>Introduction</h2><blockquote> |
| 3 | 3 | <p>CGI or "Common Gateway Interface" is a venerable yet reliable technique for |
| 4 | 4 | generating dynamic web content. This article gives a quick background on how |
| 5 | 5 | CGI works and describes how Fossil can act as a CGI service. |
| 6 | | -<p>This is a "how it works" guide. If you just want to set up Fossil |
| 7 | | -as a CGI server, see the [./server/ | Fossil Server Setup] page. |
| 6 | +<p>This is a "how it works" guide. This document provides background |
| 7 | +information on the CGI protocol so that you can better understand what |
| 8 | +is going on behind the scenes. If you just want to set up Fossil |
| 9 | +as a CGI server, see the [./server/ | Fossil Server Setup] page. Or |
| 10 | +if you want to development CGI-based extensions to Fossil, see |
| 11 | +the [./serverext.wiki|CGI Server Extensions] page. |
| 8 | 12 | </blockquote> |
| 9 | 13 | <h2>A Quick Review Of CGI</h2><blockquote> |
| 10 | 14 | <p> |
| 11 | 15 | An HTTP request is a block of text that is sent by a client application |
| 12 | 16 | (usually a web browser) and arrives at the web server over a network |
| | @@ -14,20 +18,20 @@ |
| 14 | 18 | being requested. The URL in the HTTP request is typically the same URL |
| 15 | 19 | that appears in the URL bar at the top of the web browser that is making |
| 16 | 20 | the request. The URL might contain a "?" character followed |
| 17 | 21 | query parameters. The HTTP will usually also contain other information |
| 18 | 22 | such as the name of the application that made the request, whether or |
| 19 | | -not the requesting application can except a compressed reply, POST |
| 23 | +not the requesting application can accept a compressed reply, POST |
| 20 | 24 | parameters from forms, and so forth. |
| 21 | 25 | <p> |
| 22 | 26 | The job of the web server is to interpret the HTTP request and formulate |
| 23 | 27 | an appropriate reply. |
| 24 | 28 | The web server is free to interpret the HTTP request in any way it wants. |
| 25 | 29 | But most web servers follow a similar pattern, described below. |
| 26 | 30 | (Note: details may vary from one web server to another.) |
| 27 | 31 | <p> |
| 28 | | -Suppose the URL in the HTTP request looks like this: |
| 32 | +Suppose the filename component of the URL in the HTTP request looks like this: |
| 29 | 33 | <blockquote><b>/one/two/timeline/four</b></blockquote> |
| 30 | 34 | Most web servers will search their content area for files that match |
| 31 | 35 | some prefix of the URL. The search starts with <b>/one</b>, then goes to |
| 32 | 36 | <b>/one/two</b>, then <b>/one/two/timeline</b>, and finally |
| 33 | 37 | <b>/one/two/timeline/four</b> is checked. The search stops at the first |
| | @@ -180,10 +184,23 @@ |
| 180 | 184 | a repository. The PATH_INFO is shortened by removing |
| 181 | 185 | "subdir/three/" leaving it at just "timeline". |
| 182 | 186 | <li> Fossil looks at the rest of PATH_INFO to see that the webpage |
| 183 | 187 | requested is "timeline". |
| 184 | 188 | </ol> |
| 189 | +<a name="cgivar"></a> |
| 190 | +The web server sets many environment variables in step 2 in addition |
| 191 | +to just PATH_INFO. The following diagram shows a few of these variables |
| 192 | +and their relationship to the request URL: |
| 193 | +<pre> |
| 194 | + REQUEST_URI |
| 195 | + ______________|___________________ |
| 196 | + / \ |
| 197 | + http://example.com/cgis/example2/subdir/three/timeline?c=55d7e1 |
| 198 | + \_________/\____________/\____________________/ \______/ |
| 199 | + | | | | |
| 200 | + HTTP_HOST SCRIPT_NAME PATH_INFO QUERY_STRING |
| 201 | +</pre> |
| 185 | 202 | </blockquote> |
| 186 | 203 | <h2>Additional CGI Script Options</h2> |
| 187 | 204 | <blockquote> |
| 188 | 205 | <p> |
| 189 | 206 | The CGI script can have additional options used to fine-tune |
| 190 | 207 | |