paulb@328 | 1 | <?xml version="1.0" encoding="iso-8859-1"?> |
paulb@328 | 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
paulb@328 | 3 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
paulb@328 | 4 | <html xmlns="http://www.w3.org/1999/xhtml"> |
paulb@327 | 5 | <head> |
paulb@327 | 6 | <title>URLs and Paths</title> |
paulb@328 | 7 | <meta name="generator" content="amaya 8.1a, see http://www.w3.org/Amaya/" /> |
paulb@328 | 8 | <link href="styles.css" rel="stylesheet" type="text/css" /> |
paulb@327 | 9 | </head> |
paulb@327 | 10 | |
paulb@327 | 11 | <body> |
paulb@327 | 12 | <h1>URLs and Paths</h1> |
paulb@327 | 13 | |
paulb@327 | 14 | <p>The URL at which your application shall appear is arguably the first part |
paulb@327 | 15 | of the application's user interface that any user will see. In this context, |
paulb@327 | 16 | a user can be any of the following things:</p> |
paulb@327 | 17 | <ul> |
paulb@327 | 18 | <li>A real person entering the URL into a browser's address bar.</li> |
paulb@327 | 19 | <li>A real person linking to your application by writing the URL in a |
paulb@327 | 20 | separate Web page.</li> |
paulb@327 | 21 | <li>A program which has the URL defined within it and which may manipulate |
paulb@327 | 22 | the URL to perform certain kinds of operations.</li> |
paulb@327 | 23 | </ul> |
paulb@327 | 24 | |
paulb@327 | 25 | <h2>Interpreting Path Information</h2> |
paulb@327 | 26 | |
paulb@327 | 27 | <p>What the URL is supposed to do is to say where (on the Internet or on an |
paulb@327 | 28 | intranet) your application resides and which resource or service is being |
paulb@327 | 29 | accessed, and these look like this:</p> |
paulb@327 | 30 | <pre>http://www.boddie.org.uk/python/WebStack.html</pre> |
paulb@327 | 31 | |
paulb@327 | 32 | <p>With WebStack, we also talk about a "path" as being just the part of the |
paulb@327 | 33 | URL which refers to the resource or service, ignoring the actual Internet |
paulb@327 | 34 | address, and so these look like this:</p> |
paulb@327 | 35 | <pre>/python/WebStack.html</pre> |
paulb@327 | 36 | |
paulb@327 | 37 | <p>When writing a Web application, most of the time you just need to |
paulb@327 | 38 | concentrate on the path because the address doesn't usually tell you anything |
paulb@327 | 39 | you don't already know. What you need to do is to interpret the path |
paulb@327 | 40 | specified in the request in order to work out which resource or service the |
paulb@328 | 41 | request is destined for.<br /> |
paulb@327 | 42 | </p> |
paulb@327 | 43 | |
paulb@327 | 44 | <div class="WebStack"> |
paulb@327 | 45 | <h3>WebStack API - Path Methods in Transaction Objects</h3> |
paulb@327 | 46 | |
paulb@327 | 47 | <p>WebStack provides the following transaction methods for inspecting path |
paulb@327 | 48 | information:</p> |
paulb@327 | 49 | <dl> |
paulb@327 | 50 | <dt><code>get_path</code></dt> |
paulb@327 | 51 | <dd>This gets the entire path of a resource including parameter |
paulb@327 | 52 | information - see <a href="parameters.html">"Request Parameters and |
paulb@327 | 53 | Uploads"</a>.</dd> |
paulb@327 | 54 | <dt><code>get_path_without_query</code></dt> |
paulb@327 | 55 | <dd>This gets the entire path of a resource but without any parameter |
paulb@327 | 56 | information.</dd> |
paulb@327 | 57 | </dl> |
paulb@327 | 58 | </div> |
paulb@327 | 59 | |
paulb@327 | 60 | <h2>Paths To and Within an Application</h2> |
paulb@327 | 61 | One thing to be aware of in the code of an application is which part of a |
paulb@327 | 62 | path refers to the location of the application in a server environment and |
paulb@327 | 63 | which refers to some resource within the application itself. Consider this |
paulb@328 | 64 | path:<br /> |
paulb@327 | 65 | |
paulb@327 | 66 | <pre>/folder/application/resource</pre> |
paulb@327 | 67 | Let us say that the application was deployed in a Zope server instance inside |
paulb@327 | 68 | <code>folder</code> and with the name <code>application</code>. We may then |
paulb@327 | 69 | say that the path to the application is this: |
paulb@327 | 70 | <pre>/folder/application</pre> |
paulb@327 | 71 | Meanwhile, the path within the application is just this: |
paulb@327 | 72 | <pre>/resource</pre> |
paulb@327 | 73 | |
paulb@327 | 74 | <div class="WebStack"> |
paulb@327 | 75 | <h3>WebStack API - Paths To Resources Within Applications</h3> |
paulb@327 | 76 | |
paulb@327 | 77 | <p>On transaction objects, the following methods exist to inspect paths to |
paulb@327 | 78 | resources within applications.</p> |
paulb@327 | 79 | <dl> |
paulb@327 | 80 | <dt><code>get_path_info</code></dt> |
paulb@327 | 81 | <dd>This gets the path of a resource within an application.</dd> |
paulb@327 | 82 | <dt><code>get_virtual_path_info</code></dt> |
paulb@327 | 83 | <dd>This gets the path of a resource within a part of an application - |
paulb@327 | 84 | the application itself decides the scope of the path and can set the |
paulb@327 | 85 | "virtual path info" using the <code>set_virtual_path_info</code> |
paulb@327 | 86 | method.</dd> |
paulb@327 | 87 | </dl> |
paulb@327 | 88 | </div> |
paulb@327 | 89 | |
paulb@328 | 90 | <h2>Approaches to Path Interpretation</h2> |
paulb@327 | 91 | |
paulb@327 | 92 | <p>There are various differing approaches to the problem of interpreting |
paulb@327 | 93 | paths to resources within Web applications, but these can mostly be divided |
paulb@327 | 94 | into three categories:</p> |
paulb@327 | 95 | |
paulb@327 | 96 | <table border="1" cellspacing="0" cellpadding="5"> |
paulb@327 | 97 | <tbody> |
paulb@327 | 98 | <tr> |
paulb@327 | 99 | <th>Approach</th> |
paulb@327 | 100 | <th>Examples</th> |
paulb@327 | 101 | </tr> |
paulb@327 | 102 | <tr> |
paulb@327 | 103 | <td><a href="paths-filesystem.html">Path as filesystem</a></td> |
paulb@327 | 104 | <td>WebDAV interface to a repository</td> |
paulb@327 | 105 | </tr> |
paulb@327 | 106 | <tr> |
paulb@327 | 107 | <td><a href="paths-services.html">Path as resource or service |
paulb@327 | 108 | identifier</a></td> |
paulb@327 | 109 | <td>A Web shop with very simple paths, eg. <code>/products</code>, |
paulb@327 | 110 | <code>/checkout</code>, <code>/orders</code></td> |
paulb@327 | 111 | </tr> |
paulb@327 | 112 | <tr> |
paulb@327 | 113 | <td><a href="paths-opaque.html">Path as opaque reference</a></td> |
paulb@327 | 114 | <td>An e-mail reader where the messages already have strange and |
paulb@327 | 115 | unreadable message identifiers</td> |
paulb@327 | 116 | </tr> |
paulb@327 | 117 | </tbody> |
paulb@327 | 118 | </table> |
paulb@328 | 119 | |
paulb@328 | 120 | <h2>Path Info Support in Server Environments</h2> |
paulb@328 | 121 | |
paulb@328 | 122 | <p>The following table summarises the support for paths within applications |
paulb@328 | 123 | amongst the supported server environments or frameworks within WebStack:</p> |
paulb@328 | 124 | |
paulb@328 | 125 | <table border="1" cellspacing="0" cellpadding="5"> |
paulb@328 | 126 | <tbody> |
paulb@328 | 127 | <tr> |
paulb@328 | 128 | <th>Framework</th> |
paulb@328 | 129 | <th>Behaviour/Level of Support</th> |
paulb@328 | 130 | </tr> |
paulb@328 | 131 | <tr> |
paulb@328 | 132 | <td>BaseHTTPRequestHandler</td> |
paulb@328 | 133 | <td>Same as path (correct)</td> |
paulb@328 | 134 | </tr> |
paulb@328 | 135 | <tr> |
paulb@328 | 136 | <td>CGI</td> |
paulb@328 | 137 | <td>Path beyond resource (correct)</td> |
paulb@328 | 138 | </tr> |
paulb@328 | 139 | <tr> |
paulb@328 | 140 | <td>Java Servlet API</td> |
paulb@328 | 141 | <td>Path beyond context (correct)</td> |
paulb@328 | 142 | </tr> |
paulb@328 | 143 | <tr> |
paulb@328 | 144 | <td>mod_python</td> |
paulb@328 | 145 | <td>Path beyond resource (correct)</td> |
paulb@328 | 146 | </tr> |
paulb@328 | 147 | <tr> |
paulb@328 | 148 | <td>Twisted</td> |
paulb@328 | 149 | <td>Same as path (correct)</td> |
paulb@328 | 150 | </tr> |
paulb@328 | 151 | <tr> |
paulb@328 | 152 | <td>Webware</td> |
paulb@328 | 153 | <td><= 0.8.1: Not supported (needs <code>ExtraPathInfo</code> |
paulb@328 | 154 | support)<br /> |
paulb@328 | 155 | > 0.8.1: Path beyond context (correct)</td> |
paulb@328 | 156 | </tr> |
paulb@328 | 157 | <tr> |
paulb@328 | 158 | <td>WSGI</td> |
paulb@328 | 159 | <td>Path beyond resource (correct)</td> |
paulb@328 | 160 | </tr> |
paulb@328 | 161 | <tr> |
paulb@328 | 162 | <td>Zope</td> |
paulb@328 | 163 | <td>Path beyond resource (correct)</td> |
paulb@328 | 164 | </tr> |
paulb@328 | 165 | </tbody> |
paulb@328 | 166 | </table> |
paulb@327 | 167 | </body> |
paulb@327 | 168 | </html> |