summaryrefslogtreecommitdiff
path: root/docs/manual/misc/client_block_api.html
blob: b01a58862288fac8ab137103bb1ab73e312f0f91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML>
<HEAD>
<TITLE>Reading Client Input in Apache 1.2</TITLE>
</HEAD>

<BODY>
<!--#include virtual="header.html" -->
<H1>Reading Client Input in Apache 1.2</h1>

<hr>

<p>Apache 1.1 and earlier let modules handle POST and PUT requests by
themselves. The module would, on its own, determine whether the
request had an entity, how many bytes it was, and then called a
function (<code>read_client_block</code>) to get the data.

<p>However, HTTP/1.1 requires several things of POST and PUT request
handlers that did not fit into this module, and all existing modules
have to be rewritten. The API calls for handling this have been
furthur abstracted, so that future HTTP protocol changes can be
accomplished while remaining backwards-compatible.</p>

<hr>

<h3>The New API Functions</h3>

<pre>
   int setup_client_block (request_rec *, int read_policy);
   int should_client_block (request_rec *);
   long get_client_block (request_rec *, char *buffer, int buffer_size);
</pre>

<ol>
<li>Call <code>setup_client_block()</code> near the beginning of the request
    handler. This will set up all the neccessary properties, and
    will return either OK, or an error code. If the latter,
    the module should return that error code. The second parameter
    selects the policy to apply if the request message indicates a
    body, and how a chunked
    transfer-coding should be interpreted. Choose one of
<pre>
    REQUEST_NO_BODY          Send 413 error if message has any body
    REQUEST_CHUNKED_ERROR    Send 411 error if body without Content-Length
    REQUEST_CHUNKED_DECHUNK  If chunked, remove the chunks for me.
    REQUEST_CHUNKED_PASS     Pass the chunks to me without removal.
</pre>
    In order to use the last two options, the caller MUST provide a buffer
    large enough to hold a chunk-size line, including any extensions.



<li>When you are ready to possibly accept input, call
    <code>should_client_block()</code>.
    This will tell the module whether or not to read input. If it is 0,
    the module should assume that the input is of a non-entity type
    (e.g. a GET request). A nonzero response indicates that the module
    should proceed (to step 3).
    This step also sends a 100 Continue response
    to HTTP/1.1 clients, so should not be called until the module
    is <strong>*definitely*</strong> ready to read content. (otherwise, the point of the
    100 response is defeated). Never call this function more than once.

<li>Finally, call <code>get_client_block</code> in a loop. Pass it a
    buffer and its 
    size. It will put data into the buffer (not neccessarily the full
    buffer, in the case of chunked inputs), and return the length of
    the input block. When it is done reading, it will
    return 0 if EOF, or -1 if there was an error.

</ol>

<p>As an example, please look at the code in
<code>mod_cgi.c</code>. This is properly written to the new API
guidelines.</p>

<!--#include virtual="footer.html" -->
</BODY>
</HTML>