bottleneck testcase based on rubbos
[bottlenecks.git] / rubbos / app / tomcat-connectors-1.2.32-src / docs / ajp / printer / ajpv13a.html
1 <html><head><META http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>The Apache Tomcat Connector - AJP Protocol Reference - AJPv13</title><meta name="author" value="danmil@shore.net"><meta name="email" value="danmil@shore.net"><meta name="author" value="Jean-Frederic Clere"><meta name="email" value="jfrederic.clere@fujitsu-siemens.com"><link href="../../style.css" type="text/css" rel="stylesheet"></head><body bgcolor="#ffffff" text="#000000" link="#525D76" alink="#525D76" vlink="#525D76"><table border="0" width="100%" cellspacing="4"><!--PAGE HEADER--><tr><td colspan="2"><!--TOMCAT LOGO--><a href="http://tomcat.apache.org/"><img src="../../images/tomcat.gif" align="left" alt="Apache Tomcat" border="0"></a><!--APACHE LOGO--><a href="http://www.apache.org/"><img src="http://www.apache.org/images/asf-logo.gif" align="right" alt="Apache Logo" border="0"></a></td></tr><!--HEADER SEPARATOR--><tr><td colspan="2"><hr noshade size="1"></td></tr><tr><!--RIGHT SIDE MAIN BODY--><td width="80%" valign="top" align="left"><table border="0" width="100%" cellspacing="4"><tr><td align="left" valign="top"><h1>The Apache Tomcat Connector - AJP Protocol Reference</h1><h2>AJPv13</h2></td><td align="right" valign="top" nowrap="true"><img src="../../images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"></td></tr></table><table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Intro"><strong>Intro</strong></a></font></td></tr><tr><td><blockquote>
2
3 <p>
4 The original document was written by
5 Dan Milstein, <author email="danmil@shore.net">danmil@shore.net</author>
6 on December 2000. The present document is generated out of an xml file
7 to allow a more easy integration in the Tomcat documentation.
8
9 </p>
10
11 <p>
12 This describes the Apache JServ Protocol version 1.3 (hereafter
13 <b>ajp13</b>).  There is, apparently, no current documentation of how the
14 protocol works.  This document is an attempt to remedy that, in order to
15 make life easier for maintainers of JK, and for anyone who wants to
16 port the protocol somewhere (into jakarta 4.x, for example).
17 </p>
18
19 </blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="author"><strong>author</strong></a></font></td></tr><tr><td><blockquote>
20
21 <p>
22 I am not one of the designers of this protocol -- I believe that Gal
23 Shachor was the original designer.  Everything in this document is derived
24 from the actual implementation I found in the tomcat 3.x code.  I hope it
25 is useful, but I can't make any grand claims to perfect accuracy.  I also
26 don't know why certain design decisions were made.  Where I was able, I've
27 offered some possible justifications for certain choices, but those are
28 only my guesses.  In general, the C code which Shachor wrote is very clean
29 and comprehensible (if almost totally undocumented).  I've cleaned up the
30 Java code, and I think it's reasonably readable.
31 </p>
32 </blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Design Goals"><strong>Design Goals</strong></a></font></td></tr><tr><td><blockquote>
33
34 <p>
35 According to email from Gal Shachor to the jakarta-dev mailing list,
36 the original goals of <b>JK</b> (and thus <b>ajp13</b>) were to extend
37 <b>mod_jserv</b> and <b>ajp12</b> by (I am only including the goals which
38 relate to communication between the web server and the servlet container):
39
40 <ul>
41   <li> Increasing performance (speed, specifically). </li>
42
43   <li> Adding support for SSL, so that <b class="code">isSecure()</b> and
44        <b class="code">getScheme()</b> will function correctly within the servlet
45        container.  The client certificates and cipher suite will be
46        available to servlets as request attributes. </li>
47
48 </ul>
49 </p>
50 </blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Overview of the protocol"><strong>Overview of the protocol</strong></a></font></td></tr><tr><td><blockquote>
51
52 <p>
53 The <b>ajp13</b> protocol is packet-oriented.  A binary format was
54 presumably chosen over the more readable plain text for reasons of
55 performance.  The web server communicates with the servlet container over
56 TCP connections.  To cut down on the expensive process of socket creation,
57 the web server will attempt to maintain persistent TCP connections to the
58 servlet container, and to reuse a connection for multiple request/response
59 cycles.
60 </p><p>
61 Once a connection is assigned to a particular request, it will not be
62 used for any others until the request-handling cycle has terminated.  In
63 other words, requests are not multiplexed over connections.  This makes
64 for much simpler code at either end of the connection, although it does
65 cause more connections to be open at once.
66 </p><p>
67 Once the web server has opened a connection to the servlet container,
68 the connection can be in one of the following states:
69 </p><p>
70 <ul>
71   <li> Idle <br> No request is being handled over this connection. </li>
72   <li> Assigned <br> The connecton is handling a specific request.</li>
73 </ul>
74
75 </p><p>
76 Once a connection is assigned to handle a particular request, the basic
77 request informaton (e.g. HTTP headers, etc) is sent over the connection in
78 a highly condensed form (e.g. common strings are encoded as integers).
79 Details of that format are below in Request Packet Structure. If there is a
80 body to the request (content-length &gt; 0), that is sent in a separate
81 packet immediately after.
82 </p><p>
83 At this point, the servlet container is presumably ready to start
84 processing the request.  As it does so, it can send the
85 following messages back to the web server:
86
87 <ul>
88   <li>SEND_HEADERS <br>Send a set of headers back to the browser.</li>
89
90   <li>SEND_BODY_CHUNK <br>Send a chunk of body data back to the browser.</li>
91
92   <li>GET_BODY_CHUNK <br>Get further data from the request if it hasn't all
93   been transferred yet.  This is necessary because the packets have a fixed
94   maximum size and arbitrary amounts of data can be included the body of a
95   request (for uploaded files, for example).  (Note: this is unrelated to
96   HTTP chunked tranfer).</li>
97
98   <li>END_RESPONSE <br> Finish the request-handling cycle.</li>
99 </ul>
100 </p><p>
101
102 Each message is accompanied by a differently formatted packet of data.  See
103 Response Packet Structures below for details.
104 </p>
105 </blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Basic Packet Structure"><strong>Basic Packet Structure</strong></a></font></td></tr><tr><td><blockquote>
106
107 <p>
108 There is a bit of an XDR heritage to this protocol, but it differs in
109 lots of ways (no 4 byte alignment, for example).
110 </p><p>
111 Byte order: I am not clear about the endian-ness of the individual
112 bytes.  I'm guessing the bytes are little-endian, because that's what XDR
113 specifies, and I'm guessing that sys/socket library is magically making
114 that so (on the C side).  If anyone with a better knowledge of socket calls
115 can step in, that would be great.
116 </p><p>
117 There are four data types in the protocol: bytes, booleans, integers and
118 strings.
119
120 <dl>
121   <dt><b>Byte</b></dt>
122   <dd>A single byte.</dd>
123
124   <dt><b>Boolean</b></dt>
125   <dd>A single byte, 1 = true, 0 = false.  Using other non-zero values as
126   true (i.e. C-style) may work in some places, but it won't in
127   others.</dd>
128   
129   <dt><b>Integer</b></dt>
130   <dd>A number in the range of 0 to 2^16 (32768).  Stored in 2 bytes with
131   the high-order byte first.</dd>
132
133   <dt><b>String</b></dt>
134   <dd>A variable-sized string (length bounded by 2^16). Encoded with the
135   length packed into two bytes first, followed by the string (including the
136   terminating '\0').  Note that the encoded length does <b>not</b> include
137   the trailing '\0' -- it is like <b class="code">strlen</b>.  This is a touch
138   confusing on the Java side, which is littered with odd autoincrement
139   statements to skip over these terminators.  I believe the reason this was
140   done was to allow the C code to be extra efficient when reading strings
141   which the servlet container is sending back -- with the terminating \0
142   character, the C code can pass around references into a single buffer,
143   without copying.  If the \0 was missing, the C code would have to copy
144   things out in order to get its notion of a string. Note a size of -1
145   (65535) indicates a null string and no data follow the length in this
146   case.</dd>
147 </dl>
148 </p>
149
150 <table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Packet Size"><strong>Packet Size</strong></a></font></td></tr><tr><td><blockquote>
151 <p>
152 According to much of the code, the max packet
153 size is 8 * 1024 bytes (8K).  The actual length of the packet is encoded in the
154 header.
155 </p>
156 </blockquote></td></tr></table>
157
158 <table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Packet Headers"><strong>Packet Headers</strong></a></font></td></tr><tr><td><blockquote>
159 <p>
160 Packets sent from the server to the container begin with
161 <b class="code">0x1234</b>.  Packets sent from the container to the server begin
162 with <b class="code">AB</b> (that's the ASCII code for A followed by the ASCII
163 code for B).  After those first two bytes, there is an integer (encoded as
164 above) with the length of the payload.  Although this might suggest that
165 the maximum payload could be as large as 2^16, in fact, the code sets the
166 maximum to be 8K.
167
168
169 <table>
170   <tr>
171     <th colspan="6">Packet Format (Server-&gt;Container)</th>
172   </tr>
173
174   <tr>
175     <th>Byte</th>
176     <td>0</td>
177     <td>1</td>
178     <td>2</td>
179     <td>3</td>
180     <td>4...(n+3)</td>
181   </tr>
182
183   <tr>
184     <th>Contents</th>
185     <td>0x12</td>
186     <td>0x34</td>
187     <td colspan="2">Data Length (n)</td>
188     <td>Data</td>
189   </tr>
190 </table>
191
192 <table>
193   <tr>
194     <th colspan="6"><b>Packet Format (Container-&gt;Server)</b></th>
195   </tr>
196
197   <tr>
198     <th>Byte</th>
199     <td>0</td>
200     <td>1</td>
201     <td>2</td>
202     <td>3</td>
203     <td>4...(n+3)</td>
204   </tr>
205
206   <tr>
207     <th>Contents</th>
208     <td>A</td>
209     <td>B</td>
210     <td colspan="2">Data Length (n)</td>
211     <td>Data</td>
212   </tr>
213 </table>
214 </p>
215 <p>
216 <A NAME="prefix-codes"></A> For most packets, the first byte of the
217 payload encodes the type of message.  The exception is for request body
218 packets sent from the server to the container -- they are sent with a
219 standard packet header (0x1234 and then length of the packet), but without
220 any prefix code after that (this seems like a mistake to me).
221 </p><p>
222 The web server can send the following messages to the servlet container:
223
224 <table>
225   <tr>
226     <th>Code</th>
227     <th>Type of Packet</th>
228     <th>Meaning</th>
229   </tr>
230   <tr>
231     <td>2</td>
232     <td>Forward Request</td>
233     <td>Begin the request-processing cycle with the following data</td>
234   </tr>
235   <tr>
236     <td>7</td>
237     <td>Shutdown</td>
238     <td>The web server asks the container to shut itself down.</td>
239   </tr>
240   <tr>
241     <td>8</td>
242     <td>Ping</td>
243     <td>The web server asks the container to take control (secure login phase).</td>
244   </tr>
245   <tr>
246     <td>10</td>
247     <td>CPing</td>
248     <td>The web server asks the container to respond quickly with a CPong.</td>
249   </tr>
250   <tr>
251     <td>none</td>
252     <td>Data</td>
253     <td>Size (2 bytes) and corresponding body data.</td>
254   </tr>
255 </table>
256 </p>
257 <p>
258 To ensure some
259 basic security, the container will only actually do the <b class="code">Shutdown</b> if the
260 request comes from the same machine on which it's hosted.
261 </p>
262 <p>
263 The first <b class="code">Data</b> packet is send immediatly after the <b class="code">Forward Request</b> by the web server.
264 </p>
265
266 <p>The servlet container can send the following types of messages to the web
267 server:
268 <table>
269   <tr>
270     <th>Code</th>
271     <th>Type of Packet</th>
272     <th>Meaning</th>
273   </tr>
274   <tr>
275     <td>3</td>
276     <td>Send Body Chunk</td>
277     <td>Send a chunk of the body from the servlet container to the web
278     server (and presumably, onto the browser). </td>
279   </tr>
280   <tr>
281     <td>4</td>
282     <td>Send Headers</td>
283     <td>Send the response headers from the servlet container to the web
284     server (and presumably, onto the browser).</td>
285   </tr>
286   <tr>
287     <td>5</td>
288     <td>End Response</td>
289     <td>Marks the end of the response (and thus the request-handling cycle).</td>
290   </tr>
291   <tr>
292     <td>6</td>
293     <td>Get Body Chunk</td>
294     <td>Get further data from the request if it hasn't all been transferred
295     yet.</td>
296   </tr>
297   <tr>
298     <td>9</td>
299     <td>CPong Reply</td>
300     <td>The reply to a CPing request</td>
301   </tr>
302 </table>
303 </p>
304 <p>
305 Each of the above messages has a different internal structure, detailed below.
306 </p>
307 </blockquote></td></tr></table>
308 </blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Request Packet Structure"><strong>Request Packet Structure</strong></a></font></td></tr><tr><td><blockquote>
309
310 <p>
311 For messages from the server to the container of type "Forward Request":
312 </p><p>
313 <div class="example"><pre>
314 AJP13_FORWARD_REQUEST :=
315     prefix_code      (byte) 0x02 = JK_AJP13_FORWARD_REQUEST
316     method           (byte)
317     protocol         (string)
318     req_uri          (string)
319     remote_addr      (string)
320     remote_host      (string)
321     server_name      (string)
322     server_port      (integer)
323     is_ssl           (boolean)
324     num_headers      (integer)
325     request_headers *(req_header_name req_header_value)
326     attributes      *(attribut_name attribute_value)
327     request_terminator (byte) OxFF
328 </pre></div>
329 </p><p>
330 The <b class="code">request_headers</b> have the following structure:
331 </p><p>
332 <div class="example"><pre>
333 req_header_name := 
334     sc_req_header_name | (string)  [see below for how this is parsed]
335
336 sc_req_header_name := 0xA0xx (integer)
337
338 req_header_value := (string)
339 </pre></div>
340 </p><p>
341
342 The <b class="code">attributes</b> are optional and have the following structure:
343 </p><p>
344 <div class="example"><pre>
345 attribute_name := sc_a_name | (sc_a_req_attribute string)
346
347 attribute_value := (string)
348
349 </pre></div>
350 </p><p>
351 Not that the all-important header is "content-length', because it
352 determines whether or not the container looks for another packet
353 immediately.
354 </p><p>
355 Detailed description of the elements of Forward Request.
356 </p>
357 <table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="request_prefix"><strong>request_prefix</strong></a></font></td></tr><tr><td><blockquote>
358 <p>
359 For all requests, this will be 2.
360 See above for details on other <A HREF="#prefix-codes">prefix codes</A>.
361 </p>
362 </blockquote></td></tr></table>
363
364 <table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="method"><strong>method</strong></a></font></td></tr><tr><td><blockquote>
365 <p>
366 The HTTP method, encoded as a single byte:
367 </p>
368
369 <p>
370 <table>
371   <tr><th>Command Name</th><th>Code</th></tr>
372   <tr><td>OPTIONS</td><td>1</td></tr>
373   <tr><td>GET</td><td>2</td></tr>
374   <tr><td>HEAD</td><td>3</td></tr>
375   <tr><td>POST</td><td>4</td></tr>
376   <tr><td>PUT</td><td>5</td></tr>
377   <tr><td>DELETE</td><td>6</td></tr>
378   <tr><td>TRACE</td><td>7</td></tr>
379   <tr><td>PROPFIND</td><td>8</td></tr>
380   <tr><td>PROPPATCH</td><td>9</td></tr>
381   <tr><td>MKCOL</td><td>10</td></tr>
382   <tr><td>COPY</td><td>11</td></tr>
383   <tr><td>MOVE</td><td>12</td></tr>
384   <tr><td>LOCK</td><td>13</td></tr>
385   <tr><td>UNLOCK</td><td>14</td></tr>
386   <tr><td>ACL</td><td>15</td></tr>
387   <tr><td>REPORT</td><td>16</td></tr>
388   <tr><td>VERSION-CONTROL</td><td>17</td></tr>
389   <tr><td>CHECKIN</td><td>18</td></tr>
390   <tr><td>CHECKOUT</td><td>19</td></tr>
391   <tr><td>UNCHECKOUT</td><td>20</td></tr>
392   <tr><td>SEARCH</td><td>21</td></tr>
393   <tr><td>MKWORKSPACE</td><td>22</td></tr>
394   <tr><td>UPDATE</td><td>23</td></tr>
395   <tr><td>LABEL</td><td>24</td></tr>
396   <tr><td>MERGE</td><td>25</td></tr>
397   <tr><td>BASELINE_CONTROL</td><td>26</td></tr>
398   <tr><td>MKACTIVITY</td><td>27</td></tr>
399 </table>
400 </p>
401
402 <p>Later version of ajp13, when used with mod_jk2, will transport 
403 additional methods, even if they are not in this list.
404 </p>
405
406 </blockquote></td></tr></table>
407
408 <table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="protocol, req_uri, remote_addr, remote_host, server_name, server_port, is_ssl"><strong>protocol, req_uri, remote_addr, remote_host, server_name, server_port, is_ssl</strong></a></font></td></tr><tr><td><blockquote>
409 <p>
410   These are all fairly self-explanatory.  Each of these is required, and
411   will be sent for every request.
412 </p>
413 </blockquote></td></tr></table>
414
415 <table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Headers"><strong>Headers</strong></a></font></td></tr><tr><td><blockquote>
416 <p>
417   The structure of <b class="code">request_headers</b> is the following:
418   First, the number of headers <b class="code">num_headers</b> is encoded.
419   Then, a series of header name <b class="code">req_header_name</b> / value
420   <b class="code">req_header_value</b> pairs follows.
421   Common header names are encoded as integers,
422   to save space.  If the header name is not in the list of basic headers,
423   it is encoded normally (as a string, with prefixed length).  The list of
424   common headers <b class="code">sc_req_header_name</b>and their codes
425   is as follows (all are case-sensitive):
426 </p><p>
427 <table>
428   <tr><th>Name</th><th>Code value</th><th>Code name</th></tr>
429   <tr><td>accept</td><td>0xA001</td><td>SC_REQ_ACCEPT</td></tr>
430   <tr><td>accept-charset</td><td>0xA002</td><td>SC_REQ_ACCEPT_CHARSET</td></tr>
431   <tr><td>accept-encoding</td><td>0xA003</td><td>SC_REQ_ACCEPT_ENCODING</td></tr>
432   <tr><td>accept-language</td><td>0xA004</td><td>SC_REQ_ACCEPT_LANGUAGE</td></tr>
433   <tr><td>authorization</td><td>0xA005</td><td>SC_REQ_AUTHORIZATION</td></tr>
434   <tr><td>connection</td><td>0xA006</td><td>SC_REQ_CONNECTION</td></tr>
435   <tr><td>content-type</td><td>0xA007</td><td>SC_REQ_CONTENT_TYPE</td></tr>
436   <tr><td>content-length</td><td>0xA008</td><td>SC_REQ_CONTENT_LENGTH</td></tr>
437   <tr><td>cookie</td><td>0xA009</td><td>SC_REQ_COOKIE</td></tr>
438   <tr><td>cookie2</td><td>0xA00A</td><td>SC_REQ_COOKIE2</td></tr>
439   <tr><td>host</td><td>0xA00B</td><td>SC_REQ_HOST</td></tr>
440   <tr><td>pragma</td><td>0xA00C</td><td>SC_REQ_PRAGMA</td></tr>
441   <tr><td>referer</td><td>0xA00D</td><td>SC_REQ_REFERER</td></tr>
442   <tr><td>user-agent</td><td>0xA00E</td><td>SC_REQ_USER_AGENT</td></tr>
443 </table>
444 </p><p>
445   The Java code that reads this grabs the first two-byte integer and if
446   it sees an <b class="code">'0xA0'</b> in the most significant
447   byte, it uses the integer in the second byte as an index into an array of
448   header names.  If the first byte is not '0xA0', it assumes that the
449   two-byte integer is the length of a string, which is then read in.
450 </p><p>
451   This works on the assumption that no header names will have length
452   greater than 0x9999 (==0xA000 - 1), which is perfectly reasonable, though
453   somewhat arbitrary. (If you, like me, started to think about the cookie
454   spec here, and about how long headers can get, fear not -- this limit is
455   on header <b>names</b> not header <b>values</b>.  It seems unlikely that
456   unmanageably huge header names will be showing up in the HTTP spec any time
457   soon).
458 </p><p>
459   <b>Note:</b> The <b class="code">content-length</b> header is extremely
460   important.  If it is present and non-zero, the container assumes that
461   the request has a body (a POST request, for example), and immediately
462   reads a separate packet off the input stream to get that body.
463 </p>
464 </blockquote></td></tr></table>
465
466 <table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Attributes"><strong>Attributes</strong></a></font></td></tr><tr><td><blockquote>
467 <p>
468
469   The attributes prefixed with a <b class="code">?</b>
470   (e.g. <b class="code">?context</b>) are all optional.  For each, there is a
471   single byte code to indicate the type of attribute, and then a string to
472   give its value.  They can be sent in any order (thogh the C code always
473   sends them in the order listed below).  A special terminating code is
474   sent to signal the end of the list of optional attributes. The list of
475   byte codes is:
476 </p><p>
477
478 <table>
479   <tr><th>Information</th><th>Code Value</th><th>Note</th></tr>
480   <tr><td>?context</td><td>0x01</td><td>Not currently implemented</td></tr>
481   <tr><td>?servlet_path</td><td>0x02</td><td>Not currently implemented</td></tr>
482   <tr><td>?remote_user</td><td>0x03</td><td></td></tr>
483   <tr><td>?auth_type</td><td>0x04</td><td></td></tr>
484   <tr><td>?query_string</td><td>0x05</td><td></td></tr>
485   <tr><td>?route</td><td>0x06</td><td></td></tr>
486   <tr><td>?ssl_cert</td><td>0x07</td><td></td></tr>
487   <tr><td>?ssl_cipher</td><td>0x08</td><td></td></tr>
488   <tr><td>?ssl_session</td><td>0x09</td><td></td></tr>
489   <tr><td>?req_attribute</td><td>0x0A</td><td>Name (the name of the attribut follows)</td></tr>
490   <tr><td>?ssl_key_size</td><td>0x0B</td><td></td></tr>
491   <tr><td>?secret</td><td>0x0C</td><td></td></tr>
492   <tr><td>?stored_method</td><td>0x0D</td><td></td></tr>
493   <tr><td>are_done</td><td>0xFF</td><td>request_terminator</td></tr>
494 </table>
495
496 </p><p>
497
498   The <b class="code">context</b> and <b class="code">servlet_path</b> are not currently
499   set by the C code, and most of the Java code completely ignores whatever
500   is sent over for those fields (and some of it will actually break if a
501   string is sent along after one of those codes).  I don't know if this is
502   a bug or an unimplemented feature or just vestigial code, but it's
503   missing from both sides of the connection.
504 </p><p>
505   The <b class="code">remote_user</b> and <b class="code">auth_type</b> presumably refer
506   to HTTP-level authentication, and communicate the remote user's username
507   and the type of authentication used to establish their identity (e.g. Basic,
508   Digest).  I'm not clear on why the password isn't also sent, but I don't
509   know HTTP authentication inside and out.
510 </p><p>
511   The <b class="code">query_string</b>, <b class="code">ssl_cert</b>,
512   <b class="code">ssl_cipher</b>, and <b class="code">ssl_session</b> refer to the
513   corresponding pieces of HTTP and HTTPS.
514 </p><p>
515   The <b class="code">route</b>, as I understand it, is used to support sticky
516   sessions -- associating a user's sesson with a particular Tomcat instance
517   in the presence of multiple, load-balancing servers.  I don't know the
518   details.
519 </p><p>
520   Beyond this list of basic attributes, any number of other attributes can
521   be sent via the <b class="code">req_attribute</b> code (0x0A).  A pair of strings
522   to represent the attribute name and value are sent immediately after each
523   instance of that code.  Environment values are passed in via this method.
524 </p><p>
525   Finally, after all the attributes have been sent, the attribute terminator,
526   0xFF, is sent.  This signals both the end of the list of attributes and
527   also then end of the Request Packet.
528 </p>
529 </blockquote></td></tr></table>
530
531 </blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Response Packet Structure"><strong>Response Packet Structure</strong></a></font></td></tr><tr><td><blockquote>
532
533 <p>
534 For messages which the container can send back to the server.
535
536 <div class="example"><pre>
537 AJP13_SEND_BODY_CHUNK := 
538   prefix_code   3
539   chunk_length  (integer)
540   chunk        *(byte)
541
542
543 AJP13_SEND_HEADERS :=
544   prefix_code       4
545   http_status_code  (integer)
546   http_status_msg   (string)
547   num_headers       (integer)
548   response_headers *(res_header_name header_value)
549
550 res_header_name := 
551     sc_res_header_name | (string)   [see below for how this is parsed]
552
553 sc_res_header_name := 0xA0 (byte)
554
555 header_value := (string)
556
557 AJP13_END_RESPONSE :=
558   prefix_code       5
559   reuse             (boolean)
560
561
562 AJP13_GET_BODY_CHUNK :=
563   prefix_code       6
564   requested_length  (integer)
565 </pre></div>
566
567 </p>
568 <p>
569 Details:
570 </p>
571
572 <table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Send Body Chunk"><strong>Send Body Chunk</strong></a></font></td></tr><tr><td><blockquote>
573 <p>
574   The chunk is basically binary data, and is sent directly back to the browser.
575 </p>
576 </blockquote></td></tr></table>
577
578 <table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Send Headers"><strong>Send Headers</strong></a></font></td></tr><tr><td><blockquote>
579 <p>
580   The status code and message are the usual HTTP things (e.g. "200" and "OK").
581   The response header names are encoded the same way the request header names are.
582   See <A HREF="#header_encoding">above</A> for details about how the the
583   codes are distinguished from the strings.  The codes for common headers are:
584 </p>
585
586 <p>
587 <table>
588   <tr><th>Name</th><th>Code value</th></tr>
589   <tr><td>Content-Type</td><td>0xA001</td></tr>
590   <tr><td>Content-Language</td><td>0xA002</td></tr>
591   <tr><td>Content-Length</td><td>0xA003</td></tr>
592   <tr><td>Date</td><td>0xA004</td></tr>
593   <tr><td>Last-Modified</td><td>0xA005</td></tr>
594   <tr><td>Location</td><td>0xA006</td></tr>
595   <tr><td>Set-Cookie</td><td>0xA007</td></tr>
596   <tr><td>Set-Cookie2</td><td>0xA008</td></tr>
597   <tr><td>Servlet-Engine</td><td>0xA009</td></tr>
598   <tr><td>Status</td><td>0xA00A</td></tr>
599   <tr><td>WWW-Authenticate</td><td>0xA00B</td></tr>
600 </table>
601
602 </p>
603
604 <p> 
605   After the code or the string header name, the header value is immediately
606   encoded.
607 </p>
608
609 </blockquote></td></tr></table>
610
611 <table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="End Response"><strong>End Response</strong></a></font></td></tr><tr><td><blockquote>
612 <p>
613   Signals the end of this request-handling cycle.  If the
614   <b class="code">reuse</b> flag is true (==1), this TCP connection can now be used to
615   handle new incoming requests.  If <b class="code">reuse</b> is false (anything
616   other than 1 in the actual C code), the connection should be closed.
617 </p>
618 </blockquote></td></tr></table>
619
620 <table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Get Body Chunk"><strong>Get Body Chunk</strong></a></font></td></tr><tr><td><blockquote>
621 <p>
622   The container asks for more data from the request (If the body was
623   too large to fit in the first packet sent over or when the request is
624   chuncked).
625   The server will send a body packet back with an amount of data which is
626   the minimum of the <b class="code">request_length</b>,
627   the maximum send body size (8186 (8 Kbytes - 6)), and the
628   number of bytes actually left to send from the request body.
629 <br>
630   If there is no more data in the body (i.e. the servlet container is
631   trying to read past the end of the body), the server will send back an
632   "empty" packet, which is a body packet with a payload length of 0.
633   (0x12,0x34,0x00,0x00)
634 </p>
635 </blockquote></td></tr></table>
636 </blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Questions I Have"><strong>Questions I Have</strong></a></font></td></tr><tr><td><blockquote>
637
638 <p> What happens if the request headers &gt; max packet size?  There is no
639 provision to send a second packet of request headers in case there are more
640 than 8K (I think this is correctly handled for response headers, though I'm
641 not certain).  I don't know if there is a way to get more than 8K worth of
642 data into that initial set of request headers, but I'll bet there is
643 (combine long cookies with long ssl information and a lot of environment
644 variables, and you should hit 8K easily).  I think the connector would just
645 fail before trying to send any headers in this case, but I'm not certain.</p>
646
647 <p> What about authentication?  There doesn't seem to be any authentication
648 of the connection between the web server and the container.  This strikes
649 me as potentially dangerous.</p>
650
651 </blockquote></td></tr></table></td></tr><!--FOOTER SEPARATOR--><tr><td colspan="2"><hr noshade size="1"></td></tr><!--PAGE FOOTER--><tr><td colspan="2"><div align="center"><font color="#525D76" size="-1"><em>
652         Copyright &copy; 1999-2011, Apache Software Foundation
653         </em></font></div></td></tr></table></body></html>