Skip to content

Commit 2a4d6bb

Browse files
committed
Move the KeptBodySize directive, kept_body filters and the
ap_parse_request_body function out of the http module and into a new module called mod_request, reducing the size of the core. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@647263 13f79535-47bb-0310-9956-ffa450edef68
1 parent 8d42ca8 commit 2a4d6bb

13 files changed

Lines changed: 823 additions & 554 deletions

File tree

CHANGES

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
Changes with Apache 2.3.0
33
[ When backported to 2.2.x, remove entry from this file ]
44

5+
*) Move the KeptBodySize directive, kept_body filters and the
6+
ap_parse_request_body function out of the http module and into a
7+
new module called mod_request, reducing the size of the core.
8+
[Graham Leggett]
9+
510
*) rotatelogs: Log the current file size and error code/description
611
when failing to write to the log file. [Jeff Trawick]
712

docs/manual/mod/core.xml

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,63 +1563,6 @@ requests on a persistent connection</description>
15631563
</usage>
15641564
</directivesynopsis>
15651565

1566-
<directivesynopsis>
1567-
<name>KeptBodySize</name>
1568-
<description>Keep the request body instead of discarding it up to
1569-
the specified maximum size, for potential use by filters such as
1570-
mod_include.</description>
1571-
<syntax>KeptBodySize <var>maximum size in bytes</var></syntax>
1572-
<default>KeptBodySize 0</default>
1573-
<contextlist><context>directory</context>
1574-
</contextlist>
1575-
1576-
<usage>
1577-
<p>Under normal circumstances, request handlers such as the
1578-
default handler for static files will discard the request body
1579-
when it is not needed by the request handler. As a result,
1580-
filters such as mod_include are limited to making <code>GET</code> requests
1581-
only when including other URLs as subrequests, even if the
1582-
original request was a <code>POST</code> request, as the discarded
1583-
request body is no longer available once filter processing is
1584-
taking place.</p>
1585-
1586-
<p>When this directive has a value greater than zero, request
1587-
handlers that would otherwise discard request bodies will
1588-
instead set the request body aside for use by filters up to
1589-
the maximum size specified. In the case of the mod_include
1590-
filter, an attempt to <code>POST</code> a request to the static
1591-
shtml file will cause any subrequests to be <code>POST</code>
1592-
requests, instead of <code>GET</code> requests as before.</p>
1593-
1594-
<p>This feature makes it possible to break up complex web pages and
1595-
web applications into small individual components, and combine
1596-
the components and the surrounding web page structure together
1597-
using <module>mod_include</module>. The components can take the
1598-
form of CGI programs, scripted languages, or URLs reverse proxied
1599-
into the URL space from another server using
1600-
<module>mod_proxy</module>.</p>
1601-
1602-
<p><strong>Note:</strong> Each request set aside has to be set
1603-
aside in temporary RAM until the request is complete. As a result,
1604-
care should be taken to ensure sufficient RAM is available on the
1605-
server to support the intended load. Use of this directive
1606-
should be limited to where needed on targeted parts of your
1607-
URL space, and with the lowest possible value that is still big
1608-
enough to hold a request body.</p>
1609-
1610-
<p>If the request size sent by the client exceeds the maximum
1611-
size allocated by this directive, the server will return
1612-
<code>413 Request Entity Too Large</code>.</p>
1613-
1614-
<p>Handlers such as <module>mod_cgi</module> that consume request
1615-
bodies for their own purposes rather than discard them do not take
1616-
this directive into account.</p>
1617-
1618-
</usage>
1619-
1620-
<seealso><a href="mod_include.html">mod_include</a> documentation</seealso>
1621-
</directivesynopsis>
1622-
16231566
<directivesynopsis type="section">
16241567
<name>Limit</name>
16251568
<description>Restrict enclosed access controls to only certain HTTP

docs/manual/mod/mod_include.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@
352352
to <code>exec cgi</code> to include the output of CGI programs
353353
into an HTML document.</p>
354354

355-
<p>If the <directive module="core">KeptBodySize</directive>
355+
<p>If the <directive module="mod_request">KeptBodySize</directive>
356356
directive is correctly configured and valid for this included
357357
file, attempts to POST requests to the enclosing HTML document
358358
will be passed through to subrequests as POST requests as well.

