Authentication-Results: mail-b.sr.ht; dkim=pass header.d=coded.io header.i=@coded.io; dkim=pass header.d=messagingengine.com header.i=@messagingengine.com Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by mail-b.sr.ht (Postfix) with ESMTPS id E7E6911F013 for <~adnano/go-gemini-devel@lists.sr.ht>; Thu, 25 Feb 2021 01:05:12 +0000 (UTC) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id BD31F5C00E7; Wed, 24 Feb 2021 20:05:12 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Wed, 24 Feb 2021 20:05:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=coded.io; h=from :to:cc:subject:date:message-id:mime-version :content-transfer-encoding; s=fm3; bh=yNJsE3wcQ3nkKw8J3B+UBfRBlt rBD+10zP8DPYo92KY=; b=a+U34lzq2Q6J5A9ljoP35SV/JlcoXFRvZeiTPoly6z aAzzuKEcmK8VpMOc7Hm3kZyqQCu+8yhIl3eU+RrhC97n0r0mByhTulkepV4POBMi uO7ClJmKWHKP1Wb0gw/TBlbHxHxs3xDXygbFMNKclwc/YzgOjBBy5iLN6FkbrzKs qt48NdolgtwyDXRYUQdT3S1Q3IJ+BIkyqJbpu2l9PjpYjWhX6UQU5VaxG1U7OSex EWsfWD/PU+7NfJC9J/zhNvfS1h9nFmziKn1UPFj2ket8KkJmUhA6LB2/ErSvu9vo A5k0LW+UkbF9zXFlItZrk4GKsFK2TEM3IoMSXhVCZZCw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :message-id:mime-version:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=yNJsE3wcQ3nkKw8J3 B+UBfRBltrBD+10zP8DPYo92KY=; b=SPwzb23Yq0bet2nIYNdt4pccqAxBgXzqV CT4nzqo7m9q6SvQ4mcG4Dp0QmzdTh/eTV6whM+wZmUzMiS6+HIyJu92RoD8WGatr f4BeFjtL/AhYl0S4PrLJCVfn02NJ+Erh9mx0MBxGTXkhkI7NPDMH0mVqER/ZxblV FGo336qkWpFIi+P5MSOkxnt2mir5fhO75xD6H+JeZU2TyggWWzQtd4P+OR64gGkM wqBi8eBuUg5S8U7lOKa+qPTVrKQ4Rl+67ok11cHYlebPY9PzDh1MMy260/DKCvAX erUWWDKBUzm/0kObUObUDHor54IFH7oQ23X9H+UGVZGpjmI5RnPKg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrkeekgdeftdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkffoggfgsedtkeertdertd dtnecuhfhrohhmpefmrghlvggsucfglhifvghrthcuoegsvghlrghksegtohguvggurdhi oheqnecuggftrfgrthhtvghrnheptdetgeffhedvhefhtdfhvdehleejkedukeetveelte fhkeekvefggeffuefhudfgnecuffhomhgrihhnpehgohhlrghnghdrohhrghenucfkphep hedtrdefhedrieehrdelheenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpegsvghlrghksegtohguvggurdhioh X-ME-Proxy: Received: from zagreus.lan (unknown [50.35.65.95]) by mail.messagingengine.com (Postfix) with ESMTPA id EED4A24005E; Wed, 24 Feb 2021 20:05:11 -0500 (EST) From: Kaleb Elwert To: ~adnano/go-gemini-devel@lists.sr.ht Cc: Kaleb Elwert Subject: [PATCH go-gemini] Set req.Host to SNI hostname when available Date: Wed, 24 Feb 2021 17:05:07 -0800 Message-Id: <20210225010507.203071-1-belak@coded.io> X-Mailer: git-send-email 2.30.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit --- Setting Request.Host will allow Handlers to properly handle different virtual hosts in the same process. I actually wanted to clean up server.go a bit, but I'll leave that for another patch. I think it's cleaner to use a plain net.Listener and create a tls.Conn farther down the line, because that makes it easier to pass the tls.Conn through the call chain. Unfortunately, there's an exposed method, ServeConn, which would mean breaking backwards compatibility to do this so I left it alone for now. request.go | 4 +++- server.go | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/request.go b/request.go index f15d891..00bf265 100644 --- a/request.go +++ b/request.go @@ -20,7 +20,9 @@ type Request struct { // For international domain names, Host may be in Punycode or // Unicode form. Use golang.org/x/net/idna to convert it to // either format if needed. - // This field is ignored by the Gemini server. + // + // The Gemini server in this package sets Host to the SNI hostname + // before invoking a handler. Host string // For client requests, Certificate optionally specifies the diff --git a/server.go b/server.go index a8ff77b..2576ee6 100644 --- a/server.go +++ b/server.go @@ -373,6 +373,10 @@ func (srv *Server) goServeConn(ctx context.Context, conn net.Conn) error { } req.conn = conn + if tlsConn, ok := conn.(*tls.Conn); ok { + req.Host = tlsConn.ConnectionState().ServerName + } + h := srv.Handler if h == nil { w.WriteHeader(StatusNotFound, "Not found") -- 2.30.1