diff options
| author | Adnan Maolood <[email protected]> | 2020-12-18 01:02:04 -0500 |
|---|---|---|
| committer | Adnan Maolood <[email protected]> | 2020-12-18 01:02:04 -0500 |
| commit | c329a2487e4fde2a0a2401708afc23dfbafcce38 (patch) | |
| tree | cb79d92760625ad87766df9611f727db4ae1aa25 | |
| parent | examples: Add missing descriptions (diff) | |
| download | go-gemini-c329a2487e4fde2a0a2401708afc23dfbafcce38.tar.xz go-gemini-c329a2487e4fde2a0a2401708afc23dfbafcce38.zip | |
server: Don't always assume TLS is used
| -rw-r--r-- | server.go | 17 |
1 files changed, 10 insertions, 7 deletions
@@ -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, + } } } |