Documentation
¶
Overview ¶
HTTPS Listener For HTTP Redirect
Index ¶
- Variables
- func BufioSetReader(br *bufio.Reader, rd io.Reader)
- func ConnFirstByteLooksLikeHttp(firstByte byte) bool
- func Hostname(Host string) (hostname string)
- func HostnameAppendPort(hostname string, port string) string
- func Ipv6CutPrefixSuffix(v6 string) string
- func IsHttpServerShuttingDown(srv *http.Server) bool
- func ListenAndServeTLS(addr, certFile, keyFile string, handler http.Handler) error
- func NewBufioReaderWithBytes(buf []byte, contentLength int, rd io.Reader) *bufio.Reader
- func Port(Host string) (port string)
- func Redirect(w http.ResponseWriter, code int, url string)
- func RedirectToHttps(w http.ResponseWriter, r *http.Request, code int)
- func ReplaceHostname(Host string, name string) string
- func ReplacePort(Host string, port string) string
- func ServeTLS(l net.Listener, handler http.Handler, certFile, keyFile string) error
- func SplitHostnamePort(Host string) (hostname string, port string)
- type Response
- func (r *Response) Flush()
- func (r *Response) FlushError() error
- func (r *Response) Header() http.Header
- func (r *Response) SetDeadline(t time.Time) error
- func (r *Response) SetReadDeadline(t time.Time) error
- func (r *Response) SetWriteDeadline(t time.Time) error
- func (r *Response) Write(b []byte) (int, error)
- func (r *Response) WriteByte(c byte) error
- func (r *Response) WriteHeader(statusCode int)
- func (r *Response) WriteString(s string) (int, error)
- type Server
- type TLSListener
Constants ¶
This section is empty.
Variables ¶
var ErrHttpOnHttpsPort = errors.New("client sent an HTTP request to an HTTPS server")
Functions ¶
func ConnFirstByteLooksLikeHttp ¶ added in v1.1.0
Reference:
func HostnameAppendPort ¶ added in v0.2.0
"[::1]", "5678" => "[::1]:5678"
"[::1]", ":5678" => "[::1]:5678"
"[::1]", "" => "[::1]"
"[::1]", ":" => "[::1]"
"::1" , "5678" => "[::1]:5678"
"::1" , ":5678" => "[::1]:5678"
"::1" , "" => "[::1]"
"::1" , ":" => "[::1]"
func Ipv6CutPrefixSuffix ¶ added in v0.2.0
"[::1]" => "::1"
func IsHttpServerShuttingDown ¶ added in v1.1.0
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.
func NewBufioReaderWithBytes ¶ added in v1.1.0
func Redirect ¶ added in v0.2.0
func Redirect(w http.ResponseWriter, code int, url string)
Redirect without HTTP body.
func RedirectToHttps ¶ added in v0.2.0
func RedirectToHttps(w http.ResponseWriter, r *http.Request, code int)
Redirect without HTTP body.
func ReplaceHostname ¶ added in v0.2.0
"[::1]:5678", "localhost" => "localhost:5678"
func ReplacePort ¶ added in v0.2.0
"[::1]:5678", "7890" => "localhost:7890"
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.
ServeTLS always returns a non-nil error.
func SplitHostnamePort ¶ added in v0.2.0
"[::1]:5678" => "[::1]", "5678"
Types ¶
type Response ¶ added in v0.1.0
type Response struct {
// contains filtered or unexported fields
}
Using for interface http.ResponseWriter, io.StringWriter, io.ByteWriter.
func NewResponse ¶ added in v0.1.0
func (*Response) Flush ¶ added in v1.2.3
func (r *Response) Flush()
Flush flushes buffered data to the client.
func (*Response) FlushError ¶ added in v1.3.4
func (*Response) SetReadDeadline ¶ added in v1.3.4
func (*Response) SetWriteDeadline ¶ added in v1.3.4
func (*Response) WriteHeader ¶ added in v1.2.3
Set status code and lock header, if header does not locked.
type Server ¶
type Server struct { *http.Server // HttpOnHttpsPortErrorHandler handles HTTP requests sent to an HTTPS port. // See https://github.com/bddjr/hlfhr#httponhttpsporterrorhandler-example HttpOnHttpsPortErrorHandler http.Handler }
func (*Server) IsShuttingDown ¶ added in v0.2.0
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.
ListenAndServeTLS always returns a non-nil 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.
ServeTLS always returns a non-nil error. After [Server.Shutdown] or [Server.Close], the returned error is http.ErrServerClosed.