docs/manual/mod/mod_request.xml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?xml version="1.0"?>
2+
<!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3+
<?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4+
<!-- $LastChangedRevision$ -->
5+
6+
<!--
7+
Licensed to the Apache Software Foundation (ASF) under one or more
8+
contributor license agreements. See the NOTICE file distributed with
9+
this work for additional information regarding copyright ownership.
10+
The ASF licenses this file to You under the Apache License, Version 2.0
11+
(the "License"); you may not use this file except in compliance with
12+
the License. You may obtain a copy of the License at
13+
14+
http://www.apache.org/licenses/LICENSE-2.0
15+
16+
Unless required by applicable law or agreed to in writing, software
17+
distributed under the License is distributed on an "AS IS" BASIS,
18+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
See the License for the specific language governing permissions and
20+
limitations under the License.
21+
-->
22+
23+
<modulesynopsis metafile="mod_request_body.xml.meta">
24+
25+
<name>request_body</name>
26+
<description>Filters to handle and make available HTTP request bodies</description>
27+
<status>Core</status>
28+
29+
<directivesynopsis>
30+
<name>KeptBodySize</name>
31+
<description>Keep the request body instead of discarding it up to
32+
the specified maximum size, for potential use by filters such as
33+
mod_include.</description>
34+
<syntax>KeptBodySize <var>maximum size in bytes</var></syntax>
35+
<default>KeptBodySize 0</default>
36+
<contextlist><context>directory</context>
37+
</contextlist>
38+
39+
<usage>
40+
<p>Under normal circumstances, request handlers such as the
41+
default handler for static files will discard the request body
42+
when it is not needed by the request handler. As a result,
43+
filters such as mod_include are limited to making <code>GET</code> requests
44+
only when including other URLs as subrequests, even if the
45+
original request was a <code>POST</code> request, as the discarded
46+
request body is no longer available once filter processing is
47+
taking place.</p>
48+
49+
<p>When this directive has a value greater than zero, request
50+
handlers that would otherwise discard request bodies will
51+
instead set the request body aside for use by filters up to
52+
the maximum size specified. In the case of the mod_include
53+
filter, an attempt to <code>POST</code> a request to the static
54+
shtml file will cause any subrequests to be <code>POST</code>
55+
requests, instead of <code>GET</code> requests as before.</p>
56+
57+
<p>This feature makes it possible to break up complex web pages and
58+
web applications into small individual components, and combine
59+
the components and the surrounding web page structure together
60+
using <module>mod_include</module>. The components can take the
61+
form of CGI programs, scripted languages, or URLs reverse proxied
62+
into the URL space from another server using
63+
<module>mod_proxy</module>.</p>
64+
65+
<p><strong>Note:</strong> Each request set aside has to be set
66+
aside in temporary RAM until the request is complete. As a result,
67+
care should be taken to ensure sufficient RAM is available on the
68+
server to support the intended load. Use of this directive
69+
should be limited to where needed on targeted parts of your
70+
URL space, and with the lowest possible value that is still big
71+
enough to hold a request body.</p>
72+
73+
<p>If the request size sent by the client exceeds the maximum
74+
size allocated by this directive, the server will return
75+
<code>413 Request Entity Too Large</code>.</p>
76+
77+
</usage>
78+
79+
<seealso><a href="mod_include.html">mod_include</a> documentation</seealso>
80+
<seealso><a href="mod_auth_form.html">mod_auth_form</a> documentation</seealso>
81+
</directivesynopsis>
82+
83+
</modulesynopsis>

include/http_protocol.h

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -670,54 +670,6 @@ AP_DECLARE(void) ap_finalize_sub_req_protocol(request_rec *sub_r);
670670
*/
671671
AP_DECLARE(void) ap_send_interim_response(request_rec *r, int send_headers);
672672

