Documentation
¶
Overview ¶
HTTPS Listener For HTTP Redirect
🌐 HTTP redirect to HTTPS on the same port using Golang. It can also redirect from port 80 to port 443.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ListenAndServeTLS ¶
ListenAndServeTLS acts identically to http.ListenAndServe, except that it expects HTTPS connections. Additionally, files containing a certificate and matching private key for the server must be provided. If the certificate is signed by a certificate authority, the certFile should be the concatenation of the server's certificate, any intermediates, and the CA's certificate.
If Listen80RedirectTo443 failed, the returned error is starts with "hlfhr: Listen80RedirectTo443 error: ".
func ServeTLS ¶
ServeTLS accepts incoming HTTPS connections on the listener l, creating a new service goroutine for each. The service goroutines read requests and then call handler to reply to them.
The handler is typically nil, in which case http.DefaultServeMux is used.
Additionally, files containing a certificate and matching private key for the server must be provided. If the certificate is signed by a certificate authority, the certFile should be the concatenation of the server's certificate, any intermediates, and the CA's certificate.
If Listen80RedirectTo443 failed, the returned error is starts with "hlfhr: Listen80RedirectTo443 error: ".
Types ¶
type Conn ¶ added in v0.2.0
type Conn struct {
net.Conn
TLSConn *tls.Conn // If nil, it's reading TLS or serving port 80
Server *Server
}
func (*Conn) HlfhrServe ¶ added in v1.4.1
type Server ¶
type Server struct {
*http.Server
// Handles HTTP requests sent to an HTTPS server.
//
// If you need [http.Hijacker] or [http.ResponseController.EnableFullDuplex],
// please use https://github.com/bddjr/hahosp.
HlfhrHandler http.Handler
// Port 80 redirects to port 443.
//
// This option only takes effect when listening on port 443.
//
// [Server.HlfhrHandler] is also using on port 80.
Listen80RedirectTo443 bool
}
func (*Server) ListenAndServeTLS ¶
ListenAndServeTLS listens on the TCP network address srv.Addr and then calls ServeTLS to handle requests on incoming TLS connections. Accepted connections are configured to enable TCP keep-alives.
Filenames containing a certificate and matching private key for the server must be provided if neither the Server's TLSConfig.Certificates nor TLSConfig.GetCertificate are populated. If the certificate is signed by a certificate authority, the certFile should be the concatenation of the server's certificate, any intermediates, and the CA's certificate.
If srv.Addr is blank, ":https" is used.
If Listen80RedirectTo443 failed, the returned error is starts with "hlfhr: Listen80RedirectTo443 error: ".
After [Server.Shutdown] or [Server.Close], the returned error is http.ErrServerClosed.
func (*Server) ServeTLS ¶
ServeTLS accepts incoming connections on the Listener l, creating a new service goroutine for each. The service goroutines perform TLS setup and then read requests, calling srv.Handler to reply to them.
Files containing a certificate and matching private key for the server must be provided if neither the Server's TLSConfig.Certificates nor TLSConfig.GetCertificate are populated. If the certificate is signed by a certificate authority, the certFile should be the concatenation of the server's certificate, any intermediates, and the CA's certificate.
If Listen80RedirectTo443 failed, the returned error is starts with "hlfhr: Listen80RedirectTo443 error: ".
After [Server.Shutdown] or [Server.Close], the returned error is http.ErrServerClosed.