[master] e96478c Add https_scheme feature bit

Guillaume Quintard guillaume at varnish-software.com
Mon Feb 15 13:34:34 CET 2016


commit e96478c2aea2a5c6f2e3efaff94508c3f0d43d87
Author: Guillaume Quintard <guillaume at varnish-software.com>
Date:   Tue Jan 26 16:56:40 2016 +0100

    Add https_scheme feature bit
    
    Allow to split https URI in the request line

diff --git a/bin/varnishd/http1/cache_http1_proto.c b/bin/varnishd/http1/cache_http1_proto.c
index 0ae476e..49478da 100644
--- a/bin/varnishd/http1/cache_http1_proto.c
+++ b/bin/varnishd/http1/cache_http1_proto.c
@@ -344,7 +344,7 @@ HTTP1_DissectRequest(struct http_conn *htc, struct http *hp)
 {
 	uint16_t retval;
 	const char *p;
-	const char *b, *e;
+	const char *b = NULL, *e;
 
 	CHECK_OBJ_NOTNULL(htc, HTTP_CONN_MAGIC);
 	CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC);
@@ -363,8 +363,12 @@ HTTP1_DissectRequest(struct http_conn *htc, struct http *hp)
 		return (400);
 
 	/* RFC2616, section 5.2, point 1 */
-	if (!strncasecmp(hp->hd[HTTP_HDR_URL].b, "http://", 7)) {
+	if (!strncasecmp(hp->hd[HTTP_HDR_URL].b, "http://", 7))
 		b = e = hp->hd[HTTP_HDR_URL].b + 7;
+	else if (FEATURE(FEATURE_HTTPS_SCHEME) &&
+			!strncasecmp(hp->hd[HTTP_HDR_URL].b, "https://", 8))
+		b = e = hp->hd[HTTP_HDR_URL].b + 8;
+	if (b) {
 		while (*e != '/' && *e != '\0')
 			e++;
 		if (*e == '/') {
diff --git a/bin/varnishtest/tests/r01847.vtc b/bin/varnishtest/tests/r01847.vtc
new file mode 100644
index 0000000..a163fe3
--- /dev/null
+++ b/bin/varnishtest/tests/r01847.vtc
@@ -0,0 +1,45 @@
+varnishtest "Test https_scheme parameter"
+
+server s1 {
+	rxreq
+	expect req.url == /bar
+	txresp
+
+	rxreq
+	expect req.url == https://www.example.com/bar
+	txresp
+} -start
+
+varnish v1 -vcl+backend {
+
+	sub vcl_deliver {
+		set resp.http.rxhost = req.http.host;
+		set resp.http.rxurl = req.url;
+	}
+} -start
+
+client c1 {
+	txreq -url http://www.example.com/bar
+	rxresp
+	expect resp.http.rxhost == www.example.com
+	expect resp.http.rxurl == /bar
+
+	txreq -url https://www.example.com/bar
+	rxresp
+	expect resp.http.rxhost == ""
+	expect resp.http.rxurl == https://www.example.com/bar
+} -run
+
+varnish v1 -cliok "param.set feature +https_scheme"
+
+client c1 {
+	txreq -url http://www.example.com/bar
+	rxresp
+	expect resp.http.rxhost == www.example.com
+	expect resp.http.rxurl == /bar
+
+	txreq -url https://www.example.com/bar
+	rxresp
+	expect resp.http.rxhost == www.example.com
+	expect resp.http.rxurl == /bar
+} -run
diff --git a/include/tbl/feature_bits.h b/include/tbl/feature_bits.h
index 6fcf279..8d8870b 100644
--- a/include/tbl/feature_bits.h
+++ b/include/tbl/feature_bits.h
@@ -59,4 +59,9 @@ FEATURE_BIT(ESI_REMOVE_BOM,		esi_remove_bom,
     "Remove UTF-8 BOM from front of object."
     "Ignore and remove the UTF-8 BOM (0xeb 0xbb 0xbf) from front of object."
 )
+FEATURE_BIT(HTTPS_SCHEME,		https_scheme,
+	"Also split https URIs",
+	"Extract host from full URI in the request line if the scheme is "
+	"https."
+)
 /*lint -restore */



More information about the varnish-commit mailing list