summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorBill Stoddard <stoddard@apache.org>2001-09-07 04:56:11 +0200
committerBill Stoddard <stoddard@apache.org>2001-09-07 04:56:11 +0200
commitb2d20857c669c6198593c86649c652f5dd5ede28 (patch)
treef18e4cea98fb4d2c4dfb13d8c80a42d9524eb8c0 /modules
parentSpell checking. (diff)
downloadapache2-b2d20857c669c6198593c86649c652f5dd5ede28.tar.xz
apache2-b2d20857c669c6198593c86649c652f5dd5ede28.zip
Pass headers on read/write header calls. Update mod_mem_cache to cache headers.
So much to do so little time ... git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@90947 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'modules')
-rw-r--r--modules/experimental/cache_storage.c28
-rw-r--r--modules/experimental/mod_cache.c2
-rw-r--r--modules/experimental/mod_cache.h10
-rw-r--r--modules/experimental/mod_mem_cache.c68
4 files changed, 72 insertions, 36 deletions
diff --git a/modules/experimental/cache_storage.c b/modules/experimental/cache_storage.c
index 06776013d0..d51960ba64 100644
--- a/modules/experimental/cache_storage.c
+++ b/modules/experimental/cache_storage.c
@@ -189,13 +189,9 @@ int cache_select_url(request_rec *r, const char *types, char *url)
}
apr_status_t cache_write_entity_headers(cache_handle *h, request_rec *r, cache_info *info,
- apr_table_t *headers_in, apr_table_t *headers_out)
+ apr_table_t *headers)
{
- const char *ct;
-
- ct = ap_table_get(r->headers_out, "Content-Type");
- info->content_type = ct;
- h->write_headers(h, r, info);
+ h->write_headers(h, r, info, headers);
return APR_SUCCESS;
}
apr_status_t cache_write_entity_body(cache_handle *h, apr_bucket_brigade *b)
@@ -211,27 +207,11 @@ apr_status_t cache_read_entity_headers(cache_handle *h, request_rec *r,
{
cache_info *info;
- /* Be careful to not modify info. */
- h->read_headers(h, r, &info);
-
/* Build the header table from info in the info struct */
*headers = apr_table_make(r->pool, 15);
- /* Content-Length */
- if (info->len)
- apr_table_set(*headers, "Content-Length",
- apr_psprintf(r->pool, "%" APR_SIZE_T_FMT, info->len));
- /* Last-Modified */
- if (info->lastmod) {
- }
- /* Expires */
- if (info->expire) {
- }
- if (info->content_type) {
- r->content_type = apr_pstrdup(r->pool, info->content_type);
- }
- /* Date */
-
+ h->read_headers(h, r, &info, *headers);
+
return APR_SUCCESS;
}
apr_status_t cache_read_entity_body(cache_handle *h, apr_bucket_brigade *b)
diff --git a/modules/experimental/mod_cache.c b/modules/experimental/mod_cache.c
index 3d7688a893..d611b69e8a 100644
--- a/modules/experimental/mod_cache.c
+++ b/modules/experimental/mod_cache.c
@@ -631,7 +631,7 @@ int ap_cache_in_filter(ap_filter_t *f, apr_bucket_brigade *in)
/*
* Write away header information to cache.
*/
- cache_write_entity_headers(cache->handle, r, info, r->headers_in, r->headers_out);
+ cache_write_entity_headers(cache->handle, r, info, r->headers_out);
cache_write_entity_body(cache->handle, in);
return ap_pass_brigade(f->next, in);
}
diff --git a/modules/experimental/mod_cache.h b/modules/experimental/mod_cache.h
index c68462cd56..c6cfb24ac2 100644
--- a/modules/experimental/mod_cache.h
+++ b/modules/experimental/mod_cache.h
@@ -175,9 +175,9 @@ struct cache_handle {
/* Cache call back functions */
int (*remove_entity) (cache_handle *h);
- int (*write_headers)(cache_handle *h, request_rec *r, cache_info *i);
+ int (*write_headers)(cache_handle *h, request_rec *r, cache_info *i, apr_table_t *headers);
int (*write_body)(cache_handle *h, apr_bucket_brigade *b);
- int (*read_headers) (cache_handle *h, request_rec *r, cache_info **i);
+ int (*read_headers) (cache_handle *h, request_rec *r, cache_info **i, apr_table_t *headers);
int (*read_body) (cache_handle *h, apr_bucket_brigade *bb);
};
@@ -208,7 +208,7 @@ int cache_remove_entity(request_rec *r, const char *types, cache_handle *h);
int cache_select_url(request_rec *r, const char *types, char *url);
apr_status_t cache_write_entity_headers(cache_handle *h, request_rec *r, cache_info *info,
- apr_table_t *headers_in, apr_table_t *headers_out);
+ apr_table_t *headers);
apr_status_t cache_write_entity_body(cache_handle *h, apr_bucket_brigade *bb);
apr_status_t cache_read_entity_headers(cache_handle *h, request_rec *r, apr_table_t **headers);
@@ -252,13 +252,13 @@ APR_DECLARE_EXTERNAL_HOOK(cache, CACHE, int, remove_entity,
(cache_handle *h))
APR_DECLARE_EXTERNAL_HOOK(cache, CACHE, int, read_entity_headers,
(cache_handle *h, cache_info **info,
- apr_table_t **headers_in, apr_table_t **headers_out))
+ apr_table_t **headers))
APR_DECLARE_EXTERNAL_HOOK(cache, CACHE, int, read_entity_body,
(cache_handle *h,
apr_bucket_brigade *out))
APR_DECLARE_EXTERNAL_HOOK(cache, CACHE, int, write_entity_headers,
(cache_handle *h, cache_info *info,
- apr_table_t *headers_in, apr_table_t *headers_out))
+ apr_table_t *headers))
APR_DECLARE_EXTERNAL_HOOK(cache, CACHE, int, write_entity_body,
(cache_handle *h,
apr_bucket_brigade *in))
diff --git a/modules/experimental/mod_mem_cache.c b/modules/experimental/mod_mem_cache.c
index ea6811c323..36befaf758 100644
--- a/modules/experimental/mod_mem_cache.c
+++ b/modules/experimental/mod_mem_cache.c
@@ -81,10 +81,17 @@ typedef enum {
} cache_type_e;
typedef struct {
+ char* hdr;
+ char* val;
+} cache_header_tbl_t;
+
+typedef struct {
cache_type_e type;
char *key;
- void *m;
+ apr_ssize_t num_headers;
+ cache_header_tbl_t *tbl;
apr_size_t m_len;
+ void *m;
cache_info info;
int complete;
} cache_object_t;
@@ -103,9 +110,11 @@ static mem_cache_conf *sconf;
/* Forward declarations */
static int remove_entity(cache_handle *h);
-static int write_headers(cache_handle *h, request_rec *r, cache_info *i);
+static int write_headers(cache_handle *h, request_rec *r, cache_info *i,
+ apr_table_t *headers);
static int write_body(cache_handle *h, apr_bucket_brigade *b);
-static int read_headers(cache_handle *h, request_rec *r, cache_info **info);
+static int read_headers(cache_handle *h, request_rec *r, cache_info **info,
+ apr_table_t *headers);
static int read_body(cache_handle *h, apr_bucket_brigade *bb);
static void cleanup_cache_object(cache_object_t *obj)
@@ -147,6 +156,10 @@ static void cleanup_cache_object(cache_object_t *obj)
if (obj->m)
free(obj->m);
+ /* XXX Cleanup the headers */
+ if (obj->num_headers) {
+
+ }
free(obj);
}
@@ -377,10 +390,15 @@ static int remove_url(const char *type, char *key)
return OK;
}
-static int read_headers(cache_handle *h, request_rec *r, cache_info **info)
+static int read_headers(cache_handle *h, request_rec *r, cache_info **info,
+ apr_table_t *headers)
{
cache_object_t *obj = (cache_object_t*) h->cache_obj;
+ int i;
+ for (i = 0; i < obj->num_headers; ++i) {
+ apr_table_setn(headers, obj->tbl[i].hdr, obj->tbl[i].val);
+ }
*info = &(obj->info);
return OK;
@@ -399,9 +417,47 @@ static int read_body(cache_handle *h, apr_bucket_brigade *bb)
return OK;
}
-static int write_headers(cache_handle *h, request_rec *r, cache_info *info)
+static int write_headers(cache_handle *h, request_rec *r, cache_info *info, apr_table_t *headers)
{
cache_object_t *obj = (cache_object_t*) h->cache_obj;
+ apr_table_entry_t *elts = (apr_table_entry_t *) headers->a.elts;
+ apr_ssize_t i;
+ apr_size_t len = 0;
+ apr_size_t idx = 0;
+ char *buf;
+
+ /* Precompute how much storage we need to hold the headers */
+ obj->tbl = malloc(sizeof(cache_header_tbl_t) * headers->a.nelts);
+ if (NULL == obj->tbl) {
+ return DECLINED;
+ }
+ for (i = 0; i < headers->a.nelts; ++i) {
+ len += strlen(elts[i].key);
+ len += strlen(elts[i].val);
+ len += 2; /* Extra space for NULL string terminator for key and val */
+ }
+
+ /* Transfer the headers into a contiguous memory block */
+ buf = malloc(len);
+ if (!buf) {
+ free(obj->tbl);
+ obj->tbl = NULL;
+ return DECLINED;
+ }
+ obj->num_headers = headers->a.nelts;
+ for (i = 0; i < obj->num_headers; ++i) {
+ obj->tbl[i].hdr = &buf[idx];
+ len = strlen(elts[i].key) + 1; /* Include NULL terminator */
+ strncpy(&buf[idx], elts[i].key, len);
+ idx+=len;
+
+ obj->tbl[i].val = &buf[idx];
+ len = strlen(elts[i].val) + 1;
+ strncpy(&buf[idx], elts[i].val, len);
+ idx+=len;
+ }
+
+#if 0
if (info->date) {
obj->info.date = info->date;
}
@@ -416,7 +472,7 @@ static int write_headers(cache_handle *h, request_rec *r, cache_info *info)
if (obj->info.content_type)
strcpy((char*) obj->info.content_type, info->content_type);
}
-
+#endif
return OK;
}