]> granicus.if.org Git - apache/blob - docs/manual/mod/mod_proxy_ajp.html.en
Fix alignment in a <highlight> block.
[apache] / docs / manual / mod / mod_proxy_ajp.html.en
1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
4 <meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type" />
5 <!--
6         XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
7               This file is generated from xml source: DO NOT EDIT
8         XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
9       -->
10 <title>mod_proxy_ajp - Apache HTTP Server Version 2.5</title>
11 <link href="../style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
12 <link href="../style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
13 <link href="../style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" /><link rel="stylesheet" type="text/css" href="../style/css/prettify.css" />
14 <script src="../style/scripts/prettify.min.js" type="text/javascript">
15 </script>
16
17 <link href="../images/favicon.ico" rel="shortcut icon" /></head>
18 <body>
19 <div id="page-header">
20 <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/quickreference.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p>
21 <p class="apache">Apache HTTP Server Version 2.5</p>
22 <img alt="" src="../images/feather.png" /></div>
23 <div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="../images/left.gif" /></a></div>
24 <div id="path">
25 <a href="http://www.apache.org/">Apache</a> &gt; <a href="http://httpd.apache.org/">HTTP Server</a> &gt; <a href="http://httpd.apache.org/docs/">Documentation</a> &gt; <a href="../">Version 2.5</a> &gt; <a href="./">Modules</a></div>
26 <div id="page-content">
27 <div id="preamble"><h1>Apache Module mod_proxy_ajp</h1>
28 <div class="toplang">
29 <p><span>Available Languages: </span><a href="../en/mod/mod_proxy_ajp.html" title="English">&nbsp;en&nbsp;</a> |
30 <a href="../fr/mod/mod_proxy_ajp.html" hreflang="fr" rel="alternate" title="Français">&nbsp;fr&nbsp;</a> |
31 <a href="../ja/mod/mod_proxy_ajp.html" hreflang="ja" rel="alternate" title="Japanese">&nbsp;ja&nbsp;</a></p>
32 </div>
33 <table class="module"><tr><th><a href="module-dict.html#Description">Description:</a></th><td>AJP support module for
34 <code class="module"><a href="../mod/mod_proxy.html">mod_proxy</a></code></td></tr>
35 <tr><th><a href="module-dict.html#Status">Status:</a></th><td>Extension</td></tr>
36 <tr><th><a href="module-dict.html#ModuleIdentifier">Module Identifier:</a></th><td>proxy_ajp_module</td></tr>
37 <tr><th><a href="module-dict.html#SourceFile">Source File:</a></th><td>mod_proxy_ajp.c</td></tr></table>
38 <h3>Summary</h3>
39
40     <p>This module <em>requires</em> the service of <code class="module"><a href="../mod/mod_proxy.html">mod_proxy</a></code>. It provides support for the
41     <code>Apache JServ Protocol version 1.3</code> (hereafter
42     <em>AJP13</em>).</p>
43
44     <p>Thus, in order to get the ability of handling <code>AJP13</code>
45     protocol, <code class="module"><a href="../mod/mod_proxy.html">mod_proxy</a></code> and
46     <code class="module"><a href="../mod/mod_proxy_ajp.html">mod_proxy_ajp</a></code> have to be present in the server.</p>
47
48     <div class="warning"><h3>Warning</h3>
49       <p>Do not enable proxying until you have <a href="mod_proxy.html#access">secured your server</a>. Open proxy
50       servers are dangerous both to your network and to the Internet at
51       large.</p>
52     </div>
53 </div>
54 <div id="quickview"><h3>Topics</h3>
55 <ul id="topics">
56 <li><img alt="" src="../images/down.gif" /> <a href="#usage">Usage</a></li>
57 <li><img alt="" src="../images/down.gif" /> <a href="#env">Environment Variables</a></li>
58 <li><img alt="" src="../images/down.gif" /> <a href="#overviewprotocol">Overview of the protocol</a></li>
59 <li><img alt="" src="../images/down.gif" /> <a href="#basppacketstruct">Basic Packet Structure</a></li>
60 <li><img alt="" src="../images/down.gif" /> <a href="#rpacetstruct">Request Packet Structure</a></li>
61 <li><img alt="" src="../images/down.gif" /> <a href="#resppacketstruct">Response Packet Structure</a></li>
62 </ul><h3 class="directives">Directives</h3>
63 <p>This module provides no
64             directives.</p>
65 <h3>Bugfix checklist</h3><ul class="seealso"><li><a href="https://www.apache.org/dist/httpd/CHANGES_2.4">httpd changelog</a></li><li><a href="https://bz.apache.org/bugzilla/buglist.cgi?bug_status=__open__&amp;list_id=144532&amp;product=Apache%20httpd-2&amp;query_format=specific&amp;order=changeddate%20DESC%2Cpriority%2Cbug_severity&amp;component=mod_proxy_ajp">Known issues</a></li><li><a href="https://bz.apache.org/bugzilla/enter_bug.cgi?product=Apache%20httpd-2&amp;component=mod_proxy_ajp">Report a bug</a></li></ul><h3>See also</h3>
66 <ul class="seealso">
67 <li><code class="module"><a href="../mod/mod_proxy.html">mod_proxy</a></code></li>
68 <li><a href="../env.html">Environment Variable documentation</a></li>
69 <li><a href="#comments_section">Comments</a></li></ul></div>
70 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
71 <div class="section">
72 <h2><a name="usage" id="usage">Usage</a> <a title="Permanent link" href="#usage" class="permalink">&para;</a></h2>
73     <p>This module is used to reverse proxy to a backend application server
74     (e.g. Apache Tomcat) using the AJP13 protocol. The usage is similar to
75     an HTTP reverse proxy, but uses the <code>ajp://</code> prefix:</p>
76
77     <div class="example"><h3>Simple Reverse Proxy</h3><pre class="prettyprint lang-config">ProxyPass "/app" "ajp://backend.example.com:8009/app"</pre>
78 </div>
79
80     <p>Balancers may also be used:</p>
81     <div class="example"><h3>Balancer Reverse Proxy</h3><pre class="prettyprint lang-config">&lt;Proxy balancer://cluster&gt;
82     BalancerMember ajp://app1.example.com:8009 loadfactor=1
83     BalancerMember ajp://app2.example.com:8009 loadfactor=2
84     ProxySet lbmethod=bytraffic
85 &lt;/Proxy&gt;
86 ProxyPass "/app" "balancer://cluster/app"</pre>
87 </div>
88
89     <p>Note that usually no
90     <code class="directive"><a href="../mod/mod_proxy.html#proxypassreverse">ProxyPassReverse</a></code>
91     directive is necessary. The AJP request includes the original host
92     header given to the proxy, and the application server can be expected
93     to generate self-referential headers relative to this host, so no
94     rewriting is necessary.</p>
95
96     <p>The main exception is when the URL path on the proxy differs from that
97     on the
98     backend. In this case, a redirect header can be rewritten relative to the
99     original host URL (not the backend <code>ajp://</code> URL), for
100     example:</p>
101     <div class="example"><h3>Rewriting Proxied Path</h3><pre class="prettyprint lang-config">ProxyPass "/apps/foo" "ajp://backend.example.com:8009/foo"
102 ProxyPassReverse "/apps/foo" "http://www.example.com/foo"</pre>
103 </div>
104     <p>However, it is usually better to deploy the application on the backend
105     server at the same path as the proxy rather than to take this approach.
106     </p>
107 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
108 <div class="section">
109 <h2><a name="env" id="env">Environment Variables</a> <a title="Permanent link" href="#env" class="permalink">&para;</a></h2>
110     <p>Environment variables whose names have the prefix <code>AJP_</code>
111     are forwarded to the origin server as AJP request attributes
112     (with the AJP_ prefix removed from the name of the key).</p>
113 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
114 <div class="section">
115 <h2><a name="overviewprotocol" id="overviewprotocol">Overview of the protocol</a> <a title="Permanent link" href="#overviewprotocol" class="permalink">&para;</a></h2>
116     <p>The <code>AJP13</code> protocol is packet-oriented.  A binary format
117     was presumably chosen over the more readable plain text for reasons of
118     performance.  The web server communicates with the servlet container over
119     TCP connections.  To cut down on the expensive process of socket creation,
120     the web server will attempt to maintain persistent TCP connections to the
121     servlet container, and to reuse a connection for multiple request/response
122     cycles.</p>
123     <p>Once a connection is assigned to a particular request, it will not be
124     used for any others until the request-handling cycle has terminated.  In
125     other words, requests are not multiplexed over connections.  This makes
126     for much simpler code at either end of the connection, although it does
127     cause more connections to be open at once.</p>
128     <p>Once the web server has opened a connection to the servlet container,
129     the connection can be in one of the following states:</p>
130     <ul>
131     <li> Idle <br /> No request is being handled over this connection. </li>
132     <li> Assigned <br /> The connection is handling a specific request.</li>
133     </ul>
134     <p>Once a connection is assigned to handle a particular request, the basic
135     request information (e.g. HTTP headers, etc) is sent over the connection in
136     a highly condensed form (e.g. common strings are encoded as integers).
137     Details of that format are below in Request Packet Structure. If there is a
138     body to the request <code>(content-length &gt; 0)</code>, that is sent in a
139     separate packet immediately after.</p>
140     <p>At this point, the servlet container is presumably ready to start
141     processing the request.  As it does so, it can send the
142     following messages back to the web server:</p>
143     <ul>
144     <li>SEND_HEADERS <br />Send a set of headers back to the browser.</li>
145     <li>SEND_BODY_CHUNK <br />Send a chunk of body data back to the browser.
146     </li>
147     <li>GET_BODY_CHUNK <br />Get further data from the request if it hasn't all
148     been transferred yet.  This is necessary because the packets have a fixed
149     maximum size and arbitrary amounts of data can be included the body of a
150     request (for uploaded files, for example).  (Note: this is unrelated to
151     HTTP chunked transfer).</li>
152     <li>END_RESPONSE <br /> Finish the request-handling cycle.</li>
153     </ul>
154     <p>Each message is accompanied by a differently formatted packet of data.
155     See Response Packet Structures below for details.</p>
156 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
157 <div class="section">
158 <h2><a name="basppacketstruct" id="basppacketstruct">Basic Packet Structure</a> <a title="Permanent link" href="#basppacketstruct" class="permalink">&para;</a></h2>
159     <p>There is a bit of an XDR heritage to this protocol, but it differs
160     in lots of ways (no 4 byte alignment, for example).</p>
161     <p>AJP13 uses network byte order for all data types.</p>
162     <p>There are four data types in the protocol: bytes, booleans,
163     integers and strings.</p>
164     <dl>
165     <dt><strong>Byte</strong></dt><dd>A single byte.</dd>
166     <dt><strong>Boolean</strong></dt>
167       <dd>A single byte, <code>1 = true</code>, <code>0 = false</code>.
168       Using other non-zero values as true (i.e. C-style) may work in some places,
169       but it won't in others.</dd>
170     <dt><strong>Integer</strong></dt>
171       <dd>A number in the range of <code>0 to 2^16 (32768)</code>.  Stored in
172       2 bytes with the high-order byte first.</dd>
173     <dt><strong>String</strong></dt>
174       <dd>A variable-sized string (length bounded by 2^16). Encoded with
175       the length packed into two bytes first, followed by the string
176       (including the terminating '\0').  Note that the encoded length does
177       <strong>not</strong> include the trailing '\0' -- it is like
178       <code>strlen</code>.  This is a touch confusing on the Java side, which
179       is littered with odd autoincrement statements to skip over these
180       terminators.  I believe the reason this was done was to allow the C
181       code to be extra efficient when reading strings which the servlet
182       container is sending back -- with the terminating \0 character, the
183       C code can pass around references into a single buffer, without copying.
184       if the \0 was missing, the C code would have to copy things out in order
185       to get its notion of a string.</dd>
186     </dl>
187
188   <h3>Packet Size</h3>
189     <p>According to much of the code, the max packet size is <code>
190     8 * 1024 bytes (8K)</code>.  The actual length of the packet is encoded in
191     the header.</p>
192   
193   <h3>Packet Headers</h3>
194     <p>Packets sent from the server to the container begin with
195     <code>0x1234</code>.  Packets sent from the container to the server
196     begin with <code>AB</code> (that's the ASCII code for A followed by the
197     ASCII code for B).  After those first two bytes, there is an integer
198     (encoded as above) with the length of the payload.  Although this might
199     suggest that the maximum payload could be as large as 2^16, in fact, the
200     code sets the maximum to be 8K.</p>
201     <table>
202        
203       <tr>
204         <th colspan="6"><em>Packet Format (Server-&gt;Container)</em></th>
205       </tr>
206       <tr>
207         <th>Byte</th>
208         <td>0</td>
209         <td>1</td>
210         <td>2</td>
211         <td>3</td>
212         <td>4...(n+3)</td>
213       </tr>
214       <tr>
215         <th>Contents</th>
216         <td>0x12</td>
217         <td>0x34</td>
218         <td colspan="2">Data Length (n)</td>
219         <td>Data</td>
220       </tr>
221     </table>
222     <table>
223        
224       <tr>
225         <th colspan="6"><em>Packet Format (Container-&gt;Server)</em></th>
226       </tr>
227       <tr>
228         <th>Byte</th>
229         <td>0</td>
230         <td>1</td>
231         <td>2</td>
232         <td>3</td>
233         <td>4...(n+3)</td>
234       </tr>
235       <tr>
236         <th>Contents</th>
237         <td>A</td>
238         <td>B</td>
239         <td colspan="2">Data Length (n)</td>
240         <td>Data</td>
241       </tr>
242     </table>
243     <p>For most packets, the first byte of the payload encodes the type of
244      message.  The exception is for request body packets sent from the server to
245      the container -- they are sent with a standard packet header (<code>
246      0x1234</code> and then length of the packet), but without any prefix code
247      after that.</p>
248      <p>The web server can send the following messages to the servlet
249      container:</p>
250     <table>
251        
252       <tr>
253         <td>Code</td>
254         <td>Type of Packet</td>
255         <td>Meaning</td>
256       </tr>
257       <tr>
258         <td>2</td>
259         <td>Forward Request</td>
260         <td>Begin the request-processing cycle with the following data</td>
261       </tr>
262       <tr>
263         <td>7</td>
264         <td>Shutdown</td>
265         <td>The web server asks the container to shut itself down.</td>
266       </tr>
267       <tr>
268         <td>8</td>
269         <td>Ping</td>
270         <td>The web server asks the container to take control
271         (secure login phase).</td>
272       </tr>
273       <tr>
274         <td>10</td>
275         <td>CPing</td>
276         <td>The web server asks the container to respond quickly with a CPong.
277         </td>
278       </tr>
279       <tr>
280         <td>none</td>
281         <td>Data</td>
282         <td>Size (2 bytes) and corresponding body data.</td>
283       </tr>
284     </table>
285     <p>To ensure some basic security, the container will only actually do the
286     <code>Shutdown</code> if the request comes from the same machine on which
287     it's hosted.</p>
288     <p>The first <code>Data</code> packet is send immediately after the
289     <code>Forward Request</code> by the web server.</p>
290     <p>The servlet container can send the following types of messages to the
291     webserver:</p>
292     <table>
293        
294       <tr>
295         <td>Code</td>
296         <td>Type of Packet</td>
297         <td>Meaning</td>
298       </tr>
299       <tr>
300         <td>3</td>
301         <td>Send Body Chunk</td>
302         <td>Send a chunk of the body from the servlet container to the web
303         server (and presumably, onto the browser). </td>
304       </tr>
305       <tr>
306         <td>4</td>
307         <td>Send Headers</td>
308         <td>Send the response headers from the servlet container to the web
309         server (and presumably, onto the browser).</td>
310       </tr>
311       <tr>
312         <td>5</td>
313         <td>End Response</td>
314         <td>Marks the end of the response (and thus the request-handling cycle).
315         </td>
316       </tr>
317       <tr>
318         <td>6</td>
319         <td>Get Body Chunk</td>
320         <td>Get further data from the request if it hasn't all been
321         transferred yet.</td>
322       </tr>
323       <tr>
324         <td>9</td>
325         <td>CPong Reply</td>
326         <td>The reply to a CPing request</td>
327       </tr>
328     </table>
329     <p>Each of the above messages has a different internal structure, detailed
330     below.</p>
331   
332 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
333 <div class="section">
334 <h2><a name="rpacetstruct" id="rpacetstruct">Request Packet Structure</a> <a title="Permanent link" href="#rpacetstruct" class="permalink">&para;</a></h2>
335     <p>For messages from the server to the container of type
336     <em>Forward Request</em>:</p>
337     <div class="example"><pre>AJP13_FORWARD_REQUEST :=
338     prefix_code      (byte) 0x02 = JK_AJP13_FORWARD_REQUEST
339     method           (byte)
340     protocol         (string)
341     req_uri          (string)
342     remote_addr      (string)
343     remote_host      (string)
344     server_name      (string)
345     server_port      (integer)
346     is_ssl           (boolean)
347     num_headers      (integer)
348     request_headers *(req_header_name req_header_value)
349     attributes      *(attribut_name attribute_value)
350     request_terminator (byte) OxFF</pre></div>
351     <p>The <code>request_headers</code> have the following structure:
352     </p><div class="example"><pre>req_header_name :=
353     sc_req_header_name | (string)  [see below for how this is parsed]
354
355 sc_req_header_name := 0xA0xx (integer)
356
357 req_header_value := (string)</pre></div>
358     <p>The <code>attributes</code> are optional and have the following
359     structure:</p>
360     <div class="example"><pre>attribute_name := sc_a_name | (sc_a_req_attribute string)
361
362 attribute_value := (string)</pre></div>
363     <p>Not that the all-important header is <code>content-length</code>,
364     because it determines whether or not the container looks for another
365     packet immediately.</p>
366   <h3>Detailed description of the elements of Forward Request
367   </h3>
368   <h3>Request prefix</h3>
369     <p>For all requests, this will be 2. See above for details on other Prefix
370     codes.</p>
371   
372   <h3>Method</h3>
373     <p>The HTTP method, encoded as a single byte:</p>
374     <table>
375       <tr><td>Command Name</td><td>Code</td></tr>
376       <tr><td>OPTIONS</td><td>1</td></tr>
377       <tr><td>GET</td><td>2</td></tr>
378       <tr><td>HEAD</td><td>3</td></tr>
379       <tr><td>POST</td><td>4</td></tr>
380       <tr><td>PUT</td><td>5</td></tr>
381       <tr><td>DELETE</td><td>6</td></tr>
382       <tr><td>TRACE</td><td>7</td></tr>
383       <tr><td>PROPFIND</td><td>8</td></tr>
384       <tr><td>PROPPATCH</td><td>9</td></tr>
385       <tr><td>MKCOL</td><td>10</td></tr>
386       <tr><td>COPY</td><td>11</td></tr>
387       <tr><td>MOVE</td><td>12</td></tr>
388       <tr><td>LOCK</td><td>13</td></tr>
389       <tr><td>UNLOCK</td><td>14</td></tr>
390       <tr><td>ACL</td><td>15</td></tr>
391       <tr><td>REPORT</td><td>16</td></tr>
392       <tr><td>VERSION-CONTROL</td><td>17</td></tr>
393       <tr><td>CHECKIN</td><td>18</td></tr>
394       <tr><td>CHECKOUT</td><td>19</td></tr>
395       <tr><td>UNCHECKOUT</td><td>20</td></tr>
396       <tr><td>SEARCH</td><td>21</td></tr>
397       <tr><td>MKWORKSPACE</td><td>22</td></tr>
398       <tr><td>UPDATE</td><td>23</td></tr>
399       <tr><td>LABEL</td><td>24</td></tr>
400       <tr><td>MERGE</td><td>25</td></tr>
401       <tr><td>BASELINE_CONTROL</td><td>26</td></tr>
402       <tr><td>MKACTIVITY</td><td>27</td></tr>
403     </table>
404     <p>Later version of ajp13, will transport
405     additional methods, even if they are not in this list.</p>
406   
407   <h3>protocol, req_uri, remote_addr, remote_host, server_name,
408   server_port, is_ssl</h3>
409     <p>These are all fairly self-explanatory.  Each of these is required, and
410     will be sent for every request.</p>
411   
412   <h3>Headers</h3>
413     <p>The structure of <code>request_headers</code> is the following:
414     First, the number of headers <code>num_headers</code> is encoded.
415     Then, a series of header name <code>req_header_name</code> / value
416     <code>req_header_value</code> pairs follows.
417     Common header names are encoded as integers,
418     to save space.  If the header name is not in the list of basic headers,
419     it is encoded normally (as a string, with prefixed length).  The list of
420     common headers <code>sc_req_header_name</code>and their codes
421     is as follows (all are case-sensitive):</p>
422     <table>
423       <tr><td>Name</td><td>Code value</td><td>Code name</td></tr>
424       <tr><td>accept</td><td>0xA001</td><td>SC_REQ_ACCEPT</td></tr>
425       <tr><td>accept-charset</td><td>0xA002</td><td>SC_REQ_ACCEPT_CHARSET
426       </td></tr>
427       <tr><td>accept-encoding</td><td>0xA003</td><td>SC_REQ_ACCEPT_ENCODING
428       </td></tr>
429       <tr><td>accept-language</td><td>0xA004</td><td>SC_REQ_ACCEPT_LANGUAGE
430       </td></tr>
431       <tr><td>authorization</td><td>0xA005</td><td>SC_REQ_AUTHORIZATION</td>
432       </tr>
433       <tr><td>connection</td><td>0xA006</td><td>SC_REQ_CONNECTION</td></tr>
434       <tr><td>content-type</td><td>0xA007</td><td>SC_REQ_CONTENT_TYPE</td>
435       </tr>
436       <tr><td>content-length</td><td>0xA008</td><td>SC_REQ_CONTENT_LENGTH</td>
437       </tr>
438       <tr><td>cookie</td><td>0xA009</td><td>SC_REQ_COOKIE</td></tr>
439       <tr><td>cookie2</td><td>0xA00A</td><td>SC_REQ_COOKIE2</td></tr>
440       <tr><td>host</td><td>0xA00B</td><td>SC_REQ_HOST</td></tr>
441       <tr><td>pragma</td><td>0xA00C</td><td>SC_REQ_PRAGMA</td></tr>
442       <tr><td>referer</td><td>0xA00D</td><td>SC_REQ_REFERER</td></tr>
443       <tr><td>user-agent</td><td>0xA00E</td><td>SC_REQ_USER_AGENT</td></tr>
444     </table>
445     <p>The Java code that reads this grabs the first two-byte integer and if
446     it sees an <code>'0xA0'</code> 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 <code>0xA0</code>, it assumes that
449     the two-byte integer is the length of a string, which is then read in.</p>
450     <p>This works on the assumption that no header names will have length
451     greater than <code>0x9FFF (==0xA000 - 1)</code>, which is perfectly
452     reasonable, though somewhat arbitrary.</p>
453     <div class="note"><h3>Note:</h3>
454     The <code>content-length</code> header is extremely
455     important.  If it is present and non-zero, the container assumes that
456     the request has a body (a POST request, for example), and immediately
457     reads a separate packet off the input stream to get that body.
458     </div>
459   
460   <h3>Attributes</h3>
461     <p>The attributes prefixed with a <code>?</code>
462     (e.g. <code>?context</code>) are all optional.  For each, there is a
463     single byte code to indicate the type of attribute, and then its value
464     (string or integer).  They can be sent in any order (though the C code
465     always sends them in the order listed below).  A special terminating code
466     is sent to signal the end of the list of optional attributes. The list of
467     byte codes is:</p>
468     <table>
469       <tr><td>Information</td><td>Code Value</td><td>Type Of Value</td><td>Note</td></tr>
470       <tr><td>?context</td><td>0x01</td><td>-</td><td>Not currently implemented
471       </td></tr>
472       <tr><td>?servlet_path</td><td>0x02</td><td>-</td><td>Not currently implemented
473       </td></tr>
474       <tr><td>?remote_user</td><td>0x03</td><td>String</td><td /></tr>
475       <tr><td>?auth_type</td><td>0x04</td><td>String</td><td /></tr>
476       <tr><td>?query_string</td><td>0x05</td><td>String</td><td /></tr>
477       <tr><td>?jvm_route</td><td>0x06</td><td>String</td><td /></tr>
478       <tr><td>?ssl_cert</td><td>0x07</td><td>String</td><td /></tr>
479       <tr><td>?ssl_cipher</td><td>0x08</td><td>String</td><td /></tr>
480       <tr><td>?ssl_session</td><td>0x09</td><td>String</td><td /></tr>
481       <tr><td>?req_attribute</td><td>0x0A</td><td>String</td><td>Name (the name of the
482       attribute follows)</td></tr>
483       <tr><td>?ssl_key_size</td><td>0x0B</td><td>Integer</td><td /></tr>
484       <tr><td>?secret</td><td>0x0C</td><td>String</td><td>Sent if secret is configured</td></tr>
485       <tr><td>are_done</td><td>0xFF</td><td>-</td><td>request_terminator</td></tr>
486     </table>
487     <p>The <code>context</code> and <code>servlet_path</code> are not
488     currently set by the C code, and most of the Java code completely ignores
489     whatever is sent over for those fields (and some of it will actually break
490     if a string is sent along after one of those codes).  I don't know if this
491     is a bug or an unimplemented feature or just vestigial code, but it's
492     missing from both sides of the connection.</p>
493     <p>The <code>remote_user</code> and <code>auth_type</code> presumably
494     refer to HTTP-level authentication, and communicate the remote user's
495     username and the type of authentication used to establish their identity
496     (e.g. Basic, Digest).</p>
497     <p>The <code>query_string</code>, <code>ssl_cert</code>,
498     <code>ssl_cipher</code>, <code>ssl_session</code> and
499     <code>ssl_key_size</code> refer to the
500     corresponding pieces of HTTP and HTTPS.</p>
501     <p>The <code>jvm_route</code>, is used to support sticky
502     sessions -- associating a user's sesson with a particular Tomcat instance
503     in the presence of multiple, load-balancing servers.</p>
504     <p>Beyond this list of basic attributes, any number of other attributes
505     can be sent via the <code>req_attribute</code> code <code>0x0A</code>.
506     A pair of strings to represent the attribute name and value are sent
507     immediately after each instance of that code.  Environment values are passed
508     in via this method.</p>
509     <p>The <code>secret</code> is sent when the <code>secret=secret_keyword</code> parameter is
510     used in
511     <code class="directive"><a href="../mod/mod_proxy.html#proxypass">ProxyPass</a></code> or
512     <code class="directive"><a href="../mod/mod_proxy.html#balancermember">BalancerMember</a></code> directives.
513     The backend needs to support secret and the values must match.
514     <code>request.secret</code> or <code>requiredSecret</code> are documented in the AJP
515     configuration of the Apache Tomcat.</p>
516     <p>Finally, after all the attributes have been sent, the attribute
517     terminator, <code>0xFF</code>, is sent.  This signals both the end of the
518     list of attributes and also then end of the Request Packet.</p>
519   
520 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
521 <div class="section">
522 <h2><a name="resppacketstruct" id="resppacketstruct">Response Packet Structure</a> <a title="Permanent link" href="#resppacketstruct" class="permalink">&para;</a></h2>
523     <p>for messages which the container can send back to the server.</p>
524     <div class="example"><pre>AJP13_SEND_BODY_CHUNK :=
525   prefix_code   3
526   chunk_length  (integer)
527   chunk        *(byte)
528   chunk_terminator (byte) Ox00
529
530
531 AJP13_SEND_HEADERS :=
532   prefix_code       4
533   http_status_code  (integer)
534   http_status_msg   (string)
535   num_headers       (integer)
536   response_headers *(res_header_name header_value)
537
538 res_header_name :=
539     sc_res_header_name | (string)   [see below for how this is parsed]
540
541 sc_res_header_name := 0xA0 (byte)
542
543 header_value := (string)
544
545 AJP13_END_RESPONSE :=
546   prefix_code       5
547   reuse             (boolean)
548
549
550 AJP13_GET_BODY_CHUNK :=
551   prefix_code       6
552   requested_length  (integer)</pre></div>
553   <h3>Details:</h3>
554   <h3>Send Body Chunk</h3>
555     <p>The chunk is basically binary data, and is sent directly back to the
556     browser.</p>
557   
558   <h3>Send Headers</h3>
559     <p>The status code and message are the usual HTTP things
560     (e.g. <code>200</code> and <code>OK</code>). The response header names are
561     encoded the same way the request header names are. See header_encoding above
562     for details about how the codes are distinguished from the strings.<br />
563     The codes for common headers are:</p>
564     <table>
565       <tr><td>Name</td><td>Code value</td></tr>
566       <tr><td>Content-Type</td><td>0xA001</td></tr>
567       <tr><td>Content-Language</td><td>0xA002</td></tr>
568       <tr><td>Content-Length</td><td>0xA003</td></tr>
569       <tr><td>Date</td><td>0xA004</td></tr>
570       <tr><td>Last-Modified</td><td>0xA005</td></tr>
571       <tr><td>Location</td><td>0xA006</td></tr>
572       <tr><td>Set-Cookie</td><td>0xA007</td></tr>
573       <tr><td>Set-Cookie2</td><td>0xA008</td></tr>
574       <tr><td>Servlet-Engine</td><td>0xA009</td></tr>
575       <tr><td>Status</td><td>0xA00A</td></tr>
576       <tr><td>WWW-Authenticate</td><td>0xA00B</td></tr>
577     </table>
578     <p> After the code or the string header name, the header value is
579     immediately encoded.</p>
580   
581   <h3>End Response</h3>
582     <p>Signals the end of this request-handling cycle.  If the
583     <code>reuse</code> flag is true <code>(anything other than 0 in the actual
584     C code)</code>, this TCP connection can now be used to handle new incoming
585     requests.  If <code>reuse</code> is false (==0), the connection should
586     be closed.</p>
587   
588   <h3>Get Body Chunk</h3>
589     <p>The container asks for more data from the request (If the body was
590     too large to fit in the first packet sent over or when the request is
591     chunked). The server will send a body packet back with an amount of data
592     which is the minimum of the <code>request_length</code>, the maximum send
593     body size <code>(8186 (8 Kbytes - 6))</code>, and the number of bytes
594     actually left to send from the request body.<br />
595     If there is no more data in the body (i.e. the servlet container is
596     trying to read past the end of the body), the server will send back an
597     <em>empty</em> packet, which is a body packet with a payload length of 0.
598     <code>(0x12,0x34,0x00,0x00)</code></p>
599   
600 </div>
601 </div>
602 <div class="bottomlang">
603 <p><span>Available Languages: </span><a href="../en/mod/mod_proxy_ajp.html" title="English">&nbsp;en&nbsp;</a> |
604 <a href="../fr/mod/mod_proxy_ajp.html" hreflang="fr" rel="alternate" title="Français">&nbsp;fr&nbsp;</a> |
605 <a href="../ja/mod/mod_proxy_ajp.html" hreflang="ja" rel="alternate" title="Japanese">&nbsp;ja&nbsp;</a></p>
606 </div><div class="top"><a href="#page-header"><img src="../images/up.gif" alt="top" /></a></div><div class="section"><h2><a id="comments_section" name="comments_section">Comments</a></h2><div class="warning"><strong>Notice:</strong><br />This is not a Q&amp;A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed again by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Freenode, or sent to our <a href="http://httpd.apache.org/lists.html">mailing lists</a>.</div>
607 <script type="text/javascript"><!--//--><![CDATA[//><!--
608 var comments_shortname = 'httpd';
609 var comments_identifier = 'http://httpd.apache.org/docs/trunk/mod/mod_proxy_ajp.html';
610 (function(w, d) {
611     if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
612         d.write('<div id="comments_thread"><\/div>');
613         var s = d.createElement('script');
614         s.type = 'text/javascript';
615         s.async = true;
616         s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
617         (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
618     }
619     else {
620         d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>');
621     }
622 })(window, document);
623 //--><!]]></script></div><div id="footer">
624 <p class="apache">Copyright 2019 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p>
625 <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/quickreference.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p></div><script type="text/javascript"><!--//--><![CDATA[//><!--
626 if (typeof(prettyPrint) !== 'undefined') {
627     prettyPrint();
628 }
629 //--><!]]></script>
630 </body></html>