go-gemini: Set req.Host to SNI hostname when available v1 REJECTED

Kaleb Elwert: 1
 Set req.Host to SNI hostname when available

 2 files changed, 7 insertions(+), 1 deletions(-)
#438656 .build.yml success
I've added the ServerName helper method to Request to make it easier to
access the TLS server name.

Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~adnano/go-gemini-devel/patches/20522/mbox | git am -3
Learn more about email & git

[PATCH go-gemini] Set req.Host to SNI hostname when available Export this patch

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")
go-gemini/patches/.build.yml: SUCCESS in 47s

[Set req.Host to SNI hostname when available][0] from [Kaleb Elwert][1]

[0]: https://lists.sr.ht/~adnano/go-gemini-devel/patches/20522
[1]: mailto:belak@coded.io

✓ #438656 SUCCESS go-gemini/patches/.build.yml https://builds.sr.ht/~adnano/job/438656