aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdnan Maolood <[email protected]>2020-12-18 01:02:04 -0500
committerAdnan Maolood <[email protected]>2020-12-18 01:02:04 -0500
commitc329a2487e4fde2a0a2401708afc23dfbafcce38 (patch)
treecb79d92760625ad87766df9611f727db4ae1aa25
parentexamples: Add missing descriptions (diff)
downloadgo-gemini-c329a2487e4fde2a0a2401708afc23dfbafcce38.tar.xz
go-gemini-c329a2487e4fde2a0a2401708afc23dfbafcce38.zip
server: Don't always assume TLS is used
-rw-r--r--server.go17
1 files changed, 10 insertions, 7 deletions
diff --git a/server.go b/server.go
index 9058aea..93b3d13 100644
--- a/server.go
+++ b/server.go
@@ -204,14 +204,17 @@ func (s *Server) respond(conn net.Conn) {
w.WriteStatus(StatusBadRequest)
} else {
// Store information about the TLS connection
- connState := conn.(*tls.Conn).ConnectionState()
+ var connState tls.ConnectionState
var cert *tls.Certificate
- if len(connState.PeerCertificates) > 0 {
- peerCert := connState.PeerCertificates[0]
- // Store the TLS certificate
- cert = &tls.Certificate{
- Certificate: [][]byte{peerCert.Raw},
- Leaf: peerCert,
+ if tlsConn, ok := conn.(*tls.Conn); ok {
+ connState = tlsConn.ConnectionState()
+ if len(connState.PeerCertificates) > 0 {
+ peerCert := connState.PeerCertificates[0]
+ // Store the TLS certificate
+ cert = &tls.Certificate{
+ Certificate: [][]byte{peerCert.Raw},
+ Leaf: peerCert,
+ }
}
}