673-
/**
674-
* Structure to store the contents of an HTTP form of the type
675-
* application/x-www-form-urlencoded.
676-
*
677-
* Currently it contains the name as a char* of maximum length
678-
* HUGE_STRING_LEN, and a value in the form of a bucket brigade
679-
* of arbitrary length.
680-
*/
681-
typedef struct {
682-
const char *name;
683-
apr_bucket_brigade *value;
684-
} ap_form_pair_t;
685-
686-
/**
687-
* Read the body and parse any form found, which must be of the
688-
* type application/x-www-form-urlencoded.
689-
*
690-
* Name/value pairs are returned in an array, with the names as
691-
* strings with a maximum length of HUGE_STRING_LEN, and the
692-
* values as bucket brigades. This allows values to be arbitrarily
693-
* large.
694-
*
695-
* All url-encoding is removed from both the names and the values
696-
* on the fly. The names are interpreted as strings, while the
697-
* values are interpreted as blocks of binary data, that may
698-
* contain the 0 character.
699-
*
700-
* In order to ensure that resource limits are not exceeded, a
701-
* maximum size must be provided. If the sum of the lengths of
702-
* the names and the values exceed this size, this function
703-
* will return HTTP_REQUEST_ENTITY_TOO_LARGE.
704-
*
705-
* An optional number of parameters can be provided, if the number
706-
* of parameters provided exceeds this amount, this function will
707-
* return HTTP_REQUEST_ENTITY_TOO_LARGE. If this value is negative,
708-
* no limit is imposed, and the number of parameters is in turn
709-
* constrained by the size parameter above.
710-
*
711-
* This function honours any kept_body configuration, and the
712-
* original raw request body will be saved to the kept_body brigade
713-
* if so configured, just as ap_discard_request_body does.
714-
*
715-
* NOTE: File upload is not yet supported, but can be without change
716-
* to the function call.
717-
*/
718-
AP_DECLARE(int) ap_parse_request_form(request_rec * r, apr_array_header_t ** ptr,
719-
apr_size_t num, apr_size_t size);
720-
721673
#ifdef __cplusplus
722674
}
723675
#endif

include/mod_request.h

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/* Licensed to the Apache Software Foundation (ASF) under one or more
2+
* contributor license agreements. See the NOTICE file distributed with
3+
* this work for additional information regarding copyright ownership.
4+
* The ASF licenses this file to You under the Apache License, Version 2.0
5+
* (the "License"); you may not use this file except in compliance with
6+
* the License. You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
18+
/**
19+
* @file mod_request.h
20+
* @brief mod_request private header file
21+
*
22+
* @defgroup MOD_REQUEST mod_request
23+
* @ingroup APACHE_MODS
24+
* @{
25+
*/
26+
27+
#ifndef MOD_REQUEST_H
28+
#define MOD_REQUEST_H
29+
30+
#include "apr.h"
31+
#include "apr_buckets.h"
32+
33+
#include "httpd.h"
34+
#include "util_filter.h"
35+
36+
37+
#ifdef __cplusplus
38+
extern "C" {
39+
#endif
40+
41+
extern module AP_MODULE_DECLARE_DATA request_module;
42+
43+
#define KEEP_BODY_FILTER "KEEP_BODY"
44+
#define KEPT_BODY_FILTER "KEPT_BODY"
45+
46+
/**
47+
* Core per-directory configuration.
48+
*/
49+
typedef struct {
50+
apr_off_t keep_body;
51+
int keep_body_set;
52+
} request_dir_conf;
53+
54+
/* Handles for core filters */
55+
extern AP_DECLARE_DATA ap_filter_rec_t *ap_keep_body_input_filter_handle;
56+
extern AP_DECLARE_DATA ap_filter_rec_t *ap_kept_body_input_filter_handle;
57+
58+
/* Filter to set aside a kept body on subrequests */
59+
AP_DECLARE(apr_status_t) ap_keep_body_filter(ap_filter_t *f, apr_bucket_brigade *b,
60+
ap_input_mode_t mode, apr_read_type_e block,
61+
apr_off_t readbytes);
62+
63+
/* Filter to insert a kept body on subrequests */
64+
AP_DECLARE(apr_status_t) ap_kept_body_filter(ap_filter_t *f, apr_bucket_brigade *b,
65+
ap_input_mode_t mode, apr_read_type_e block,
66+
apr_off_t readbytes);
67+
68+
/**
69+
* Structure to store the contents of an HTTP form of the type
70+
* application/x-www-form-urlencoded.
71+
*
72+
* Currently it contains the name as a char* of maximum length
73+
* HUGE_STRING_LEN, and a value in the form of a bucket brigade
74+
* of arbitrary length.
75+
*/
76+
typedef struct {
77+
const char *name;
78+
apr_bucket_brigade *value;
79+
} ap_form_pair_t;
80+
81+
/**
82+
* Read the body and parse any form found, which must be of the
83+
* type application/x-www-form-urlencoded.
84+
*
85+
* Name/value pairs are returned in an array, with the names as
86+
* strings with a maximum length of HUGE_STRING_LEN, and the
87+
* values as bucket brigades. This allows values to be arbitrarily
88+
* large.
89+
*
90+
* All url-encoding is removed from both the names and the values
91+
* on the fly. The names are interpreted as strings, while the
92+
* values are interpreted as blocks of binary data, that may
93+
* contain the 0 character.
94+
*
95+
* In order to ensure that resource limits are not exceeded, a
96+
* maximum size must be provided. If the sum of the lengths of
97+
* the names and the values exceed this size, this function
98+
* will return HTTP_REQUEST_ENTITY_TOO_LARGE.
99+
*
100+
* An optional number of parameters can be provided, if the number
101+
* of parameters provided exceeds this amount, this function will
102+
* return HTTP_REQUEST_ENTITY_TOO_LARGE. If this value is negative,
103+
* no limit is imposed, and the number of parameters is in turn
104+
* constrained by the size parameter above.
105+
*
106+
* This function honours any kept_body configuration, and the
107+
* original raw request body will be saved to the kept_body brigade
108+
* if so configured, just as ap_discard_request_body does.
109+
*
110+
* NOTE: File upload is not yet supported, but can be without change
111+
* to the function call.
112+
*/
113+
AP_DECLARE(int) ap_parse_request_form(request_rec * r, apr_array_header_t ** ptr,
114+
apr_size_t num, apr_size_t size);
115+
116+
APR_DECLARE_OPTIONAL_FN(void, ap_parse_request_form, (request_rec * r, apr_array_header_t ** ptr,
117+
apr_size_t num, apr_size_t size));
118+
119+
#ifdef __cplusplus
120+
}
121+
#endif
122+
123+
#endif /* !MOD_REQUEST_H */
124+
/** @} */

