From 937fdfb4ed8e55795902e8567e8624da06ea4f8a Mon Sep 17 00:00:00 2001
From: Lars-Dominik Braun <lars@6xq.net>
Date: Wed, 9 Nov 2011 21:10:12 +0100
Subject: waitress: Poor man's proxy support for TLS

---
 src/libwaitress/waitress.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/src/libwaitress/waitress.c b/src/libwaitress/waitress.c
index 1a6d4cd..d4081ef 100644
--- a/src/libwaitress/waitress.c
+++ b/src/libwaitress/waitress.c
@@ -815,6 +815,21 @@ static WaitressReturn_t WaitressConnect (WaitressHandle_t *waith) {
 
 #ifdef ENABLE_TLS
 	if (waith->url.tls) {
+		/* set up proxy tunnel */
+		if (WaitressProxyEnabled (waith)) {
+			char buf[256];
+			size_t size;
+			snprintf (buf, sizeof (buf), "CONNECT %s:%s HTTP/1.1\r\n\r\n",
+						waith->url.host, WaitressDefaultPort (&waith->url));
+			WaitressOrdinaryWrite (waith, buf, strlen (buf));
+
+			WaitressOrdinaryRead (waith, buf, sizeof (buf)-1, &size);
+			buf[size] = 0;
+			if (WaitressParseStatusline (buf) != 200) {
+				return WAITRESS_RET_CONNECT_REFUSED;
+			}
+		}
+
 		if (gnutls_handshake (waith->request.tlsSession) != GNUTLS_E_SUCCESS) {
 			return WAITRESS_RET_TLS_HANDSHAKE_ERR;
 		}
-- 
cgit v1.2.3