[master] 2bbb032 Split absolute URIs into URL and Host: as per RFC2616 5.2
Poul-Henning Kamp
phk at varnish-cache.org
Wed Jan 30 11:14:49 CET 2013
commit 2bbb032bf67871d7d5a43a38104d58f747f2e860
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed Jan 30 10:05:54 2013 +0000
Split absolute URIs into URL and Host: as per RFC2616 5.2
Fixes #1255
diff --git a/bin/varnishd/cache/cache_http1_proto.c b/bin/varnishd/cache/cache_http1_proto.c
index 8caa135..e0c8b83 100644
--- a/bin/varnishd/cache/cache_http1_proto.c
+++ b/bin/varnishd/cache/cache_http1_proto.c
@@ -389,12 +389,15 @@ htc_proto_ver(struct http *hp)
/*--------------------------------------------------------------------*/
+#include <stdio.h>
+
uint16_t
HTTP1_DissectRequest(struct req *req)
{
struct http_conn *htc;
struct http *hp;
uint16_t retval;
+ char *b, *e;
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
htc = req->htc;
@@ -408,8 +411,22 @@ HTTP1_DissectRequest(struct req *req)
return (retval);
}
htc_proto_ver(hp);
+
+ /* RFC2616, section 5.2, point 1 */
+ if (!strncasecmp(hp->hd[HTTP_HDR_URL].b, "http://", 7)) {
+ b = e = hp->hd[HTTP_HDR_URL].b + 7;
+ while (*e != '/' && *e != '\0')
+ e++;
+ if (*e == '/') {
+ http_Unset(hp, H_Host);
+ http_PrintfHeader(hp, "Host: %.*s", (int)(e - b), b);
+ hp->hd[HTTP_HDR_URL].b = e;
+ }
+ }
+
return (retval);
}
+
/*--------------------------------------------------------------------*/
uint16_t
diff --git a/bin/varnishtest/tests/r01255.vtc b/bin/varnishtest/tests/r01255.vtc
new file mode 100644
index 0000000..cb53d71
--- /dev/null
+++ b/bin/varnishtest/tests/r01255.vtc
@@ -0,0 +1,19 @@
+varnishtest "Test RFC2616 5.2 compliance"
+
+server s1 {
+ rxreq
+ txresp -hdr "Foo: 1"
+} -start
+
+varnish v1 -vcl+backend {
+
+ sub vcl_deliver {
+ set resp.http.rxhost = req.http.host;
+ }
+} -start
+
+client c1 {
+ txreq -url http://www.example.com/bar
+ rxresp
+ expect resp.http.rxhost == www.example.com
+} -run
More information about the varnish-commit
mailing list