aboutsummaryrefslogtreecommitdiff
path: root/server.go
diff options
context:
space:
mode:
authorAdnan Maolood <[email protected]>2020-10-21 17:47:34 -0400
committerAdnan Maolood <[email protected]>2020-10-21 17:47:34 -0400
commit1634c2c11c76acb65e8df2e87e02f19537c9ef14 (patch)
treea5c6a9920be28eb15de8d26715af6f6edfdee77c /server.go
parentexamples/auth: Use sensitive input for passwords (diff)
downloadgo-gemini-1634c2c11c76acb65e8df2e87e02f19537c9ef14.tar.xz
go-gemini-1634c2c11c76acb65e8df2e87e02f19537c9ef14.zip
Add Certificate helper function
Diffstat (limited to 'server.go')
-rw-r--r--server.go11
1 files changed, 5 insertions, 6 deletions
diff --git a/server.go b/server.go
index 4fde605..d33a234 100644
--- a/server.go
+++ b/server.go
@@ -311,15 +311,14 @@ func CertificateNotAuthorized(w *ResponseWriter, r *Request) {
w.WriteHeader(StatusCertificateNotAuthorized, "Certificate not authorized")
}
-// WithCertificate either responds with CertificateRequired if the client did
-// not provide a certificate, or calls f with the first ceritificate provided.
-func WithCertificate(w *ResponseWriter, r *Request, f func(*x509.Certificate)) {
+// Certificate returns the request certificate. If one is not provided,
+// it returns nil and responds with StatusCertificateRequired.
+func Certificate(w *ResponseWriter, r *Request) (*x509.Certificate, bool) {
if len(r.TLS.PeerCertificates) == 0 {
CertificateRequired(w, r)
- return
+ return nil, false
}
- cert := r.TLS.PeerCertificates[0]
- f(cert)
+ return r.TLS.PeerCertificates[0], true
}
// ResponderFunc is a wrapper around a bare function that implements Handler.