/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* mod_request.c --- HTTP routines to set aside or process request bodies.
*/
#include "apr.h"
#include "apr_strings.h"
#include "apr_buckets.h"
#include "apr_lib.h"
#include "ap_config.h"
#include "httpd.h"
#include "http_config.h"
#include "http_protocol.h"
#include "http_log.h" /* For errors detected in basic auth common
* support code... */
#include "http_request.h"
#include "mod_request.h"
/* Handles for core filters */
ap_filter_t *f,
int http_error)
{
apr_bucket *e;
f->c->bucket_alloc);
e = apr_bucket_eos_create(f->c->bucket_alloc);
}
typedef struct keep_body_filter_ctx {
/**
* This is the KEEP_BODY_INPUT filter for HTTP requests, for times when the
* body should be set aside for future use by other modules.
*/
{
apr_bucket *e;
if (!ctx) {
const char *lenp;
/* must we step out of the way? */
}
/* fail fast if the content length exceeds keep body */
if (lenp) {
* string (excluding leading space) (the endstr checks)
* and a negative number. */
"Invalid Content-Length");
return bail_out_on_error(b, f, HTTP_REQUEST_ENTITY_TOO_LARGE);
}
/* If we have a limit in effect and we know the C-L ahead of
* time, stop it here if it is invalid.
*/
"Requested content-length of %" APR_OFF_T_FMT
" is larger than the configured limit"
return bail_out_on_error(b, f, HTTP_REQUEST_ENTITY_TOO_LARGE);
}
}
}
/* get the brigade from upstream, and read it in to get its length */
if (rv == APR_SUCCESS) {
}
/* does the length take us over the limit? */
if (f->r->kept_body) {
apr_brigade_cleanup(f->r->kept_body);
}
"Requested content-length of %" APR_OFF_T_FMT
" is larger than the configured limit"
return bail_out_on_error(b, f, HTTP_REQUEST_ENTITY_TOO_LARGE);
}
/* pass any errors downstream */
if (rv != APR_SUCCESS) {
if (f->r->kept_body) {
apr_brigade_cleanup(f->r->kept_body);
}
return rv;
}
/* all is well, set aside the buckets */
for (bucket = APR_BRIGADE_FIRST(b);
bucket != APR_BRIGADE_SENTINEL(b);
{
apr_bucket_copy(bucket, &e);
APR_BRIGADE_INSERT_TAIL(f->r->kept_body, e);
}
return APR_SUCCESS;
}
typedef struct kept_body_filter_ctx {
/**
* Initialisation of filter to handle a kept body on subrequests.
*
* If a body is to be reinserted into a subrequest, any chunking will have
* been removed from the body during storage. We need to change the request
* from Transfer-Encoding: chunked to an explicit Content-Length.
*/
request_rec *r = f->r;
if (kept_body) {
}
return OK;
}
/**
* Filter to handle a kept body on subrequests.
*
* If a body has been previously kept by the request, and if a subrequest wants
* to re-insert the body into the request, this input filter makes it happen.
*/
{
request_rec *r = f->r;
/* just get out of the way of things we don't want. */
}
/* set up the context if it does not already exist */
if (!ctx) {
}
/* kept_body is finished, send next filter */
}
/* send all of the kept_body, but no more */
}
/* send part of the kept_body */
return rv;
}
return rv;
}
do {
const char *str;
/* As above; this should not fail since the bucket has
* a known length, but just to be sure, this takes
* care of uncopyable buckets that do somehow manage
* to slip through. */
/* XXX: check for failure? */
}
return APR_SUCCESS;
}
/**
* Check whether this filter is not already present.
*/
{
ap_filter_t * f = r->input_filters;
while (f) {
return 1;
}
f = f->next;
}
return 0;
}
/**
* Insert filter hook.
*
* Add the KEEP_BODY filter to the request, if the admin wants to keep
* the body using the KeptBodySize directive.
*
* As a precaution, any pre-existing instances of either the kept_body or
* keep_body filters will be removed before the filter is added.
*
* @param r The request
*/
{
if (r->kept_body) {
NULL, r, r->connection);
}
}
NULL, r, r->connection);
}
}
}
/**
* Remove the kept_body and keep body filters from this specific request.
*/
{
ap_filter_t * f = r->input_filters;
while (f) {
}
f = f->next;
}
}
{
return (void *) new;
}
{
return new;
}
const char *arg)
{
return "KeptBodySize must be a valid size in bytes, or zero.";
}
return NULL;
}
"Maximum size of request bodies kept aside for use by filters"),
{ NULL }
};
{
}
create_request_dir_config, /* create per-directory config structure */
merge_request_dir_config, /* merge per-directory config structures */
NULL, /* create per-server config structure */
NULL, /* merge per-server config structures */
request_cmds, /* command apr_table_t */
register_hooks /* register hooks */
};