[4.0] bfceeca Bring in the http_CountHdr function from master
Martin Blix Grydeland
martin at varnish-software.com
Mon Mar 16 16:11:00 CET 2015
commit bfceecad021075d6067b16107d93284b4674f2e2
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date: Mon Mar 16 14:22:39 2015 +0100
Bring in the http_CountHdr function from master
Use this when checking for duplicate Host headers
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 4a74db0..0fb6206 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -1024,6 +1024,7 @@ int http_IsHdr(const txt *hh, const char *hdr);
enum sess_close http_DoConnection(struct http *);
void http_CopyHome(struct http *hp);
void http_Unset(struct http *hp, const char *hdr);
+unsigned http_CountHdr(const struct http *hp, const char *hdr);
void http_CollectHdr(struct http *hp, const char *hdr);
void http_VSL_log(const struct http *hp);
void http_Merge(const struct http *fm, struct http *to, int not_ce);
diff --git a/bin/varnishd/cache/cache_http.c b/bin/varnishd/cache/cache_http.c
index 8fc3d16..572d987 100644
--- a/bin/varnishd/cache/cache_http.c
+++ b/bin/varnishd/cache/cache_http.c
@@ -264,6 +264,26 @@ http_findhdr(const struct http *hp, unsigned l, const char *hdr)
}
/*--------------------------------------------------------------------
+ * Count how many instances we have of this header
+ */
+
+unsigned
+http_CountHdr(const struct http *hp, const char *hdr)
+{
+ unsigned retval = 0;
+ unsigned u;
+
+ CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC);
+
+ for (u = HTTP_HDR_FIRST; u < hp->nhd; u++) {
+ Tcheck(hp->hd[u]);
+ if (http_IsHdr(&hp->hd[u], hdr))
+ retval++;
+ }
+ return (retval);
+}
+
+/*--------------------------------------------------------------------
* This function collapses multiple headerlines of the same name.
* The lines are joined with a comma, according to [rfc2616, 4.2bot, p32]
*/
diff --git a/bin/varnishd/cache/cache_http1_proto.c b/bin/varnishd/cache/cache_http1_proto.c
index ff58c69..2c4eab3 100644
--- a/bin/varnishd/cache/cache_http1_proto.c
+++ b/bin/varnishd/cache/cache_http1_proto.c
@@ -375,30 +375,6 @@ htc_splitline(struct http *hp, const struct http_conn *htc, const int *hf)
/*--------------------------------------------------------------------*/
-static uint16_t
-htc_request_check_host_hdr(const struct http *hp)
-{
- int u;
- int seen_host = 0;
- for (u = HTTP_HDR_FIRST; u < hp->nhd; u++) {
- if (hp->hd[u].b == NULL)
- continue;
- AN(hp->hd[u].b);
- AN(hp->hd[u].e);
- if (http_IsHdr(&hp->hd[u], H_Host)) {
- if (seen_host) {
- VSLb(hp->vsl, SLT_Error,
- "Duplicated Host header");
- return (400);
- }
- seen_host = 1;
- }
- }
- return (0);
-}
-
-/*--------------------------------------------------------------------*/
-
static void
htc_proto_ver(struct http *hp)
{
@@ -435,9 +411,9 @@ HTTP1_DissectRequest(struct req *req)
}
htc_proto_ver(hp);
- retval = htc_request_check_host_hdr(hp);
- if (retval != 0) {
- return (retval);
+ if (http_CountHdr(hp, H_Host) > 1) {
+ VSLb(hp->vsl, SLT_Error, "Duplicate Host header");
+ return (400);
}
/* RFC2616, section 5.2, point 1 */
More information about the varnish-commit
mailing list