aboutsummaryrefslogtreecommitdiffstats
path: root/buckets/headers_buckets.c
diff options
context:
space:
mode:
Diffstat (limited to 'buckets/headers_buckets.c')
-rw-r--r--buckets/headers_buckets.c37
1 files changed, 31 insertions, 6 deletions
diff --git a/buckets/headers_buckets.c b/buckets/headers_buckets.c
index 6401f7fc1df2..04e64d19b63b 100644
--- a/buckets/headers_buckets.c
+++ b/buckets/headers_buckets.c
@@ -20,6 +20,8 @@
#include "serf.h"
#include "serf_bucket_util.h"
+#include "serf_private.h" /* for serf__bucket_headers_remove */
+
typedef struct header_list {
const char *header;
@@ -37,6 +39,7 @@ typedef struct header_list {
typedef struct {
header_list_t *list;
+ header_list_t *last;
header_list_t *cur_read;
enum {
@@ -60,6 +63,7 @@ serf_bucket_t *serf_bucket_headers_create(
ctx = serf_bucket_mem_alloc(allocator, sizeof(*ctx));
ctx->list = NULL;
+ ctx->last = NULL;
ctx->state = READ_START;
return serf_bucket_create(&serf_bucket_type_headers, allocator, ctx);
@@ -71,7 +75,6 @@ void serf_bucket_headers_setx(
const char *value, apr_size_t value_size, int value_copy)
{
headers_context_t *ctx = bkt->data;
- header_list_t *iter = ctx->list;
header_list_t *hdr;
#if 0
@@ -105,13 +108,12 @@ void serf_bucket_headers_setx(
}
/* Add the new header at the end of the list. */
- while (iter && iter->next) {
- iter = iter->next;
- }
- if (iter)
- iter->next = hdr;
+ if (ctx->last)
+ ctx->last->next = hdr;
else
ctx->list = hdr;
+
+ ctx->last = hdr;
}
void serf_bucket_headers_set(
@@ -191,6 +193,29 @@ const char *serf_bucket_headers_get(
return val;
}
+void serf__bucket_headers_remove(serf_bucket_t *bucket, const char *header)
+{
+ headers_context_t *ctx = bucket->data;
+ header_list_t *scan = ctx->list, *prev = NULL;
+
+ /* Find and delete all items with the same header (case insensitive) */
+ while (scan) {
+ if (strcasecmp(scan->header, header) == 0) {
+ if (prev) {
+ prev->next = scan->next;
+ } else {
+ ctx->list = scan->next;
+ }
+ if (ctx->last == scan) {
+ ctx->last = NULL;
+ }
+ } else {
+ prev = scan;
+ }
+ scan = scan->next;
+ }
+}
+
void serf_bucket_headers_do(
serf_bucket_t *headers_bucket,
serf_bucket_headers_do_callback_fn_t func,