[master] d9698da Streamline the H1->H2 handover a bit

Poul-Henning Kamp phk at FreeBSD.org
Wed Mar 8 21:35:06 CET 2017


commit d9698da29340c74c18e182c606e69d0c588df97a
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Mar 8 20:34:14 2017 +0000

    Streamline the H1->H2 handover a bit

diff --git a/bin/varnishd/cache/cache_transport.h b/bin/varnishd/cache/cache_transport.h
index 447c427..22c10b2 100644
--- a/bin/varnishd/cache/cache_transport.h
+++ b/bin/varnishd/cache/cache_transport.h
@@ -70,6 +70,8 @@ extern struct transport PROXY_transport;
 extern struct transport HTTP1_transport;
 extern struct transport H2_transport;
 htc_complete_f H2_prism_complete;
+void H2_PU_Sess(struct worker *, struct sess *, struct req *);
+void H2_OU_Sess(struct worker *, struct sess *, struct req *);
 
 const struct transport *XPORT_ByNumber(uint16_t no);
 void VPX_Send_Proxy(int fd, int version, const struct sess *);
diff --git a/bin/varnishd/http1/cache_http1_fsm.c b/bin/varnishd/http1/cache_http1_fsm.c
index d386840..5e8d42e 100644
--- a/bin/varnishd/http1/cache_http1_fsm.c
+++ b/bin/varnishd/http1/cache_http1_fsm.c
@@ -408,11 +408,8 @@ HTTP1_Session(struct worker *wrk, struct req *req)
 					http1_setstate(sp, H1CLEANUP);
 					continue;
 				}
-				VSLb(req->vsl, SLT_Debug,
-				    "H2 Prior Knowledge Upgrade");
 				http1_setstate(sp, NULL);
-				req->err_code = 1;
-				SES_SetTransport(wrk, sp, req, &H2_transport);
+				H2_PU_Sess(wrk, sp, req);
 				return;
 			}
 
@@ -433,12 +430,9 @@ HTTP1_Session(struct worker *wrk, struct req *req)
 					VSLb(req->vsl, SLT_Debug,
 					    "H2 upgrade attempt has body");
 				} else {
-					VSLb(req->vsl, SLT_Debug,
-					    "H2 Upgrade");
 					http1_setstate(sp, NULL);
 					req->err_code = 2;
-					SES_SetTransport(wrk, sp, req,
-					    &H2_transport);
+					H2_OU_Sess(wrk, sp, req);
 					return;
 				}
 			}
diff --git a/bin/varnishd/http2/cache_http2_session.c b/bin/varnishd/http2/cache_http2_session.c
index 522e252..050ce4a 100644
--- a/bin/varnishd/http2/cache_http2_session.c
+++ b/bin/varnishd/http2/cache_http2_session.c
@@ -288,6 +288,28 @@ h2_new_ou_session(struct worker *wrk, struct h2_sess *h2,
 	return (1);
 }
 
+/**********************************************************************
+ */
+
+#define H2_PU_MARKER	1
+#define H2_OU_MARKER	2
+
+void
+H2_PU_Sess(struct worker *wrk, struct sess *sp, struct req *req)
+{
+	VSLb(req->vsl, SLT_Debug, "H2 Prior Knowledge Upgrade");
+	req->err_code = H2_PU_MARKER;
+	SES_SetTransport(wrk, sp, req, &H2_transport);
+}
+
+void
+H2_OU_Sess(struct worker *wrk, struct sess *sp, struct req *req)
+{
+	VSLb(req->vsl, SLT_Debug, "H2 Optimistic Upgrade");
+	req->err_code = H2_OU_MARKER;
+	SES_SetTransport(wrk, sp, req, &H2_transport);
+}
+
 static void __match_proto__(task_func_t)
 h2_new_session(struct worker *wrk, void *arg)
 {
@@ -304,35 +326,17 @@ h2_new_session(struct worker *wrk, void *arg)
 
 	assert(req->transport == &H2_transport);
 
+	assert (req->err_code == H2_PU_MARKER || req->err_code == H2_OU_MARKER);
 
-	switch(req->err_code) {
-	case 0:
-		/* Direct H2 connection (via Proxy) */
-		h2 = h2_new_sess(wrk, sp, req);
-		wsp = WS_Snapshot(h2->ws);
-		(void)h2_new_req(wrk, h2, 0, NULL);
-		break;
-	case 1:
-		/* Prior Knowledge H1->H2 upgrade */
-		h2 = h2_new_sess(wrk, sp, req);
-		wsp = WS_Snapshot(h2->ws);
-		(void)h2_new_req(wrk, h2, 0, NULL);
-
-		if (!h2_new_pu_session(wrk, h2))
-			return;
-		break;
-	case 2:
-		/* Optimistic H1->H2 upgrade */
-		h2 = h2_new_sess(wrk, sp, NULL);
-		wsp = WS_Snapshot(h2->ws);
-		(void)h2_new_req(wrk, h2, 0, NULL);
-
-		if (!h2_new_ou_session(wrk, h2, req))
-			return;
-		break;
-	default:
-		WRONG("Bad req->err_code");
-	}
+	h2 = h2_new_sess(wrk, sp, req->err_code == H2_PU_MARKER ? req : NULL);
+	wsp = WS_Snapshot(h2->ws);
+	(void)h2_new_req(wrk, h2, 0, NULL);
+
+	if (req->err_code == H2_PU_MARKER && !h2_new_pu_session(wrk, h2))
+		return;
+
+	if (req->err_code == H2_OU_MARKER && !h2_new_ou_session(wrk, h2, req))
+		return;
 
 	THR_SetRequest(h2->srq);
 



More information about the varnish-commit mailing list