From 6c75b7bf2481ab3f59ca20b3e9424cc31aac3ee6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Mon, 21 Sep 2009 13:15:57 +0000 Subject: [PATCH] - Combine Cache-Control header value in mod_expire to existing HTTP header if header already added by other modules (fixes #2068) git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2621 152afb58-edef-0310-8abb-c4023f1b3aa9 --- NEWS | 1 + src/http-header-glue.c | 15 +++++++++++++++ src/mod_expire.c | 2 +- src/response.h | 1 + 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index f8eec811..6f396ae8 100644 --- a/NEWS +++ b/NEWS @@ -36,6 +36,7 @@ NEWS * Set tm.tm_isdst = 0 before mktime() (fixes #2047) * Use linux-epoll by default if available (fixes #2021, thx Olaf van der Spek) * Print an error if you use too many captures in a regex pattern (fixes #2059) + * Combine Cache-Control header value in mod_expire to existing HTTP header if header already added by other modules (fixes #2068) - 1.4.23 - 2009-06-19 * Added some extra warning options in cmake and fix the resulting warnings (unused/static functions) diff --git a/src/http-header-glue.c b/src/http-header-glue.c index e8b7e11e..9b7d6b9a 100644 --- a/src/http-header-glue.c +++ b/src/http-header-glue.c @@ -104,6 +104,21 @@ int response_header_overwrite(server *srv, connection *con, const char *key, siz return response_header_insert(srv, con, key, keylen, value, vallen); } +int response_header_append(server *srv, connection *con, const char *key, size_t keylen, const char *value, size_t vallen) { + data_string *ds; + + UNUSED(srv); + + /* if there already is a key by this name append the value */ + if (NULL != (ds = (data_string *)array_get_element(con->response.headers, key))) { + buffer_append_string_len(ds->value, CONST_STR_LEN(", ")); + buffer_append_string_len(ds->value, value, vallen); + return 0; + } + + return response_header_insert(srv, con, key, keylen, value, vallen); +} + int http_response_redirect_to_directory(server *srv, connection *con) { buffer *o; diff --git a/src/mod_expire.c b/src/mod_expire.c index 2a66476f..32177060 100644 --- a/src/mod_expire.c +++ b/src/mod_expire.c @@ -342,7 +342,7 @@ URIHANDLER_FUNC(mod_expire_path_handler) { buffer_copy_string_len(p->expire_tstmp, CONST_STR_LEN("max-age=")); buffer_append_long(p->expire_tstmp, expires - srv->cur_ts); /* as expires >= srv->cur_ts the difference is >= 0 */ - response_header_insert(srv, con, CONST_STR_LEN("Cache-Control"), CONST_BUF_LEN(p->expire_tstmp)); + response_header_append(srv, con, CONST_STR_LEN("Cache-Control"), CONST_BUF_LEN(p->expire_tstmp)); return HANDLER_GO_ON; } diff --git a/src/response.h b/src/response.h index c9ff2344..a479e0f0 100644 --- a/src/response.h +++ b/src/response.h @@ -10,6 +10,7 @@ int http_response_write_header(server *srv, connection *con); int response_header_insert(server *srv, connection *con, const char *key, size_t keylen, const char *value, size_t vallen); int response_header_overwrite(server *srv, connection *con, const char *key, size_t keylen, const char *value, size_t vallen); +int response_header_append(server *srv, connection *con, const char *key, size_t keylen, const char *value, size_t vallen); handler_t http_response_prepare(server *srv, connection *con); int http_response_redirect_to_directory(server *srv, connection *con);