modules/aaa/mod_auth_form.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
#include "mod_auth.h"
3535
#include "mod_session.h"
36+
#include "mod_request.h"
3637

3738
#define LOG_PREFIX "mod_auth_form: "
3839
#define FORM_LOGIN_HANDLER "form-login-handler"
@@ -45,6 +46,8 @@ static void (*ap_session_get_fn) (request_rec * r, session_rec * z,
4546
const char *key, const char **value) = NULL;
4647
static void (*ap_session_set_fn) (request_rec * r, session_rec * z,
4748
const char *key, const char *value) = NULL;
49+
static void (*ap_parse_request_form_fn) (request_rec * r, apr_array_header_t ** ptr,
50+
apr_size_t num, apr_size_t size) = NULL;
4851

4952
typedef struct {
5053
authn_provider_list *providers;
@@ -176,7 +179,15 @@ static const char *add_authn_provider(cmd_parms * cmd, void *config,
176179
ap_session_set_fn = APR_RETRIEVE_OPTIONAL_FN(ap_session_set);
177180
if (!ap_session_load_fn || !ap_session_get_fn || !ap_session_set_fn) {
178181
return "You must load mod_session to enable the mod_auth_form "
179-
"functions";
182+
"functions";
183+
}
184+
}
185+
186+
if (!ap_parse_request_form_fn) {
187+
ap_parse_request_form_fn = APR_RETRIEVE_OPTIONAL_FN(ap_parse_request_form);
188+
if (!ap_parse_request_form_fn) {
189+
return "You must load mod_request to enable the mod_auth_form "
190+
"functions";
180191
}
181192
}
182193

modules/filters/config.m4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ dnl APACHE_MODULE(name, helptext[, objects[, structname[, default[, config]]]])
55
APACHE_MODPATH_INIT(filters)
66

77
APACHE_MODULE(ext_filter, external filter module, , , most)
8+
APACHE_MODULE(request, Request Body Filtering, , , yes)
89
APACHE_MODULE(include, Server Side Includes, , , yes)
910
APACHE_MODULE(filter, Smart Filtering, , , yes)
1011
APACHE_MODULE(substitute, response content rewrite-like filtering, , , most)

0 commit comments

Comments
 (0)