0000: 3c 74 69 74 6c 65 3e 48 6f 77 20 43 47 49 20 57 <title>How CGI W
0010: 6f 72 6b 73 20 49 6e 20 46 6f 73 73 69 6c 3c 2f orks In Fossil</
0020: 74 69 74 6c 65 3e 0a 0a 3c 68 32 3e 49 6e 74 72 title>..<h2>Intr
0030: 6f 64 75 63 74 69 6f 6e 3c 2f 68 32 3e 0a 0a 43 oduction</h2>..C
0040: 47 49 20 6f 72 20 22 43 6f 6d 6d 6f 6e 20 47 61 GI or "Common Ga
0050: 74 65 77 61 79 20 49 6e 74 65 72 66 61 63 65 22 teway Interface"
0060: 20 69 73 20 61 20 76 65 6e 65 72 61 62 6c 65 20 is a venerable
0070: 79 65 74 20 72 65 6c 69 61 62 6c 65 20 74 65 63 yet reliable tec
0080: 68 6e 69 71 75 65 20 66 6f 72 0a 67 65 6e 65 72 hnique for.gener
0090: 61 74 69 6e 67 20 64 79 6e 61 6d 69 63 20 77 65 ating dynamic we
00a0: 62 20 63 6f 6e 74 65 6e 74 2e 20 20 54 68 69 73 b content. This
00b0: 20 61 72 74 69 63 6c 65 20 67 69 76 65 73 20 61 article gives a
00c0: 20 71 75 69 63 6b 20 62 61 63 6b 67 72 6f 75 6e quick backgroun
00d0: 64 20 6f 6e 20 68 6f 77 0a 43 47 49 20 77 6f 72 d on how.CGI wor
00e0: 6b 73 20 61 6e 64 20 64 65 73 63 72 69 62 65 73 ks and describes
00f0: 20 68 6f 77 20 46 6f 73 73 69 6c 20 63 61 6e 20 how Fossil can
0100: 61 63 74 20 61 73 20 61 20 43 47 49 20 73 65 72 act as a CGI ser
0110: 76 69 63 65 2e 0a 0a 54 68 69 73 20 69 73 20 61 vice...This is a
0120: 20 22 68 6f 77 20 69 74 20 77 6f 72 6b 73 22 20 "how it works"
0130: 67 75 69 64 65 2e 20 20 54 68 69 73 20 64 6f 63 guide. This doc
0140: 75 6d 65 6e 74 20 70 72 6f 76 69 64 65 73 20 62 ument provides b
0150: 61 63 6b 67 72 6f 75 6e 64 0a 69 6e 66 6f 72 6d ackground.inform
0160: 61 74 69 6f 6e 20 6f 6e 20 74 68 65 20 43 47 49 ation on the CGI
0170: 20 70 72 6f 74 6f 63 6f 6c 20 73 6f 20 74 68 61 protocol so tha
0180: 74 20 79 6f 75 20 63 61 6e 20 62 65 74 74 65 72 t you can better
0190: 20 75 6e 64 65 72 73 74 61 6e 64 20 77 68 61 74 understand what
01a0: 0a 69 73 20 67 6f 69 6e 67 20 6f 6e 20 62 65 68 .is going on beh
01b0: 69 6e 64 20 74 68 65 20 73 63 65 6e 65 73 2e 20 ind the scenes.
01c0: 20 49 66 20 79 6f 75 20 6a 75 73 74 20 77 61 6e If you just wan
01d0: 74 20 74 6f 20 73 65 74 20 75 70 20 46 6f 73 73 t to set up Foss
01e0: 69 6c 0a 61 73 20 61 20 43 47 49 20 73 65 72 76 il.as a CGI serv
01f0: 65 72 2c 20 73 65 65 20 74 68 65 20 5b 2e 2f 73 er, see the [./s
0200: 65 72 76 65 72 2f 20 7c 20 46 6f 73 73 69 6c 20 erver/ | Fossil
0210: 53 65 72 76 65 72 20 53 65 74 75 70 5d 20 70 61 Server Setup] pa
0220: 67 65 2e 20 20 4f 72 0a 69 66 20 79 6f 75 20 77 ge. Or.if you w
0230: 61 6e 74 20 74 6f 20 64 65 76 65 6c 6f 70 20 43 ant to develop C
0240: 47 49 2d 62 61 73 65 64 20 65 78 74 65 6e 73 69 GI-based extensi
0250: 6f 6e 73 20 74 6f 20 46 6f 73 73 69 6c 2c 20 73 ons to Fossil, s
0260: 65 65 0a 74 68 65 20 5b 2e 2f 73 65 72 76 65 72 ee.the [./server
0270: 65 78 74 2e 77 69 6b 69 7c 43 47 49 20 53 65 72 ext.wiki|CGI Ser
0280: 76 65 72 20 45 78 74 65 6e 73 69 6f 6e 73 5d 20 ver Extensions]
0290: 70 61 67 65 2e 0a 0a 3c 68 32 3e 41 20 51 75 69 page...<h2>A Qui
02a0: 63 6b 20 52 65 76 69 65 77 20 4f 66 20 43 47 49 ck Review Of CGI
02b0: 3c 2f 68 32 3e 0a 0a 41 6e 20 48 54 54 50 20 72 </h2>..An HTTP r
02c0: 65 71 75 65 73 74 20 69 73 20 61 20 62 6c 6f 63 equest is a bloc
02d0: 6b 20 6f 66 20 74 65 78 74 20 74 68 61 74 20 69 k of text that i
02e0: 73 20 73 65 6e 74 20 62 79 20 61 20 63 6c 69 65 s sent by a clie
02f0: 6e 74 20 61 70 70 6c 69 63 61 74 69 6f 6e 0a 28 nt application.(
0300: 75 73 75 61 6c 6c 79 20 61 20 77 65 62 20 62 72 usually a web br
0310: 6f 77 73 65 72 29 20 61 6e 64 20 61 72 72 69 76 owser) and arriv
0320: 65 73 20 61 74 20 74 68 65 20 77 65 62 20 73 65 es at the web se
0330: 72 76 65 72 20 6f 76 65 72 20 61 20 6e 65 74 77 rver over a netw
0340: 6f 72 6b 0a 63 6f 6e 6e 65 63 74 69 6f 6e 2e 20 ork.connection.
0350: 20 54 68 65 20 48 54 54 50 20 72 65 71 75 65 73 The HTTP reques
0360: 74 20 63 6f 6e 74 61 69 6e 73 20 61 20 55 52 4c t contains a URL
0370: 20 74 68 61 74 20 64 65 73 63 72 69 62 65 73 20 that describes
0380: 74 68 65 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 0a the information.
0390: 62 65 69 6e 67 20 72 65 71 75 65 73 74 65 64 2e being requested.
03a0: 20 20 54 68 65 20 55 52 4c 20 69 6e 20 74 68 65 The URL in the
03b0: 20 48 54 54 50 20 72 65 71 75 65 73 74 20 69 73 HTTP request is
03c0: 20 74 79 70 69 63 61 6c 6c 79 20 74 68 65 20 73 typically the s
03d0: 61 6d 65 20 55 52 4c 0a 74 68 61 74 20 61 70 70 ame URL.that app
03e0: 65 61 72 73 20 69 6e 20 74 68 65 20 55 52 4c 20 ears in the URL
03f0: 62 61 72 20 61 74 20 74 68 65 20 74 6f 70 20 6f bar at the top o
0400: 66 20 74 68 65 20 77 65 62 20 62 72 6f 77 73 65 f the web browse
0410: 72 20 74 68 61 74 20 69 73 20 6d 61 6b 69 6e 67 r that is making
0420: 0a 74 68 65 20 72 65 71 75 65 73 74 2e 20 20 54 .the request. T
0430: 68 65 20 55 52 4c 20 6d 69 67 68 74 20 63 6f 6e he URL might con
0440: 74 61 69 6e 20 61 20 22 3f 22 20 63 68 61 72 61 tain a "?" chara
0450: 63 74 65 72 20 66 6f 6c 6c 6f 77 65 64 20 62 79 cter followed by
0460: 0a 71 75 65 72 79 20 70 61 72 61 6d 65 74 65 72 .query parameter
0470: 73 2e 20 20 54 68 65 20 48 54 54 50 20 77 69 6c s. The HTTP wil
0480: 6c 20 75 73 75 61 6c 6c 79 20 61 6c 73 6f 20 63 l usually also c
0490: 6f 6e 74 61 69 6e 20 6f 74 68 65 72 20 69 6e 66 ontain other inf
04a0: 6f 72 6d 61 74 69 6f 6e 0a 73 75 63 68 20 61 73 ormation.such as
04b0: 20 74 68 65 20 6e 61 6d 65 20 6f 66 20 74 68 65 the name of the
04c0: 20 61 70 70 6c 69 63 61 74 69 6f 6e 20 74 68 61 application tha
04d0: 74 20 6d 61 64 65 20 74 68 65 20 72 65 71 75 65 t made the reque
04e0: 73 74 2c 20 77 68 65 74 68 65 72 20 6f 72 0a 6e st, whether or.n
04f0: 6f 74 20 74 68 65 20 72 65 71 75 65 73 74 69 6e ot the requestin
0500: 67 20 61 70 70 6c 69 63 61 74 69 6f 6e 20 63 61 g application ca
0510: 6e 20 61 63 63 65 70 74 20 61 20 63 6f 6d 70 72 n accept a compr
0520: 65 73 73 65 64 20 72 65 70 6c 79 2c 20 50 4f 53 essed reply, POS
0530: 54 0a 70 61 72 61 6d 65 74 65 72 73 20 66 72 6f T.parameters fro
0540: 6d 20 66 6f 72 6d 73 2c 20 61 6e 64 20 73 6f 20 m forms, and so
0550: 66 6f 72 74 68 2e 0a 0a 54 68 65 20 6a 6f 62 20 forth...The job
0560: 6f 66 20 74 68 65 20 77 65 62 20 73 65 72 76 65 of the web serve
0570: 72 20 69 73 20 74 6f 20 69 6e 74 65 72 70 72 65 r is to interpre
0580: 74 20 74 68 65 20 48 54 54 50 20 72 65 71 75 65 t the HTTP reque
0590: 73 74 20 61 6e 64 20 66 6f 72 6d 75 6c 61 74 65 st and formulate
05a0: 0a 61 6e 20 61 70 70 72 6f 70 72 69 61 74 65 20 .an appropriate
05b0: 72 65 70 6c 79 2e 0a 54 68 65 20 77 65 62 20 73 reply..The web s
05c0: 65 72 76 65 72 20 69 73 20 66 72 65 65 20 74 6f erver is free to
05d0: 20 69 6e 74 65 72 70 72 65 74 20 74 68 65 20 48 interpret the H
05e0: 54 54 50 20 72 65 71 75 65 73 74 20 69 6e 20 61 TTP request in a
05f0: 6e 79 20 77 61 79 20 69 74 20 77 61 6e 74 73 2c ny way it wants,
0600: 0a 62 75 74 20 6d 6f 73 74 20 77 65 62 20 73 65 .but most web se
0610: 72 76 65 72 73 20 66 6f 6c 6c 6f 77 20 61 20 73 rvers follow a s
0620: 69 6d 69 6c 61 72 20 70 61 74 74 65 72 6e 2c 20 imilar pattern,
0630: 64 65 73 63 72 69 62 65 64 20 62 65 6c 6f 77 2e described below.
0640: 0a 28 4e 6f 74 65 3a 20 64 65 74 61 69 6c 73 20 .(Note: details
0650: 6d 61 79 20 76 61 72 79 20 66 72 6f 6d 20 6f 6e may vary from on
0660: 65 20 77 65 62 20 73 65 72 76 65 72 20 74 6f 20 e web server to
0670: 61 6e 6f 74 68 65 72 2e 29 0a 0a 53 75 70 70 6f another.)..Suppo
0680: 73 65 20 74 68 65 20 66 69 6c 65 6e 61 6d 65 20 se the filename
0690: 63 6f 6d 70 6f 6e 65 6e 74 20 6f 66 20 74 68 65 component of the
06a0: 20 55 52 4c 20 69 6e 20 74 68 65 20 48 54 54 50 URL in the HTTP
06b0: 20 72 65 71 75 65 73 74 20 6c 6f 6f 6b 73 20 6c request looks l
06c0: 69 6b 65 20 74 68 69 73 3a 0a 0a 3c 70 72 65 3e ike this:..<pre>
06d0: 2f 6f 6e 65 2f 74 77 6f 2f 74 69 6d 65 6c 69 6e /one/two/timelin
06e0: 65 2f 66 6f 75 72 3c 2f 70 72 65 3e 0a 0a 4d 6f e/four</pre>..Mo
06f0: 73 74 20 77 65 62 20 73 65 72 76 65 72 73 20 77 st web servers w
0700: 69 6c 6c 20 73 65 61 72 63 68 20 74 68 65 69 72 ill search their
0710: 20 63 6f 6e 74 65 6e 74 20 61 72 65 61 20 66 6f content area fo
0720: 72 20 66 69 6c 65 73 20 74 68 61 74 20 6d 61 74 r files that mat
0730: 63 68 0a 73 6f 6d 65 20 70 72 65 66 69 78 20 6f ch.some prefix o
0740: 66 20 74 68 65 20 55 52 4c 2e 20 20 54 68 65 20 f the URL. The
0750: 73 65 61 72 63 68 20 73 74 61 72 74 73 20 77 69 search starts wi
0760: 74 68 20 3c 62 3e 2f 6f 6e 65 3c 2f 62 3e 2c 20 th <b>/one</b>,
0770: 74 68 65 6e 20 67 6f 65 73 20 74 6f 0a 3c 62 3e then goes to.<b>
0780: 2f 6f 6e 65 2f 74 77 6f 3c 2f 62 3e 2c 20 74 68 /one/two</b>, th
0790: 65 6e 20 3c 62 3e 2f 6f 6e 65 2f 74 77 6f 2f 74 en <b>/one/two/t
07a0: 69 6d 65 6c 69 6e 65 3c 2f 62 3e 2c 20 61 6e 64 imeline</b>, and
07b0: 20 66 69 6e 61 6c 6c 79 0a 3c 62 3e 2f 6f 6e 65 finally.<b>/one
07c0: 2f 74 77 6f 2f 74 69 6d 65 6c 69 6e 65 2f 66 6f /two/timeline/fo
07d0: 75 72 3c 2f 62 3e 20 69 73 20 63 68 65 63 6b 65 ur</b> is checke
07e0: 64 2e 20 20 54 68 65 20 73 65 61 72 63 68 20 73 d. The search s
07f0: 74 6f 70 73 20 61 74 20 74 68 65 20 66 69 72 73 tops at the firs
0800: 74 0a 6d 61 74 63 68 2e 0a 0a 53 75 70 70 6f 73 t.match...Suppos
0810: 65 20 74 68 65 20 66 69 72 73 74 20 6d 61 74 63 e the first matc
0820: 68 20 69 73 20 3c 62 3e 2f 6f 6e 65 2f 74 77 6f h is <b>/one/two
0830: 3c 2f 62 3e 2e 20 20 49 66 20 3c 62 3e 2f 6f 6e </b>. If <b>/on
0840: 65 2f 74 77 6f 3c 2f 62 3e 20 69 73 20 61 6e 0a e/two</b> is an.
0850: 6f 72 64 69 6e 61 72 79 20 66 69 6c 65 20 69 6e ordinary file in
0860: 20 74 68 65 20 63 6f 6e 74 65 6e 74 20 61 72 65 the content are
0870: 61 2c 20 74 68 65 6e 20 74 68 61 74 20 66 69 6c a, then that fil
0880: 65 20 69 73 20 72 65 74 75 72 6e 65 64 20 61 73 e is returned as
0890: 20 73 74 61 74 69 63 0a 63 6f 6e 74 65 6e 74 2e static.content.
08a0: 20 20 54 68 65 20 22 3c 62 3e 2f 74 69 6d 65 6c The "<b>/timel
08b0: 69 6e 65 2f 66 6f 75 72 3c 2f 62 3e 22 20 73 75 ine/four</b>" su
08c0: 66 66 69 78 20 69 73 20 73 69 6c 65 6e 74 6c 79 ffix is silently
08d0: 20 69 67 6e 6f 72 65 64 2e 0a 0a 49 66 20 3c 62 ignored...If <b
08e0: 3e 2f 6f 6e 65 2f 74 77 6f 3c 2f 62 3e 20 69 73 >/one/two</b> is
08f0: 20 61 20 43 47 49 20 73 63 72 69 70 74 20 28 6f a CGI script (o
0900: 72 20 70 72 6f 67 72 61 6d 29 2c 20 74 68 65 6e r program), then
0910: 20 74 68 65 20 77 65 62 20 73 65 72 76 65 72 0a the web server.
0920: 65 78 65 63 75 74 65 73 20 74 68 65 20 3c 62 3e executes the <b>
0930: 2f 6f 6e 65 2f 74 77 6f 3c 2f 62 3e 20 73 63 72 /one/two</b> scr
0940: 69 70 74 2e 20 20 54 68 65 20 6f 75 74 70 75 74 ipt. The output
0950: 20 67 65 6e 65 72 61 74 65 64 20 62 79 0a 74 68 generated by.th
0960: 65 20 73 63 72 69 70 74 20 69 73 20 63 6f 6c 6c e script is coll
0970: 65 63 74 65 64 20 61 6e 64 20 72 65 70 61 63 6b ected and repack
0980: 61 67 65 64 20 61 73 20 74 68 65 20 48 54 54 50 aged as the HTTP
0990: 20 72 65 70 6c 79 2e 0a 0a 42 65 66 6f 72 65 20 reply...Before
09a0: 65 78 65 63 75 74 69 6e 67 20 74 68 65 20 43 47 executing the CG
09b0: 49 20 73 63 72 69 70 74 2c 20 74 68 65 20 77 65 I script, the we
09c0: 62 20 73 65 72 76 65 72 20 77 69 6c 6c 20 73 65 b server will se
09d0: 74 20 75 70 20 76 61 72 69 6f 75 73 0a 65 6e 76 t up various.env
09e0: 69 72 6f 6e 6d 65 6e 74 20 76 61 72 69 61 62 6c ironment variabl
09f0: 65 73 20 77 69 74 68 20 69 6e 66 6f 72 6d 61 74 es with informat
0a00: 69 6f 6e 20 75 73 65 66 75 6c 20 74 6f 20 74 68 ion useful to th
0a10: 65 20 43 47 49 20 73 63 72 69 70 74 3a 0a 3c 74 e CGI script:.<t
0a20: 61 62 6c 65 3e 0a 3c 74 72 3e 3c 74 68 3e 56 61 able>.<tr><th>Va
0a30: 72 69 61 62 6c 65 3c 74 68 3e 4d 65 61 6e 69 6e riable<th>Meanin
0a40: 67 0a 3c 74 72 3e 3c 74 64 3e 47 41 54 45 57 41 g.<tr><td>GATEWA
0a50: 59 5f 49 4e 54 45 52 46 41 43 45 3c 74 64 3e 41 Y_INTERFACE<td>A
0a60: 6c 77 61 79 73 20 73 65 74 20 74 6f 20 22 43 47 lways set to "CG
0a70: 49 2f 31 2e 30 22 0a 3c 74 72 3e 3c 74 64 3e 52 I/1.0".<tr><td>R
0a80: 45 51 55 45 53 54 5f 55 52 49 0a 20 20 20 20 3c EQUEST_URI. <
0a90: 74 64 3e 54 68 65 20 69 6e 70 75 74 20 55 52 4c td>The input URL
0aa0: 20 66 72 6f 6d 20 74 68 65 20 48 54 54 50 20 72 from the HTTP r
0ab0: 65 71 75 65 73 74 2e 0a 3c 74 72 3e 3c 74 64 3e equest..<tr><td>
0ac0: 53 43 52 49 50 54 5f 4e 41 4d 45 0a 20 20 20 20 SCRIPT_NAME.
0ad0: 3c 74 64 3e 54 68 65 20 70 72 65 66 69 78 20 6f <td>The prefix o
0ae0: 66 20 74 68 65 20 69 6e 70 75 74 20 55 52 4c 20 f the input URL
0af0: 74 68 61 74 20 6d 61 74 63 68 65 73 20 74 68 65 that matches the
0b00: 20 43 47 49 20 73 63 72 69 70 74 20 6e 61 6d 65 CGI script name
0b10: 2e 0a 20 20 20 20 49 6e 20 74 68 69 73 20 65 78 .. In this ex
0b20: 61 6d 70 6c 65 3a 20 22 2f 6f 6e 65 2f 74 77 6f ample: "/one/two
0b30: 22 2e 0a 3c 74 72 3e 3c 74 64 3e 50 41 54 48 5f "..<tr><td>PATH_
0b40: 49 4e 46 4f 0a 20 20 20 20 3c 74 64 3e 54 68 65 INFO. <td>The
0b50: 20 73 75 66 66 69 78 20 6f 66 20 74 68 65 20 55 suffix of the U
0b60: 52 4c 20 62 65 79 6f 6e 64 20 74 68 65 20 6e 61 RL beyond the na
0b70: 6d 65 20 6f 66 20 74 68 65 20 43 47 49 20 73 63 me of the CGI sc
0b80: 72 69 70 74 2e 0a 20 20 20 20 49 6e 20 74 68 69 ript.. In thi
0b90: 73 20 65 78 61 6d 70 6c 65 3a 20 22 74 69 6d 65 s example: "time
0ba0: 6c 69 6e 65 2f 66 6f 75 72 22 2e 0a 3c 74 72 3e line/four"..<tr>
0bb0: 3c 74 64 3e 51 55 45 52 59 5f 53 54 52 49 4e 47 <td>QUERY_STRING
0bc0: 0a 20 20 20 20 3c 74 64 3e 54 68 65 20 71 75 65 . <td>The que
0bd0: 72 79 20 73 74 72 69 6e 67 20 74 68 61 74 20 66 ry string that f
0be0: 6f 6c 6c 6f 77 73 20 74 68 65 20 22 3f 22 20 69 ollows the "?" i
0bf0: 6e 20 74 68 65 20 55 52 4c 2c 20 69 66 20 74 68 n the URL, if th
0c00: 65 72 65 20 69 73 20 6f 6e 65 2e 0a 3c 2f 74 61 ere is one..</ta
0c10: 62 6c 65 3e 0a 0a 54 68 65 72 65 20 61 72 65 20 ble>..There are
0c20: 6f 74 68 65 72 20 43 47 49 20 65 6e 76 69 72 6f other CGI enviro
0c30: 6e 6d 65 6e 74 20 76 61 72 69 61 62 6c 65 73 20 nment variables
0c40: 62 65 79 6f 6e 64 20 74 68 6f 73 65 20 6c 69 73 beyond those lis
0c50: 74 65 64 20 61 62 6f 76 65 2e 0a 4d 61 6e 79 20 ted above..Many
0c60: 46 6f 73 73 69 6c 20 73 65 72 76 65 72 73 20 69 Fossil servers i
0c70: 6d 70 6c 65 6d 65 6e 74 20 74 68 65 0a 5b 68 74 mplement the.[ht
0c80: 74 70 73 3a 2f 2f 66 6f 73 73 69 6c 2d 73 63 6d tps://fossil-scm
0c90: 2e 6f 72 67 2f 68 6f 6d 65 2f 74 65 73 74 5f 65 .org/home/test_e
0ca0: 6e 76 2f 74 77 6f 2f 74 68 72 65 65 3f 61 62 63 nv/two/three?abc
0cb0: 3d 78 79 7a 7c 74 65 73 74 5f 65 6e 76 5d 0a 77 =xyz|test_env].w
0cc0: 65 62 70 61 67 65 20 74 68 61 74 20 73 68 6f 77 ebpage that show
0cd0: 73 20 73 6f 6d 65 20 6f 66 20 74 68 65 20 43 47 s some of the CG
0ce0: 49 20 65 6e 76 69 72 6f 6e 6d 65 6e 74 0a 76 61 I environment.va
0cf0: 72 69 61 62 6c 65 73 20 74 68 61 74 20 46 6f 73 riables that Fos
0d00: 73 69 6c 20 70 61 79 73 20 61 74 74 65 6e 74 69 sil pays attenti
0d10: 6f 6e 20 74 6f 2e 0a 0a 49 6e 20 61 64 64 69 74 on to...In addit
0d20: 69 6f 6e 20 74 6f 20 73 65 74 74 69 6e 67 20 76 ion to setting v
0d30: 61 72 69 6f 75 73 20 43 47 49 20 65 6e 76 69 72 arious CGI envir
0d40: 6f 6e 6d 65 6e 74 20 76 61 72 69 61 62 6c 65 73 onment variables
0d50: 2c 20 69 66 20 74 68 65 20 48 54 54 50 0a 72 65 , if the HTTP.re
0d60: 71 75 65 73 74 20 63 6f 6e 74 61 69 6e 73 20 50 quest contains P
0d70: 4f 53 54 20 63 6f 6e 74 65 6e 74 2c 20 74 68 65 OST content, the
0d80: 6e 20 74 68 65 20 77 65 62 20 73 65 72 76 65 72 n the web server
0d90: 20 72 65 6c 61 79 73 20 74 68 65 20 50 4f 53 54 relays the POST
0da0: 20 63 6f 6e 74 65 6e 74 0a 74 6f 20 73 74 61 6e content.to stan
0db0: 64 61 72 64 20 69 6e 70 75 74 20 6f 66 20 74 68 dard input of th
0dc0: 65 20 43 47 49 20 73 63 72 69 70 74 2e 0a 0a 49 e CGI script...I
0dd0: 6e 20 73 75 6d 6d 61 72 79 2c 20 74 68 65 20 74 n summary, the t
0de0: 61 73 6b 20 6f 66 20 74 68 65 0a 43 47 49 20 73 ask of the.CGI s
0df0: 63 72 69 70 74 20 69 73 20 74 6f 20 72 65 61 64 cript is to read
0e00: 20 74 68 65 20 76 61 72 69 6f 75 73 20 43 47 49 the various CGI
0e10: 20 65 6e 76 69 72 6f 6e 6d 65 6e 74 20 76 61 72 environment var
0e20: 69 61 62 6c 65 73 20 61 6e 64 0a 74 68 65 20 50 iables and.the P
0e30: 4f 53 54 20 63 6f 6e 74 65 6e 74 20 6f 6e 20 73 OST content on s
0e40: 74 61 6e 64 61 72 64 20 69 6e 70 75 74 20 28 69 tandard input (i
0e50: 66 20 61 6e 79 29 2c 20 66 69 67 75 72 65 20 6f f any), figure o
0e60: 75 74 20 61 6e 20 61 70 70 72 6f 70 72 69 61 74 ut an appropriat
0e70: 65 0a 72 65 70 6c 79 2c 20 74 68 65 6e 20 77 72 e.reply, then wr
0e80: 69 74 65 20 74 68 61 74 20 72 65 70 6c 79 20 6f ite that reply o
0e90: 6e 20 73 74 61 6e 64 61 72 64 20 6f 75 74 70 75 n standard outpu
0ea0: 74 2e 0a 54 68 65 20 77 65 62 20 73 65 72 76 65 t..The web serve
0eb0: 72 20 77 69 6c 6c 20 72 65 61 64 20 74 68 65 20 r will read the
0ec0: 6f 75 74 70 75 74 20 66 72 6f 6d 20 74 68 65 20 output from the
0ed0: 43 47 49 20 73 63 72 69 70 74 2c 20 72 65 66 6f CGI script, refo
0ee0: 72 6d 61 74 20 69 74 0a 69 6e 74 6f 20 61 6e 20 rmat it.into an
0ef0: 61 70 70 72 6f 70 72 69 61 74 65 20 48 54 54 50 appropriate HTTP
0f00: 20 72 65 70 6c 79 2c 20 61 6e 64 20 72 65 6c 61 reply, and rela
0f10: 79 20 74 68 65 20 72 65 73 75 6c 74 20 62 61 63 y the result bac
0f20: 6b 20 74 6f 20 74 68 65 0a 72 65 71 75 65 73 74 k to the.request
0f30: 69 6e 67 20 61 70 70 6c 69 63 61 74 69 6f 6e 2e ing application.
0f40: 0a 54 68 65 20 43 47 49 20 73 63 72 69 70 74 20 .The CGI script
0f50: 65 78 69 74 73 20 61 73 20 73 6f 6f 6e 20 61 73 exits as soon as
0f60: 20 69 74 20 67 65 6e 65 72 61 74 65 73 20 61 20 it generates a
0f70: 73 69 6e 67 6c 65 20 72 65 70 6c 79 2e 0a 54 68 single reply..Th
0f80: 65 20 77 65 62 20 73 65 72 76 65 72 20 77 69 6c e web server wil
0f90: 6c 20 28 75 73 75 61 6c 6c 79 29 20 70 65 72 73 l (usually) pers
0fa0: 69 73 74 20 61 6e 64 20 68 61 6e 64 6c 65 20 6d ist and handle m
0fb0: 75 6c 74 69 70 6c 65 20 48 54 54 50 20 72 65 71 ultiple HTTP req
0fc0: 75 65 73 74 73 2c 0a 62 75 74 20 61 20 43 47 49 uests,.but a CGI
0fd0: 20 73 63 72 69 70 74 20 68 61 6e 64 6c 65 73 20 script handles
0fe0: 6a 75 73 74 20 6f 6e 65 20 48 54 54 50 20 72 65 just one HTTP re
0ff0: 71 75 65 73 74 20 61 6e 64 20 74 68 65 6e 20 65 quest and then e
1000: 78 69 74 73 2e 0a 0a 54 68 65 20 61 62 6f 76 65 xits...The above
1010: 20 69 73 20 61 20 72 6f 75 67 68 20 6f 75 74 6c is a rough outl
1020: 69 6e 65 20 6f 66 20 68 6f 77 20 43 47 49 20 77 ine of how CGI w
1030: 6f 72 6b 73 2e 0a 54 68 65 72 65 20 61 72 65 20 orks..There are
1040: 6d 61 6e 79 20 64 65 74 61 69 6c 73 20 6f 6d 69 many details omi
1050: 74 74 65 64 20 66 72 6f 6d 20 74 68 69 73 20 62 tted from this b
1060: 72 69 65 66 20 64 69 73 63 75 73 73 69 6f 6e 2e rief discussion.
1070: 0a 53 65 65 20 6f 74 68 65 72 20 6f 6e 2d 6c 69 .See other on-li
1080: 6e 65 20 43 47 49 20 74 75 74 6f 72 69 61 6c 73 ne CGI tutorials
1090: 20 66 6f 72 20 66 75 72 74 68 65 72 20 69 6e 66 for further inf
10a0: 6f 72 6d 61 74 69 6f 6e 2e 0a 0a 3c 68 32 3e 48 ormation...<h2>H
10b0: 6f 77 20 46 6f 73 73 69 6c 20 41 63 74 73 20 41 ow Fossil Acts A
10c0: 73 20 41 20 43 47 49 20 50 72 6f 67 72 61 6d 3c s A CGI Program<
10d0: 2f 68 32 3e 0a 0a 41 6e 20 61 70 70 72 6f 70 72 /h2>..An appropr
10e0: 69 61 74 65 20 43 47 49 20 73 63 72 69 70 74 20 iate CGI script
10f0: 66 6f 72 20 72 75 6e 6e 69 6e 67 20 46 6f 73 73 for running Foss
1100: 69 6c 20 77 69 6c 6c 20 6c 6f 6f 6b 20 73 6f 6d il will look som
1110: 65 74 68 69 6e 67 0a 6c 69 6b 65 20 74 68 65 20 ething.like the
1120: 66 6f 6c 6c 6f 77 69 6e 67 3a 0a 0a 3c 70 72 65 following:..<pre
1130: 3e 0a 23 21 2f 75 73 72 2f 62 69 6e 2f 66 6f 73 >.#!/usr/bin/fos
1140: 73 69 6c 0a 72 65 70 6f 73 69 74 6f 72 79 3a 20 sil.repository:
1150: 2f 68 6f 6d 65 2f 77 77 77 2f 72 65 70 6f 73 2f /home/www/repos/
1160: 70 72 6f 6a 65 63 74 2e 66 6f 73 73 69 6c 0a 3c project.fossil.<
1170: 2f 70 72 65 3e 0a 0a 54 68 65 20 66 69 72 73 74 /pre>..The first
1180: 20 6c 69 6e 65 20 6f 66 20 74 68 65 20 73 63 72 line of the scr
1190: 69 70 74 20 69 73 20 61 0a 22 5b 68 74 74 70 73 ipt is a."[https
11a0: 3a 2f 2f 65 6e 2e 77 69 6b 69 70 65 64 69 61 2e ://en.wikipedia.
11b0: 6f 72 67 2f 77 69 6b 69 2f 53 68 65 62 61 6e 67 org/wiki/Shebang
11c0: 5f 25 32 38 55 6e 69 78 25 32 39 7c 73 68 65 62 _%28Unix%29|sheb
11d0: 61 6e 67 5d 22 0a 74 68 61 74 20 74 65 6c 6c 73 ang]".that tells
11e0: 20 74 68 65 20 6f 70 65 72 61 74 69 6e 67 20 73 the operating s
11f0: 79 73 74 65 6d 20 77 68 61 74 20 70 72 6f 67 72 ystem what progr
1200: 61 6d 20 74 6f 20 75 73 65 20 61 73 20 74 68 65 am to use as the
1210: 20 69 6e 74 65 72 70 72 65 74 65 72 0a 66 6f 72 interpreter.for
1220: 20 74 68 69 73 20 73 63 72 69 70 74 2e 20 20 4f this script. O
1230: 6e 20 75 6e 69 78 2c 20 77 68 65 6e 20 79 6f 75 n unix, when you
1240: 20 65 78 65 63 75 74 65 20 61 20 73 63 72 69 70 execute a scrip
1250: 74 20 74 68 61 74 20 73 74 61 72 74 73 20 77 69 t that starts wi
1260: 74 68 0a 61 20 73 68 65 62 61 6e 67 2c 20 74 68 th.a shebang, th
1270: 65 20 6f 70 65 72 61 74 69 6e 67 20 73 79 73 74 e operating syst
1280: 65 6d 20 72 75 6e 73 20 74 68 65 20 70 72 6f 67 em runs the prog
1290: 72 61 6d 20 69 64 65 6e 74 69 66 69 65 64 20 62 ram identified b
12a0: 79 20 74 68 65 0a 73 68 65 62 61 6e 67 20 77 69 y the.shebang wi
12b0: 74 68 20 61 20 73 69 6e 67 6c 65 20 61 72 67 75 th a single argu
12c0: 6d 65 6e 74 20 74 68 61 74 20 69 73 20 74 68 65 ment that is the
12d0: 20 66 75 6c 6c 20 70 61 74 68 6e 61 6d 65 20 6f full pathname o
12e0: 66 20 74 68 65 20 73 63 72 69 70 74 0a 69 74 73 f the script.its
12f0: 65 6c 66 2e 0a 49 6e 20 6f 75 72 20 65 78 61 6d elf..In our exam
1300: 70 6c 65 2c 20 74 68 65 20 69 6e 74 65 72 70 72 ple, the interpr
1310: 65 74 65 72 20 69 73 20 46 6f 73 73 69 6c 2c 20 eter is Fossil,
1320: 61 6e 64 20 74 68 65 20 61 72 67 75 6d 65 6e 74 and the argument
1330: 20 6d 69 67 68 74 0a 62 65 20 73 6f 6d 65 74 68 might.be someth
1340: 69 6e 67 20 6c 69 6b 65 20 22 2f 76 61 72 2f 77 ing like "/var/w
1350: 77 77 2f 63 67 69 2d 62 69 6e 2f 6f 6e 65 2f 74 ww/cgi-bin/one/t
1360: 77 6f 22 20 28 64 65 70 65 6e 64 69 6e 67 20 6f wo" (depending o
1370: 6e 20 68 6f 77 20 79 6f 75 72 0a 70 61 72 74 69 n how your.parti
1380: 63 75 6c 61 72 20 77 65 62 20 73 65 72 76 65 72 cular web server
1390: 20 69 73 20 63 6f 6e 66 69 67 75 72 65 64 29 2e is configured).
13a0: 0a 0a 54 68 65 20 46 6f 73 73 69 6c 20 70 72 6f ..The Fossil pro
13b0: 67 72 61 6d 20 74 68 61 74 20 69 73 20 72 75 6e gram that is run
13c0: 20 61 73 20 74 68 65 20 73 63 72 69 70 74 20 69 as the script i
13d0: 6e 74 65 72 70 72 65 74 65 72 0a 69 73 20 74 68 nterpreter.is th
13e0: 65 20 73 61 6d 65 20 46 6f 73 73 69 6c 20 74 68 e same Fossil th
13f0: 61 74 20 72 75 6e 73 20 77 68 65 6e 0a 79 6f 75 at runs when.you
1400: 20 74 79 70 65 20 6f 72 64 69 6e 61 72 79 20 46 type ordinary F
1410: 6f 73 73 69 6c 20 63 6f 6d 6d 61 6e 64 73 20 6c ossil commands l
1420: 69 6b 65 20 22 66 6f 73 73 69 6c 20 73 79 6e 63 ike "fossil sync
1430: 22 20 6f 72 20 22 66 6f 73 73 69 6c 20 63 6f 6d " or "fossil com
1440: 6d 69 74 22 2e 0a 42 75 74 20 69 6e 20 74 68 69 mit"..But in thi
1450: 73 20 63 61 73 65 2c 20 61 73 20 73 6f 6f 6e 20 s case, as soon
1460: 61 73 20 69 74 20 6c 61 75 6e 63 68 65 73 2c 20 as it launches,
1470: 74 68 65 20 46 6f 73 73 69 6c 20 70 72 6f 67 72 the Fossil progr
1480: 61 6d 0a 72 65 63 6f 67 6e 69 7a 65 73 20 74 68 am.recognizes th
1490: 61 74 20 74 68 65 20 47 41 54 45 57 41 59 5f 49 at the GATEWAY_I
14a0: 4e 54 45 52 46 41 43 45 20 65 6e 76 69 72 6f 6e NTERFACE environ
14b0: 6d 65 6e 74 20 76 61 72 69 61 62 6c 65 20 69 73 ment variable is
14c0: 0a 73 65 74 20 74 6f 20 22 43 47 49 2f 31 2e 30 .set to "CGI/1.0
14d0: 22 20 61 6e 64 20 69 74 20 74 68 65 72 65 66 6f " and it therefo
14e0: 72 65 20 6b 6e 6f 77 73 20 74 68 61 74 20 69 74 re knows that it
14f0: 20 69 73 20 62 65 69 6e 67 20 75 73 65 64 20 61 is being used a
1500: 73 0a 43 47 49 20 72 61 74 68 65 72 20 74 68 61 s.CGI rather tha
1510: 6e 20 61 73 20 61 6e 20 6f 72 64 69 6e 61 72 79 n as an ordinary
1520: 20 63 6f 6d 6d 61 6e 64 2d 6c 69 6e 65 20 74 6f command-line to
1530: 6f 6c 2c 20 61 6e 64 20 62 65 68 61 76 65 73 20 ol, and behaves
1540: 61 63 63 6f 72 64 69 6e 67 6c 79 2e 0a 0a 57 68 accordingly...Wh
1550: 65 6e 20 46 6f 73 73 69 6c 20 72 65 63 6f 67 6e en Fossil recogn
1560: 69 7a 65 73 20 74 68 61 74 20 69 74 20 69 73 20 izes that it is
1570: 62 65 69 6e 67 20 72 75 6e 20 61 73 20 43 47 49 being run as CGI
1580: 2c 20 69 74 20 6f 70 65 6e 73 20 61 6e 64 20 72 , it opens and r
1590: 65 61 64 73 0a 74 68 65 20 66 69 6c 65 20 69 64 eads.the file id
15a0: 65 6e 74 69 66 69 65 64 20 62 79 20 69 74 73 20 entified by its
15b0: 73 6f 6c 65 20 61 72 67 75 6d 65 6e 74 20 28 74 sole argument (t
15c0: 68 65 20 66 69 6c 65 20 6e 61 6d 65 64 20 62 79 he file named by
15d0: 0a 3c 63 6f 64 65 3e 61 72 67 76 26 23 39 31 3b .<code>argv[
15e0: 31 26 23 39 33 3b 3c 2f 63 6f 64 65 3e 29 2e 20 1]</code>).
15f0: 20 49 6e 20 6f 75 72 20 65 78 61 6d 70 6c 65 2c In our example,
1600: 20 74 68 65 20 73 65 63 6f 6e 64 20 6c 69 6e 65 the second line
1610: 20 6f 66 20 74 68 61 74 20 66 69 6c 65 0a 74 65 of that file.te
1620: 6c 6c 73 20 46 6f 73 73 69 6c 20 74 68 65 20 6c lls Fossil the l
1630: 6f 63 61 74 69 6f 6e 20 6f 66 20 74 68 65 20 72 ocation of the r
1640: 65 70 6f 73 69 74 6f 72 79 20 69 74 20 77 69 6c epository it wil
1650: 6c 20 62 65 20 73 65 72 76 69 6e 67 2e 0a 46 6f l be serving..Fo
1660: 73 73 69 6c 20 74 68 65 6e 20 73 74 61 72 74 73 ssil then starts
1670: 20 6c 6f 6f 6b 69 6e 67 20 61 74 20 74 68 65 20 looking at the
1680: 43 47 49 20 65 6e 76 69 72 6f 6e 6d 65 6e 74 20 CGI environment
1690: 76 61 72 69 61 62 6c 65 73 20 74 6f 20 66 69 67 variables to fig
16a0: 75 72 65 0a 6f 75 74 20 77 68 61 74 20 77 65 62 ure.out what web
16b0: 20 70 61 67 65 20 69 73 20 62 65 69 6e 67 20 72 page is being r
16c0: 65 71 75 65 73 74 65 64 2c 20 67 65 6e 65 72 61 equested, genera
16d0: 74 65 73 20 74 68 61 74 20 6f 6e 65 20 77 65 62 tes that one web
16e0: 20 70 61 67 65 2c 0a 74 68 65 6e 20 65 78 69 74 page,.then exit
16f0: 73 2e 0a 0a 55 73 75 61 6c 6c 79 2c 20 74 68 65 s...Usually, the
1700: 20 77 65 62 70 61 67 65 20 62 65 69 6e 67 20 72 webpage being r
1710: 65 71 75 65 73 74 65 64 20 69 73 20 74 68 65 20 equested is the
1720: 66 69 72 73 74 20 74 65 72 6d 20 6f 66 20 74 68 first term of th
1730: 65 0a 50 41 54 48 5f 49 4e 46 4f 20 65 6e 76 69 e.PATH_INFO envi
1740: 72 6f 6e 6d 65 6e 74 20 76 61 72 69 61 62 6c 65 ronment variable
1750: 2e 20 20 28 45 78 63 65 70 74 69 6f 6e 73 20 74 . (Exceptions t
1760: 6f 20 74 68 69 73 20 72 75 6c 65 20 61 72 65 20 o this rule are
1770: 6e 6f 74 65 64 0a 69 6e 20 74 68 65 20 73 65 71 noted.in the seq
1780: 75 65 6c 2e 29 20 20 46 6f 72 20 6f 75 72 20 65 uel.) For our e
1790: 78 61 6d 70 6c 65 2c 20 74 68 65 20 66 69 72 73 xample, the firs
17a0: 74 20 74 65 72 6d 20 6f 66 20 50 41 54 48 5f 49 t term of PATH_I
17b0: 4e 46 4f 0a 69 73 20 22 74 69 6d 65 6c 69 6e 65 NFO.is "timeline
17c0: 22 2c 20 77 68 69 63 68 20 6d 65 61 6e 73 20 74 ", which means t
17d0: 68 61 74 20 46 6f 73 73 69 6c 20 77 69 6c 6c 20 hat Fossil will
17e0: 67 65 6e 65 72 61 74 65 0a 74 68 65 20 5b 2f 68 generate.the [/h
17f0: 65 6c 70 3f 63 6d 64 3d 2f 74 69 6d 65 6c 69 6e elp?cmd=/timelin
1800: 65 7c 2f 74 69 6d 65 6c 69 6e 65 5d 20 77 65 62 e|/timeline] web
1810: 70 61 67 65 2e 0a 0a 57 69 74 68 20 46 6f 73 73 page...With Foss
1820: 69 6c 2c 20 74 65 72 6d 73 20 6f 66 20 50 41 54 il, terms of PAT
1830: 48 5f 49 4e 46 4f 20 62 65 79 6f 6e 64 20 74 68 H_INFO beyond th
1840: 65 20 77 65 62 70 61 67 65 20 6e 61 6d 65 20 61 e webpage name a
1850: 72 65 20 63 6f 6e 76 65 72 74 65 64 20 69 6e 74 re converted int
1860: 6f 0a 74 68 65 20 22 6e 61 6d 65 22 20 71 75 65 o.the "name" que
1870: 72 79 20 70 61 72 61 6d 65 74 65 72 2e 20 20 48 ry parameter. H
1880: 65 6e 63 65 2c 20 74 68 65 20 66 6f 6c 6c 6f 77 ence, the follow
1890: 69 6e 67 20 74 77 6f 20 55 52 4c 73 20 6d 65 61 ing two URLs mea
18a0: 6e 0a 65 78 61 63 74 6c 79 20 74 68 65 20 73 61 n.exactly the sa
18b0: 6d 65 20 74 68 69 6e 67 20 74 6f 20 46 6f 73 73 me thing to Foss
18c0: 69 6c 3a 0a 3c 6f 6c 20 74 79 70 65 3d 27 41 27 il:.<ol type='A'
18d0: 3e 0a 3c 6c 69 3e 20 5b 68 74 74 70 73 3a 2f 2f >.<li> [https://
18e0: 66 6f 73 73 69 6c 2d 73 63 6d 2e 6f 72 67 2f 68 fossil-scm.org/h
18f0: 6f 6d 65 2f 69 6e 66 6f 2f 63 31 34 65 63 63 34 ome/info/c14ecc4
1900: 33 5d 0a 3c 6c 69 3e 20 5b 68 74 74 70 73 3a 2f 3].<li> [https:/
1910: 2f 66 6f 73 73 69 6c 2d 73 63 6d 2e 6f 72 67 2f /fossil-scm.org/
1920: 68 6f 6d 65 2f 69 6e 66 6f 3f 6e 61 6d 65 3d 63 home/info?name=c
1930: 31 34 65 63 63 34 33 5d 0a 3c 2f 6f 6c 3e 0a 0a 14ecc43].</ol>..
1940: 49 6e 20 62 6f 74 68 20 63 61 73 65 73 2c 20 74 In both cases, t
1950: 68 65 20 43 47 49 20 73 63 72 69 70 74 20 69 73 he CGI script is
1960: 20 63 61 6c 6c 65 64 20 22 2f 66 6f 73 73 69 6c called "/fossil
1970: 22 2e 20 20 46 6f 72 20 63 61 73 65 20 28 41 29 ". For case (A)
1980: 2c 0a 74 68 65 20 50 41 54 48 5f 49 4e 46 4f 20 ,.the PATH_INFO
1990: 76 61 72 69 61 62 6c 65 20 77 69 6c 6c 20 62 65 variable will be
19a0: 20 22 69 6e 66 6f 2f 63 31 34 65 63 63 34 33 22 "info/c14ecc43"
19b0: 20 61 6e 64 20 73 6f 20 74 68 65 0a 22 5b 2f 68 and so the."[/h
19c0: 65 6c 70 3f 63 6d 64 3d 2f 69 6e 66 6f 7c 2f 69 elp?cmd=/info|/i
19d0: 6e 66 6f 5d 22 20 77 65 62 70 61 67 65 20 77 69 nfo]" webpage wi
19e0: 6c 6c 20 62 65 20 67 65 6e 65 72 61 74 65 64 20 ll be generated
19f0: 61 6e 64 20 74 68 65 20 73 75 66 66 69 78 20 6f and the suffix o
1a00: 66 0a 50 41 54 48 5f 49 4e 46 4f 20 77 69 6c 6c f.PATH_INFO will
1a10: 20 62 65 20 63 6f 6e 76 65 72 74 65 64 20 69 6e be converted in
1a20: 74 6f 20 74 68 65 20 22 6e 61 6d 65 22 20 71 75 to the "name" qu
1a30: 65 72 79 20 70 61 72 61 6d 65 74 65 72 2c 20 77 ery parameter, w
1a40: 68 69 63 68 0a 69 64 65 6e 74 69 66 69 65 73 20 hich.identifies
1a50: 74 68 65 20 61 72 74 69 66 61 63 74 20 61 62 6f the artifact abo
1a60: 75 74 20 77 68 69 63 68 20 69 6e 66 6f 72 6d 61 ut which informa
1a70: 74 69 6f 6e 20 69 73 20 72 65 71 75 65 73 74 65 tion is requeste
1a80: 64 2e 0a 49 6e 20 63 61 73 65 20 28 42 29 2c 20 d..In case (B),
1a90: 74 68 65 20 50 41 54 48 5f 49 4e 46 4f 20 69 73 the PATH_INFO is
1aa0: 20 6a 75 73 74 20 22 69 6e 66 6f 22 2c 20 62 75 just "info", bu
1ab0: 74 20 74 68 65 20 73 61 6d 65 20 22 6e 61 6d 65 t the same "name
1ac0: 22 0a 71 75 65 72 79 20 70 61 72 61 6d 65 74 65 ".query paramete
1ad0: 72 20 69 73 20 73 65 74 20 65 78 70 6c 69 63 69 r is set explici
1ae0: 74 6c 79 20 62 79 20 74 68 65 20 55 52 4c 20 69 tly by the URL i
1af0: 74 73 65 6c 66 2e 0a 0a 3c 68 32 3e 53 65 72 76 tself...<h2>Serv
1b00: 69 6e 67 20 4d 75 6c 74 69 70 6c 65 20 46 6f 73 ing Multiple Fos
1b10: 73 69 6c 20 52 65 70 6f 73 69 74 6f 72 69 65 73 sil Repositories
1b20: 20 46 72 6f 6d 20 4f 6e 65 20 43 47 49 20 53 63 From One CGI Sc
1b30: 72 69 70 74 3c 2f 68 32 3e 0a 0a 54 68 65 20 70 ript</h2>..The p
1b40: 72 65 76 69 6f 75 73 20 65 78 61 6d 70 6c 65 20 revious example
1b50: 73 68 6f 77 65 64 20 68 6f 77 20 74 6f 20 73 65 showed how to se
1b60: 72 76 65 20 61 20 73 69 6e 67 6c 65 20 46 6f 73 rve a single Fos
1b70: 73 69 6c 20 72 65 70 6f 73 69 74 6f 72 79 0a 75 sil repository.u
1b80: 73 69 6e 67 20 61 20 73 69 6e 67 6c 65 20 43 47 sing a single CG
1b90: 49 20 73 63 72 69 70 74 2e 0a 4f 6e 20 61 20 77 I script..On a w
1ba0: 65 62 73 69 74 65 20 74 68 61 74 20 77 61 6e 74 ebsite that want
1bb0: 73 20 74 6f 20 73 65 72 76 65 20 6d 75 6c 74 69 s to serve multi
1bc0: 70 6c 65 20 72 65 70 6f 73 69 74 6f 72 69 65 73 ple repositories
1bd0: 2c 20 6f 6e 65 20 63 6f 75 6c 64 0a 73 69 6d 70 , one could.simp
1be0: 6c 79 20 63 72 65 61 74 65 20 6d 75 6c 74 69 70 ly create multip
1bf0: 6c 65 20 43 47 49 20 73 63 72 69 70 74 73 2c 20 le CGI scripts,
1c00: 6f 6e 65 20 73 63 72 69 70 74 20 66 6f 72 20 65 one script for e
1c10: 61 63 68 20 72 65 70 6f 73 69 74 6f 72 79 2e 0a ach repository..
1c20: 42 75 74 20 69 74 20 69 73 20 61 6c 73 6f 20 70 But it is also p
1c30: 6f 73 73 69 62 6c 65 20 74 6f 20 73 65 72 76 65 ossible to serve
1c40: 20 6d 75 6c 74 69 70 6c 65 20 46 6f 73 73 69 6c multiple Fossil
1c50: 20 72 65 70 6f 73 69 74 6f 72 69 65 73 20 66 72 repositories fr
1c60: 6f 6d 0a 61 20 73 69 6e 67 6c 65 20 43 47 49 20 om.a single CGI
1c70: 73 63 72 69 70 74 2e 0a 0a 49 66 20 74 68 65 20 script...If the
1c80: 43 47 49 20 73 63 72 69 70 74 20 66 6f 72 20 46 CGI script for F
1c90: 6f 73 73 69 6c 20 63 6f 6e 74 61 69 6e 73 20 61 ossil contains a
1ca0: 20 22 64 69 72 65 63 74 6f 72 79 3a 22 20 6c 69 "directory:" li
1cb0: 6e 65 20 69 6e 73 74 65 61 64 20 6f 66 0a 61 20 ne instead of.a
1cc0: 22 72 65 70 6f 73 69 74 6f 72 79 3a 22 20 6c 69 "repository:" li
1cd0: 6e 65 2c 20 74 68 65 6e 20 74 68 65 20 61 72 67 ne, then the arg
1ce0: 75 6d 65 6e 74 20 74 6f 20 22 64 69 72 65 63 74 ument to "direct
1cf0: 6f 72 79 3a 22 20 69 73 20 74 68 65 20 6e 61 6d ory:" is the nam
1d00: 65 0a 6f 66 20 61 20 64 69 72 65 63 74 6f 72 79 e.of a directory
1d10: 20 74 68 61 74 20 63 6f 6e 74 61 69 6e 73 20 6d that contains m
1d20: 75 6c 74 69 70 6c 65 20 72 65 70 6f 73 69 74 6f ultiple reposito
1d30: 72 79 20 66 69 6c 65 73 2c 20 65 61 63 68 20 65 ry files, each e
1d40: 6e 64 69 6e 67 0a 77 69 74 68 20 22 2e 66 6f 73 nding.with ".fos
1d50: 73 69 6c 22 2e 20 20 46 6f 72 20 65 78 61 6d 70 sil". For examp
1d60: 6c 65 3a 0a 0a 3c 70 72 65 3e 0a 23 21 2f 75 73 le:..<pre>.#!/us
1d70: 72 2f 62 69 6e 2f 66 6f 73 73 69 6c 0a 64 69 72 r/bin/fossil.dir
1d80: 65 63 74 6f 72 79 3a 20 2f 68 6f 6d 65 2f 77 77 ectory: /home/ww
1d90: 77 2f 72 65 70 6f 73 0a 3c 2f 70 72 65 3e 0a 0a w/repos.</pre>..
1da0: 53 75 70 70 6f 73 65 20 74 68 65 20 2f 68 6f 6d Suppose the /hom
1db0: 65 2f 77 77 77 2f 72 65 70 6f 73 20 64 69 72 65 e/www/repos dire
1dc0: 63 74 6f 72 79 20 63 6f 6e 74 61 69 6e 73 20 66 ctory contains f
1dd0: 69 6c 65 73 20 6e 61 6d 65 64 0a 3c 62 3e 6f 6e iles named.<b>on
1de0: 65 2e 66 6f 73 73 69 6c 3c 2f 62 3e 2c 20 3c 62 e.fossil</b>, <b
1df0: 3e 74 77 6f 2e 66 6f 73 73 69 6c 3c 2f 62 3e 2c >two.fossil</b>,
1e00: 20 61 6e 64 20 3c 62 3e 73 75 62 64 69 72 2f 74 and <b>subdir/t
1e10: 68 72 65 65 2e 66 6f 73 73 69 6c 3c 2f 62 3e 2e hree.fossil</b>.
1e20: 0a 46 75 72 74 68 65 72 20 73 75 70 70 6f 73 65 .Further suppose
1e30: 20 74 68 61 74 20 74 68 65 20 6e 61 6d 65 20 6f that the name o
1e40: 66 20 74 68 65 20 43 47 49 20 73 63 72 69 70 74 f the CGI script
1e50: 20 28 72 65 6c 61 74 69 76 65 20 74 6f 20 74 68 (relative to th
1e60: 65 20 72 6f 6f 74 0a 6f 66 20 74 68 65 20 77 65 e root.of the we
1e70: 62 73 65 72 76 65 72 20 64 6f 63 75 6d 65 6e 74 bserver document
1e80: 20 61 72 65 61 29 20 69 73 20 22 63 67 69 73 2f area) is "cgis/
1e90: 65 78 61 6d 70 6c 65 32 22 2e 20 20 54 68 65 6e example2". Then
1ea0: 20 74 6f 0a 73 65 65 20 74 68 65 20 74 69 6d 65 to.see the time
1eb0: 6c 69 6e 65 20 66 6f 72 20 74 68 65 20 22 74 68 line for the "th
1ec0: 72 65 65 2e 66 6f 73 73 69 6c 22 20 72 65 70 6f ree.fossil" repo
1ed0: 73 69 74 6f 72 79 2c 20 74 68 65 20 55 52 4c 20 sitory, the URL
1ee0: 77 6f 75 6c 64 20 62 65 3a 0a 0a 3c 70 72 65 3e would be:..<pre>
1ef0: 0a 68 74 74 70 3a 2f 2f 65 78 61 6d 70 6c 65 2e .http://example.
1f00: 63 6f 6d 2f 63 67 69 73 2f 65 78 61 6d 70 6c 65 com/cgis/example
1f10: 32 2f 73 75 62 64 69 72 2f 74 68 72 65 65 2f 74 2/subdir/three/t
1f20: 69 6d 65 6c 69 6e 65 0a 3c 2f 70 72 65 3e 0a 0a imeline.</pre>..
1f30: 48 65 72 65 20 69 73 20 77 68 61 74 20 68 61 70 Here is what hap
1f40: 70 65 6e 73 3a 0a 3c 6f 6c 3e 0a 3c 6c 69 3e 20 pens:.<ol>.<li>
1f50: 54 68 65 20 69 6e 70 75 74 20 55 52 49 20 6f 6e The input URI on
1f60: 20 74 68 65 20 48 54 54 50 20 72 65 71 75 65 73 the HTTP reques
1f70: 74 20 69 73 0a 20 20 20 20 20 3c 62 3e 2f 63 67 t is. <b>/cg
1f80: 69 73 2f 65 78 61 6d 70 6c 65 32 2f 73 75 62 64 is/example2/subd
1f90: 69 72 2f 74 68 72 65 65 2f 74 69 6d 65 6c 69 6e ir/three/timelin
1fa0: 65 3c 2f 62 3e 0a 3c 6c 69 3e 20 54 68 65 20 77 e</b>.<li> The w
1fb0: 65 62 20 73 65 72 76 65 72 20 73 65 61 72 63 68 eb server search
1fc0: 65 73 20 70 72 65 66 69 78 65 73 20 6f 66 20 74 es prefixes of t
1fd0: 68 65 20 69 6e 70 75 74 20 55 52 49 20 75 6e 74 he input URI unt
1fe0: 69 6c 20 69 74 20 66 69 6e 64 73 0a 20 20 20 20 il it finds.
1ff0: 20 74 68 65 20 22 63 67 69 73 2f 65 78 61 6d 70 the "cgis/examp
2000: 6c 65 32 22 20 73 63 72 69 70 74 2e 20 20 54 68 le2" script. Th
2010: 65 20 77 65 62 20 73 65 72 76 65 72 20 74 68 65 e web server the
2020: 6e 20 73 65 74 73 0a 20 20 20 20 20 50 41 54 48 n sets. PATH
2030: 5f 49 4e 46 4f 20 74 6f 20 74 68 65 20 22 73 75 _INFO to the "su
2040: 62 64 69 72 2f 74 68 72 65 65 2f 74 69 6d 65 6c bdir/three/timel
2050: 69 6e 65 22 20 73 75 66 66 69 78 20 61 6e 64 20 ine" suffix and
2060: 69 6e 76 6f 6b 65 73 20 74 68 65 0a 20 20 20 20 invokes the.
2070: 20 22 63 67 69 73 2f 65 78 61 6d 70 6c 65 32 22 "cgis/example2"
2080: 20 73 63 72 69 70 74 2e 0a 3c 6c 69 3e 20 46 6f script..<li> Fo
2090: 73 73 69 6c 20 72 75 6e 73 20 61 6e 64 20 73 65 ssil runs and se
20a0: 65 73 20 74 68 65 20 22 64 69 72 65 63 74 6f 72 es the "director
20b0: 79 3a 22 20 6c 69 6e 65 20 70 6f 69 6e 74 69 6e y:" line pointin
20c0: 67 20 74 6f 0a 20 20 20 20 20 22 2f 68 6f 6d 65 g to. "/home
20d0: 2f 77 77 77 2f 72 65 70 6f 73 22 2e 20 20 46 6f /www/repos". Fo
20e0: 73 73 69 6c 20 74 68 65 6e 20 73 74 61 72 74 73 ssil then starts
20f0: 20 70 75 6c 6c 69 6e 67 20 74 65 72 6d 73 20 6f pulling terms o
2100: 66 66 20 74 68 65 0a 20 20 20 20 20 66 72 6f 6e ff the. fron
2110: 74 20 6f 66 20 74 68 65 20 50 41 54 48 5f 49 4e t of the PATH_IN
2120: 46 4f 20 6c 6f 6f 6b 69 6e 67 20 66 6f 72 20 61 FO looking for a
2130: 20 72 65 70 6f 73 69 74 6f 72 79 2e 20 20 49 74 repository. It
2140: 20 66 69 72 73 74 20 6c 6f 6f 6b 73 0a 20 20 20 first looks.
2150: 20 20 61 74 20 22 2f 68 6f 6d 65 2f 77 77 77 2f at "/home/www/
2160: 72 65 73 70 73 2f 73 75 62 64 69 72 2e 66 6f 73 resps/subdir.fos
2170: 73 69 6c 22 20 62 75 74 20 74 68 65 72 65 20 69 sil" but there i
2180: 73 20 6e 6f 20 73 75 63 68 20 72 65 70 6f 73 69 s no such reposi
2190: 74 6f 72 79 2e 0a 20 20 20 20 20 53 6f 20 74 68 tory.. So th
21a0: 65 6e 20 69 74 20 6c 6f 6f 6b 73 20 61 74 20 22 en it looks at "
21b0: 2f 68 6f 6d 65 2f 77 77 77 2f 72 65 70 6f 73 2f /home/www/repos/
21c0: 73 75 62 64 69 72 2f 74 68 72 65 65 2e 66 6f 73 subdir/three.fos
21d0: 73 69 6c 22 20 61 6e 64 20 66 69 6e 64 73 0a 20 sil" and finds.
21e0: 20 20 20 20 61 20 72 65 70 6f 73 69 74 6f 72 79 a repository
21f0: 2e 20 20 54 68 65 20 50 41 54 48 5f 49 4e 46 4f . The PATH_INFO
2200: 20 69 73 20 73 68 6f 72 74 65 6e 65 64 20 62 79 is shortened by
2210: 20 72 65 6d 6f 76 69 6e 67 0a 20 20 20 20 20 22 removing. "
2220: 73 75 62 64 69 72 2f 74 68 72 65 65 2f 22 20 6c subdir/three/" l
2230: 65 61 76 69 6e 67 20 69 74 20 61 74 20 6a 75 73 eaving it at jus
2240: 74 20 22 74 69 6d 65 6c 69 6e 65 22 2e 0a 3c 6c t "timeline"..<l
2250: 69 3e 20 46 6f 73 73 69 6c 20 6c 6f 6f 6b 73 20 i> Fossil looks
2260: 61 74 20 74 68 65 20 72 65 73 74 20 6f 66 20 50 at the rest of P
2270: 41 54 48 5f 49 4e 46 4f 20 74 6f 20 73 65 65 20 ATH_INFO to see
2280: 74 68 61 74 20 74 68 65 20 77 65 62 70 61 67 65 that the webpage
2290: 0a 20 20 20 20 20 72 65 71 75 65 73 74 65 64 20 . requested
22a0: 69 73 20 22 74 69 6d 65 6c 69 6e 65 22 2e 0a 3c is "timeline"..<
22b0: 2f 6f 6c 3e 0a 3c 61 20 69 64 3d 22 63 67 69 76 /ol>.<a id="cgiv
22c0: 61 72 22 3e 3c 2f 61 3e 0a 0a 54 68 65 20 77 65 ar"></a>..The we
22d0: 62 20 73 65 72 76 65 72 20 73 65 74 73 20 6d 61 b server sets ma
22e0: 6e 79 20 65 6e 76 69 72 6f 6e 6d 65 6e 74 20 76 ny environment v
22f0: 61 72 69 61 62 6c 65 73 20 69 6e 20 73 74 65 70 ariables in step
2300: 20 32 20 69 6e 20 61 64 64 69 74 69 6f 6e 0a 74 2 in addition.t
2310: 6f 20 6a 75 73 74 20 50 41 54 48 5f 49 4e 46 4f o just PATH_INFO
2320: 2e 20 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 . The following
2330: 20 64 69 61 67 72 61 6d 20 73 68 6f 77 73 20 61 diagram shows a
2340: 20 66 65 77 20 6f 66 20 74 68 65 73 65 20 76 61 few of these va
2350: 72 69 61 62 6c 65 73 0a 61 6e 64 20 74 68 65 69 riables.and thei
2360: 72 20 72 65 6c 61 74 69 6f 6e 73 68 69 70 20 74 r relationship t
2370: 6f 20 74 68 65 20 72 65 71 75 65 73 74 20 55 52 o the request UR
2380: 4c 3a 0a 0a 3c 76 65 72 62 61 74 69 6d 20 74 79 L:..<verbatim ty
2390: 70 65 3d 22 70 69 6b 63 68 72 22 3e 0a 63 68 61 pe="pikchr">.cha
23a0: 72 77 69 64 20 3d 20 30 2e 30 37 35 0a 74 68 69 rwid = 0.075.thi
23b0: 63 6b 6e 65 73 73 20 3d 20 30 0a 0a 53 43 48 45 ckness = 0..SCHE
23c0: 4d 45 3a 20 62 6f 78 20 22 68 74 74 70 73 3a 2f ME: box "https:/
23d0: 2f 22 20 6d 6f 6e 6f 20 66 69 74 0a 44 4f 4d 41 /" mono fit.DOMA
23e0: 49 4e 3a 20 62 6f 78 20 22 65 78 61 6d 70 6c 65 IN: box "example
23f0: 2e 63 6f 6d 22 20 6d 6f 6e 6f 20 66 69 74 0a 53 .com" mono fit.S
2400: 43 52 49 50 54 3a 20 62 6f 78 20 22 2f 63 67 69 CRIPT: box "/cgi
2410: 73 2f 65 78 61 6d 70 6c 65 32 22 20 6d 6f 6e 6f s/example2" mono
2420: 20 66 69 74 0a 50 41 54 48 3a 20 20 20 62 6f 78 fit.PATH: box
2430: 20 22 2f 73 75 62 64 69 72 2f 74 68 72 65 65 2f "/subdir/three/
2440: 74 69 6d 65 6c 69 6e 65 22 20 6d 6f 6e 6f 20 66 timeline" mono f
2450: 69 74 0a 51 55 45 52 59 3a 20 20 62 6f 78 20 22 it.QUERY: box "
2460: 3f 63 3d 35 35 64 37 65 31 22 20 6d 6f 6e 6f 20 ?c=55d7e1" mono
2470: 66 69 74 0a 0a 74 68 69 63 6b 6e 65 73 73 20 3d fit..thickness =
2480: 20 30 2e 30 31 0a 0a 44 42 3a 20 62 6f 78 20 61 0.01..DB: box a
2490: 74 20 30 2e 33 20 62 65 6c 6f 77 20 44 4f 4d 41 t 0.3 below DOMA
24a0: 49 4e 20 22 48 54 54 50 5f 48 4f 53 54 22 20 20 IN "HTTP_HOST"
24b0: 20 20 6d 6f 6e 6f 20 66 69 74 20 69 6e 76 69 73 mono fit invis
24c0: 0a 53 42 3a 20 62 6f 78 20 61 74 20 30 2e 33 20 .SB: box at 0.3
24d0: 62 65 6c 6f 77 20 53 43 52 49 50 54 20 22 53 43 below SCRIPT "SC
24e0: 52 49 50 54 5f 4e 41 4d 45 22 20 20 6d 6f 6e 6f RIPT_NAME" mono
24f0: 20 66 69 74 20 69 6e 76 69 73 0a 50 42 3a 20 62 fit invis.PB: b
2500: 6f 78 20 61 74 20 30 2e 33 20 62 65 6c 6f 77 20 ox at 0.3 below
2510: 50 41 54 48 20 20 20 22 50 41 54 48 5f 49 4e 46 PATH "PATH_INF
2520: 4f 22 20 20 20 20 6d 6f 6e 6f 20 66 69 74 20 69 O" mono fit i
2530: 6e 76 69 73 0a 51 42 3a 20 62 6f 78 20 61 74 20 nvis.QB: box at
2540: 30 2e 33 20 62 65 6c 6f 77 20 51 55 45 52 59 20 0.3 below QUERY
2550: 20 22 51 55 45 52 59 5f 53 54 52 49 4e 47 22 20 "QUERY_STRING"
2560: 6d 6f 6e 6f 20 66 69 74 20 69 6e 76 69 73 0a 52 mono fit invis.R
2570: 42 3a 20 62 6f 78 20 61 74 20 30 2e 35 20 61 62 B: box at 0.5 ab
2580: 6f 76 65 20 50 41 54 48 20 20 20 22 52 45 51 55 ove PATH "REQU
2590: 45 53 54 5f 55 52 49 22 20 20 6d 6f 6e 6f 20 66 EST_URI" mono f
25a0: 69 74 20 69 6e 76 69 73 0a 0a 63 6f 6c 6f 72 20 it invis..color
25b0: 3d 20 6c 69 67 68 74 67 72 61 79 0a 0a 62 6f 78 = lightgray..box
25c0: 20 61 74 20 53 43 48 45 4d 45 20 77 69 64 74 68 at SCHEME width
25d0: 20 53 43 48 45 4d 45 2e 77 69 64 74 68 20 68 65 SCHEME.width he
25e0: 69 67 68 74 20 53 43 48 45 4d 45 2e 68 65 69 67 ight SCHEME.heig
25f0: 68 74 0a 6c 69 6e 65 20 66 69 6c 6c 20 30 78 37 ht.line fill 0x7
2600: 37 39 39 43 43 20 62 65 68 69 6e 64 20 51 55 45 799CC behind QUE
2610: 52 59 20 5c 0a 20 20 66 72 6f 6d 20 53 43 52 49 RY \. from SCRI
2620: 50 54 2e 6e 77 20 5c 0a 20 20 20 20 74 6f 20 52 PT.nw \. to R
2630: 42 2e 73 77 20 5c 0a 20 20 20 20 74 6f 20 52 42 B.sw \. to RB
2640: 2e 73 65 20 5c 0a 20 20 20 20 74 6f 20 51 55 45 .se \. to QUE
2650: 52 59 2e 6e 65 20 5c 0a 20 20 63 6c 6f 73 65 0a RY.ne \. close.
2660: 6c 69 6e 65 20 66 69 6c 6c 20 30 78 39 39 43 43 line fill 0x99CC
2670: 46 46 20 62 65 68 69 6e 64 20 44 4f 4d 41 49 4e FF behind DOMAIN
2680: 20 5c 0a 20 20 66 72 6f 6d 20 44 4f 4d 41 49 4e \. from DOMAIN
2690: 2e 6e 77 20 5c 0a 20 20 20 20 74 6f 20 44 4f 4d .nw \. to DOM
26a0: 41 49 4e 2e 73 77 20 5c 0a 20 20 20 20 74 6f 20 AIN.sw \. to
26b0: 44 42 2e 6e 20 5c 0a 20 20 20 20 74 6f 20 44 4f DB.n \. to DO
26c0: 4d 41 49 4e 2e 73 65 20 5c 0a 20 20 20 20 74 6f MAIN.se \. to
26d0: 20 44 4f 4d 41 49 4e 2e 6e 65 20 5c 0a 20 20 63 DOMAIN.ne \. c
26e0: 6c 6f 73 65 0a 6c 69 6e 65 20 66 69 6c 6c 20 30 lose.line fill 0
26f0: 78 43 43 45 45 46 46 20 62 65 68 69 6e 64 20 53 xCCEEFF behind S
2700: 43 52 49 50 54 20 5c 0a 20 20 66 72 6f 6d 20 53 CRIPT \. from S
2710: 43 52 49 50 54 2e 6e 77 20 5c 0a 20 20 20 20 74 CRIPT.nw \. t
2720: 6f 20 53 43 52 49 50 54 2e 73 77 20 5c 0a 20 20 o SCRIPT.sw \.
2730: 20 20 74 6f 20 53 42 2e 6e 20 5c 0a 20 20 20 20 to SB.n \.
2740: 74 6f 20 53 43 52 49 50 54 2e 73 65 20 5c 0a 20 to SCRIPT.se \.
2750: 20 20 20 74 6f 20 53 43 52 49 50 54 2e 6e 65 20 to SCRIPT.ne
2760: 5c 0a 20 20 63 6c 6f 73 65 0a 6c 69 6e 65 20 66 \. close.line f
2770: 69 6c 6c 20 30 78 39 39 43 43 46 46 20 62 65 68 ill 0x99CCFF beh
2780: 69 6e 64 20 50 41 54 48 20 5c 0a 20 20 66 72 6f ind PATH \. fro
2790: 6d 20 50 41 54 48 2e 6e 77 20 5c 0a 20 20 20 20 m PATH.nw \.
27a0: 74 6f 20 50 41 54 48 2e 73 77 20 5c 0a 20 20 20 to PATH.sw \.
27b0: 20 74 6f 20 50 42 2e 6e 20 5c 0a 20 20 20 20 74 to PB.n \. t
27c0: 6f 20 50 41 54 48 2e 73 65 20 5c 0a 20 20 20 20 o PATH.se \.
27d0: 74 6f 20 50 41 54 48 2e 6e 65 20 5c 0a 20 20 63 to PATH.ne \. c
27e0: 6c 6f 73 65 0a 6c 69 6e 65 20 66 69 6c 6c 20 30 lose.line fill 0
27f0: 78 43 43 45 45 46 46 20 62 65 68 69 6e 64 20 51 xCCEEFF behind Q
2800: 55 45 52 59 20 5c 0a 20 20 66 72 6f 6d 20 51 55 UERY \. from QU
2810: 45 52 59 2e 6e 77 20 5c 0a 20 20 20 20 74 6f 20 ERY.nw \. to
2820: 51 55 45 52 59 2e 73 77 20 5c 0a 20 20 20 20 74 QUERY.sw \. t
2830: 6f 20 51 42 2e 6e 20 5c 0a 20 20 20 20 74 6f 20 o QB.n \. to
2840: 51 55 45 52 59 2e 73 65 20 5c 0a 20 20 20 20 74 QUERY.se \. t
2850: 6f 20 51 55 45 52 59 2e 6e 65 20 5c 0a 20 20 63 o QUERY.ne \. c
2860: 6c 6f 73 65 0a 3c 2f 76 65 72 62 61 74 69 6d 3e lose.</verbatim>
2870: 0a 0a 3c 68 32 3e 41 64 64 69 74 69 6f 6e 61 6c ..<h2>Additional
2880: 20 43 47 49 20 53 63 72 69 70 74 20 4f 70 74 69 CGI Script Opti
2890: 6f 6e 73 3c 2f 68 32 3e 0a 0a 54 68 65 20 43 47 ons</h2>..The CG
28a0: 49 20 73 63 72 69 70 74 20 63 61 6e 20 68 61 76 I script can hav
28b0: 65 20 61 64 64 69 74 69 6f 6e 61 6c 20 6f 70 74 e additional opt
28c0: 69 6f 6e 73 20 75 73 65 64 20 74 6f 20 66 69 6e ions used to fin
28d0: 65 2d 74 75 6e 65 0a 46 6f 73 73 69 6c 27 73 20 e-tune.Fossil's
28e0: 62 65 68 61 76 69 6f 72 2e 20 20 53 65 65 20 74 behavior. See t
28f0: 68 65 20 5b 2e 2f 63 67 69 2e 77 69 6b 69 7c 43 he [./cgi.wiki|C
2900: 47 49 20 73 63 72 69 70 74 20 64 6f 63 75 6d 65 GI script docume
2910: 6e 74 61 74 69 6f 6e 5d 0a 66 6f 72 20 64 65 74 ntation].for det
2920: 61 69 6c 73 2e 0a 0a 3c 68 32 3e 41 64 64 69 74 ails...<h2>Addit
2930: 69 6f 6e 61 6c 20 4f 62 73 65 72 76 61 74 69 6f ional Observatio
2940: 6e 73 3c 2f 68 32 3e 0a 3c 6f 6c 20 74 79 70 65 ns</h2>.<ol type
2950: 3d 22 49 22 3e 0a 3c 6c 69 3e 3c 70 3e 0a 46 6f ="I">.<li><p>.Fo
2960: 73 73 69 6c 20 64 6f 65 73 20 6e 6f 74 20 64 69 ssil does not di
2970: 73 74 69 6e 67 75 69 73 68 20 62 65 74 77 65 65 stinguish betwee
2980: 6e 20 74 68 65 20 76 61 72 69 6f 75 73 20 48 54 n the various HT
2990: 54 50 20 6d 65 74 68 6f 64 73 20 28 47 45 54 2c TP methods (GET,
29a0: 20 50 55 54 2c 0a 44 45 4c 45 54 45 2c 20 65 74 PUT,.DELETE, et
29b0: 63 29 2e 20 20 46 6f 73 73 69 6c 20 66 69 67 75 c). Fossil figu
29c0: 72 65 73 20 6f 75 74 20 77 68 61 74 20 69 74 20 res out what it
29d0: 6e 65 65 64 73 20 74 6f 20 64 6f 20 70 75 72 65 needs to do pure
29e0: 6c 79 20 66 72 6f 6d 20 74 68 65 0a 77 65 62 70 ly from the.webp
29f0: 61 67 65 20 74 65 72 6d 20 6f 66 20 74 68 65 20 age term of the
2a00: 55 52 49 2e 3c 2f 70 3e 3c 2f 6c 69 3e 0a 3c 6c URI.</p></li>.<l
2a10: 69 3e 3c 70 3e 0a 46 6f 73 73 69 6c 20 64 6f 65 i><p>.Fossil doe
2a20: 73 20 6e 6f 74 20 64 69 73 74 69 6e 67 75 69 73 s not distinguis
2a30: 68 20 62 65 74 77 65 65 6e 20 71 75 65 72 79 20 h between query
2a40: 70 61 72 61 6d 65 74 65 72 73 20 74 68 61 74 20 parameters that
2a50: 61 72 65 20 70 61 72 74 20 6f 66 20 74 68 65 0a are part of the.
2a60: 55 52 49 2c 20 61 70 70 6c 69 63 61 74 69 6f 6e URI, application
2a70: 2f 78 2d 77 77 77 2d 66 6f 72 6d 2d 75 72 6c 65 /x-www-form-urle
2a80: 6e 63 6f 64 65 64 20 6f 72 20 6d 75 6c 74 69 70 ncoded or multip
2a90: 61 72 74 2f 66 6f 72 6d 2d 64 61 74 61 20 65 6e art/form-data en
2aa0: 63 6f 64 65 64 0a 70 61 72 61 6d 65 74 65 72 20 coded.parameter
2ab0: 74 68 61 74 20 61 72 65 20 70 61 72 74 20 6f 66 that are part of
2ac0: 20 74 68 65 20 50 4f 53 54 20 63 6f 6e 74 65 6e the POST conten
2ad0: 74 2c 20 61 6e 64 20 63 6f 6f 6b 69 65 73 2e 20 t, and cookies.
2ae0: 20 45 61 63 68 20 69 6e 66 6f 72 6d 61 74 69 6f Each informatio
2af0: 6e 0a 73 6f 75 72 63 65 20 69 73 20 73 65 65 6e n.source is seen
2b00: 20 61 73 20 61 20 73 70 61 63 65 20 6f 66 20 6b as a space of k
2b10: 65 79 2f 76 61 6c 75 65 20 70 61 69 72 73 20 77 ey/value pairs w
2b20: 68 69 63 68 20 61 72 65 20 6c 6f 61 64 65 64 20 hich are loaded
2b30: 69 6e 74 6f 20 61 6e 0a 69 6e 74 65 72 6e 61 6c into an.internal
2b40: 20 70 72 6f 70 65 72 74 79 20 68 61 73 68 20 74 property hash t
2b50: 61 62 6c 65 2e 20 20 54 68 65 20 63 6f 64 65 20 able. The code
2b60: 74 68 61 74 20 72 75 6e 73 20 74 6f 20 67 65 6e that runs to gen
2b70: 65 72 61 74 65 20 74 68 65 20 72 65 70 6c 79 0a erate the reply.
2b80: 63 61 6e 20 74 68 65 6e 20 72 65 66 65 72 65 6e can then referen
2b90: 63 65 20 76 61 72 69 6f 75 73 20 70 72 6f 70 65 ce various prope
2ba0: 72 74 69 65 73 20 76 61 6c 75 65 73 2e 0a 46 6f rties values..Fo
2bb0: 73 73 69 6c 20 64 6f 65 73 20 6e 6f 74 20 63 61 ssil does not ca
2bc0: 72 65 20 77 68 65 72 65 20 74 68 65 20 76 61 6c re where the val
2bd0: 75 65 20 6f 66 20 65 61 63 68 20 70 72 6f 70 65 ue of each prope
2be0: 72 74 79 20 63 6f 6d 65 73 20 66 72 6f 6d 20 28 rty comes from (
2bf0: 50 4f 53 54 0a 63 6f 6e 74 65 6e 74 2c 20 63 6f POST.content, co
2c00: 6f 6b 69 65 73 2c 20 6f 72 20 71 75 65 72 79 20 okies, or query
2c10: 70 61 72 61 6d 65 74 65 72 73 29 20 6f 6e 6c 79 parameters) only
2c20: 20 74 68 61 74 20 74 68 65 20 70 72 6f 70 65 72 that the proper
2c30: 74 79 20 65 78 69 73 74 73 0a 61 6e 64 20 68 61 ty exists.and ha
2c40: 73 20 61 20 76 61 6c 75 65 2e 3c 2f 70 3e 3c 2f s a value.</p></
2c50: 6c 69 3e 0a 3c 6c 69 3e 3c 70 3e 0a 54 68 65 20 li>.<li><p>.The
2c60: 22 5b 2f 68 65 6c 70 3f 63 6d 64 3d 75 69 7c 66 "[/help?cmd=ui|f
2c70: 6f 73 73 69 6c 20 75 69 5d 22 20 61 6e 64 20 22 ossil ui]" and "
2c80: 5b 2f 68 65 6c 70 3f 63 6d 64 3d 73 65 72 76 65 [/help?cmd=serve
2c90: 72 7c 66 6f 73 73 69 6c 20 73 65 72 76 65 72 5d r|fossil server]
2ca0: 22 20 63 6f 6d 6d 61 6e 64 73 0a 61 72 65 20 69 " commands.are i
2cb0: 6d 70 6c 65 6d 65 6e 74 65 64 20 75 73 69 6e 67 mplemented using
2cc0: 20 61 20 73 69 6d 70 6c 65 20 62 75 69 6c 74 2d a simple built-
2cd0: 69 6e 20 77 65 62 20 73 65 72 76 65 72 20 74 68 in web server th
2ce0: 61 74 20 61 63 63 65 70 74 73 20 69 6e 63 6f 6d at accepts incom
2cf0: 69 6e 67 20 48 54 54 50 0a 72 65 71 75 65 73 74 ing HTTP.request
2d00: 73 2c 20 74 72 61 6e 73 6c 61 74 65 73 20 65 61 s, translates ea
2d10: 63 68 20 72 65 71 75 65 73 74 20 69 6e 74 6f 20 ch request into
2d20: 61 20 43 47 49 20 69 6e 76 6f 63 61 74 69 6f 6e a CGI invocation
2d30: 2c 20 74 68 65 6e 20 63 72 65 61 74 65 73 20 61 , then creates a
2d40: 0a 73 65 70 61 72 61 74 65 20 63 68 69 6c 64 20 .separate child
2d50: 46 6f 73 73 69 6c 20 70 72 6f 63 65 73 73 20 74 Fossil process t
2d60: 6f 20 68 61 6e 64 6c 65 20 65 61 63 68 20 72 65 o handle each re
2d70: 71 75 65 73 74 2e 20 20 49 6e 20 6f 74 68 65 72 quest. In other
2d80: 20 77 6f 72 64 73 2c 20 43 47 49 0a 69 73 20 75 words, CGI.is u
2d90: 73 65 64 20 69 6e 74 65 72 6e 61 6c 6c 79 20 74 sed internally t
2da0: 6f 20 69 6d 70 6c 65 6d 65 6e 74 20 22 66 6f 73 o implement "fos
2db0: 73 69 6c 20 75 69 2f 73 65 72 76 65 72 22 2e 0a sil ui/server"..
2dc0: 3c 62 72 3e 3c 62 72 3e 0a 53 43 47 49 20 69 73 <br><br>.SCGI is
2dd0: 20 70 72 6f 63 65 73 73 65 64 20 75 73 69 6e 67 processed using
2de0: 20 74 68 65 20 73 61 6d 65 20 62 75 69 6c 74 2d the same built-
2df0: 69 6e 20 77 65 62 20 73 65 72 76 65 72 2c 20 6a in web server, j
2e00: 75 73 74 20 6d 6f 64 69 66 69 65 64 0a 74 6f 20 ust modified.to
2e10: 70 61 72 73 65 20 53 43 47 49 20 72 65 71 75 65 parse SCGI reque
2e20: 73 74 73 20 69 6e 73 74 65 61 64 20 6f 66 20 48 sts instead of H
2e30: 54 54 50 20 72 65 71 75 65 73 74 73 2e 20 20 45 TTP requests. E
2e40: 61 63 68 20 53 43 47 49 20 72 65 71 75 65 73 74 ach SCGI request
2e50: 20 69 73 0a 63 6f 6e 76 65 72 74 65 64 20 69 6e is.converted in
2e60: 74 6f 20 43 47 49 2c 20 74 68 65 6e 20 46 6f 73 to CGI, then Fos
2e70: 73 69 6c 20 63 72 65 61 74 65 73 20 61 20 73 65 sil creates a se
2e80: 70 61 72 61 74 65 20 63 68 69 6c 64 20 46 6f 73 parate child Fos
2e90: 73 69 6c 0a 70 72 6f 63 65 73 73 20 74 6f 20 68 sil.process to h
2ea0: 61 6e 64 6c 65 20 65 61 63 68 20 43 47 49 20 72 andle each CGI r
2eb0: 65 71 75 65 73 74 2e 3c 2f 70 3e 3c 2f 6c 69 3e equest.</p></li>
2ec0: 0a 3c 6c 69 3e 3c 70 3e 0a 46 6f 73 73 69 6c 20 .<li><p>.Fossil
2ed0: 69 73 20 69 74 73 65 6c 66 20 6f 66 74 65 6e 20 is itself often
2ee0: 6c 61 75 6e 63 68 65 64 20 75 73 69 6e 67 20 43 launched using C
2ef0: 47 49 2e 20 20 42 75 74 20 46 6f 73 73 69 6c 20 GI. But Fossil
2f00: 63 61 6e 20 61 6c 73 6f 20 74 68 65 6e 0a 74 75 can also then.tu
2f10: 72 6e 20 61 72 6f 75 6e 64 20 61 6e 64 20 6c 61 rn around and la
2f20: 75 6e 63 68 20 5b 2e 2f 73 65 72 76 65 72 65 78 unch [./serverex
2f30: 74 2e 77 69 6b 69 7c 73 75 62 2d 43 47 49 20 73 t.wiki|sub-CGI s
2f40: 63 72 69 70 74 73 20 74 6f 20 69 6d 70 6c 65 6d cripts to implem
2f50: 65 6e 74 0a 65 78 74 65 6e 73 69 6f 6e 73 5d 2e ent.extensions].
2f60: 3c 2f 70 3e 3c 2f 6c 69 3e 0a 3c 2f 6f 6c 3e 0a </p></li>.</ol>.