From: Ruediger Pluem Date: Tue, 26 Jan 2016 12:13:56 +0000 (+0000) Subject: * Introduce ap_proxy_buckets_lifetime_transform as a replacement for X-Git-Tag: 2.5.0-alpha~2277 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=67ddd9009c92f8f1c083f4a77228a04f6e10ec3e;p=thirdparty%2Fapache%2Fhttpd.git * Introduce ap_proxy_buckets_lifetime_transform as a replacement for proxy_buckets_lifetime_transform in mod_proxy_http. Another future consumer of this will be mod_proxy_wstunnel. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1726779 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/modules/proxy/mod_proxy.h b/modules/proxy/mod_proxy.h index 59edc2558c5..c1d32bf354e 100644 --- a/modules/proxy/mod_proxy.h +++ b/modules/proxy/mod_proxy.h @@ -1140,6 +1140,29 @@ PROXY_DECLARE (const char *) ap_proxy_show_hcmethod(hcmethod_t method); */ PROXY_DECLARE(const char *) ap_proxy_de_socketfy(apr_pool_t *p, const char *url); +/* + * Transform buckets from one bucket allocator to another one by creating a + * transient bucket for each data bucket and let it use the data read from + * the old bucket. Metabuckets are transformed by just recreating them. + * Attention: Currently only the following bucket types are handled: + * + * All data buckets + * FLUSH + * EOS + * + * If an other bucket type is found its type is logged as a debug message + * and APR_EGENERAL is returned. + * + * @param r request_rec of the actual request. Used for logging purposes + * @param from the bucket brigade to take the buckets from + * @param to the bucket brigade to store the transformed buckets + * @return apr_status_t of the operation. Either APR_SUCCESS or + * APR_EGENERAL + */ +PROXY_DECLARE(apr_status_t) ap_proxy_buckets_lifetime_transform(request_rec *r, + apr_bucket_brigade *from, + apr_bucket_brigade *to); + extern module PROXY_DECLARE_DATA proxy_module; #endif /*MOD_PROXY_H*/ diff --git a/modules/proxy/proxy_util.c b/modules/proxy/proxy_util.c index b268afb3e2b..cc7305ba78e 100644 --- a/modules/proxy/proxy_util.c +++ b/modules/proxy/proxy_util.c @@ -3710,6 +3710,44 @@ PROXY_DECLARE (const char *) ap_proxy_show_hcmethod(hcmethod_t method) return "???"; } +PROXY_DECLARE(apr_status_t) ap_proxy_buckets_lifetime_transform(request_rec *r, + apr_bucket_brigade *from, + apr_bucket_brigade *to) +{ + apr_bucket *e; + apr_bucket *new; + const char *data; + apr_size_t bytes; + apr_status_t rv = APR_SUCCESS; + apr_bucket_alloc_t *bucket_alloc = to->bucket_alloc; + + apr_brigade_cleanup(to); + for (e = APR_BRIGADE_FIRST(from); + e != APR_BRIGADE_SENTINEL(from); + e = APR_BUCKET_NEXT(e)) { + if (!APR_BUCKET_IS_METADATA(e)) { + apr_bucket_read(e, &data, &bytes, APR_BLOCK_READ); + new = apr_bucket_transient_create(data, bytes, bucket_alloc); + APR_BRIGADE_INSERT_TAIL(to, new); + } + else if (APR_BUCKET_IS_FLUSH(e)) { + new = apr_bucket_flush_create(bucket_alloc); + APR_BRIGADE_INSERT_TAIL(to, new); + } + else if (APR_BUCKET_IS_EOS(e)) { + new = apr_bucket_eos_create(bucket_alloc); + APR_BRIGADE_INSERT_TAIL(to, new); + } + else { + ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO() + "Unhandled bucket type of type %s in" + " ap_proxy_buckets_lifetime_transform", e->type->name); + rv = APR_EGENERAL; + } + } + return rv; +} + void proxy_util_register_hooks(apr_pool_t *p) { APR_REGISTER_OPTIONAL_FN(ap_proxy_retry_worker);