BUG/MINOR: cache: also cache absolute URIs

The recent changes to address URI issues mixed with the recent fix to
stop caching absolute URIs have caused the cache not to cache H2 requests
anymore since these ones come with a scheme and authority. Let's unbreak
this by using absolute URIs all the time, now that we keep host and
authority in sync. So what is done now is that if we have an authority,
we take the whole URI as it is as the cache key. This covers H2 and H1
absolute requests. If no authority is present (most H1 origin requests),
then we prepend "https://" and the Host header. The reason for https://
is that most of the time we don't care about the scheme, but since about
all H2 clients use this scheme, at least we can share the cache between
H1 and H2.

No backport is needed since the breakage only affects 2.1-dev.
diff --git a/src/cache.c b/src/cache.c
index d350872..1fd8dc6 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -1061,7 +1061,7 @@
 	struct htx *htx = htxbuf(&s->req.buf);
 	struct htx_sl *sl;
 	struct http_hdr_ctx ctx;
-	struct ist path;
+	struct ist uri;
 	blk_SHA_CTX sha1_ctx;
 	struct buffer *trash;
 
@@ -1077,15 +1077,31 @@
 		return 0;
 	}
 
-	if (!http_find_header(htx, ist("Host"), &ctx, 0))
-		return 0;
-	chunk_memcat(trash, ctx.value.ptr, ctx.value.len);
-
 	sl = http_get_stline(htx);
-	path = htx_sl_req_uri(sl); // whole uri
-	if (!path.len || *path.ptr != '/')
+	uri = htx_sl_req_uri(sl); // whole uri
+	if (!uri.len)
 		return 0;
-	chunk_memcat(trash, path.ptr, path.len);
+
+	/* In HTTP/1, most URIs are seen in origin form ('/path/to/resource'),
+	 * unless haproxy is deployed in front of an outbound cache. In HTTP/2,
+	 * URIs are almost always sent in absolute form with their scheme. In
+	 * this case, the scheme is almost always "https". In order to support
+	 * sharing of cache objects between H1 and H2, we'll hash the absolute
+	 * URI whenever known, or prepend "https://" + the Host header for
+	 * relative URIs. The difference will only appear on absolute HTTP/1
+	 * requests sent to an origin server, which practically is never met in
+	 * the real world so we don't care about the ability to share the same
+	 * key here.URIs are normalized from the absolute URI to an origin form as
+	 * well.
+	 */
+	if (!(sl->flags & HTX_SL_F_HAS_AUTHORITY)) {
+		chunk_cat(trash, b_fromist(ist("https://")));
+		if (!http_find_header(htx, ist("Host"), &ctx, 0))
+			return 0;
+		chunk_cat(trash, b_fromist(ctx.value));
+	}
+
+	chunk_memcat(trash, uri.ptr, uri.len);
 
 	/* hash everything */
 	blk_SHA1_Init(&sha1_ctx);