diff options
| author | Adnan Maolood <[email protected]> | 2020-10-21 17:47:34 -0400 |
|---|---|---|
| committer | Adnan Maolood <[email protected]> | 2020-10-21 17:47:34 -0400 |
| commit | 1634c2c11c76acb65e8df2e87e02f19537c9ef14 (patch) | |
| tree | a5c6a9920be28eb15de8d26715af6f6edfdee77c /server.go | |
| parent | examples/auth: Use sensitive input for passwords (diff) | |
| download | go-gemini-1634c2c11c76acb65e8df2e87e02f19537c9ef14.tar.xz go-gemini-1634c2c11c76acb65e8df2e87e02f19537c9ef14.zip | |
Add Certificate helper function
Diffstat (limited to 'server.go')
| -rw-r--r-- | server.go | 11 |
1 files changed, 5 insertions, 6 deletions
@@ -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. |