httpdown

package
v0.0.0-...-5c6c1e7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 29, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package httpdown provides http.ConnState enabled graceful termination of http.Server. based on github.com/facebookarchive/httpdown, who's licence is MIT-licence, we add a feature of supporting for http TLS

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListenAndServe

func ListenAndServe(s *http.Server, hd *HTTP) error

ListenAndServe is a convenience function to serve and wait for a SIGTERM or SIGINT before shutting down.

Types

type HTTP

type HTTP struct {
	// StopTimeout is the duration before we begin force closing connections.
	// Defaults to 1 minute.
	StopTimeout time.Duration

	// KillTimeout is the duration before which we completely give up and abort
	// even though we still have connected clients. This is useful when a large
	// number of client connections exist and closing them can take a long time.
	// Note, this is in addition to the StopTimeout. Defaults to 1 minute.
	KillTimeout time.Duration

	// Stats is optional. If provided, it will be used to record various metrics.
	Stats stats.Client

	// Clock allows for testing timing related functionality. Do not specify this
	// in production code.
	Clock clock.Clock

	// when set CertFile and KeyFile, the httpDown will start a http with TLS.
	// 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.
	CertFile, KeyFile string
}

HTTP defines the configuration for serving a http.Server. Multiple calls to Serve or ListenAndServe can be made on the same HTTP instance. The default timeouts of 1 minute each result in a maximum of 2 minutes before a Stop() returns.

func (HTTP) ListenAndServe

func (h HTTP) ListenAndServe(s *http.Server) (Server, error)

ListenAndServe returns a Server for the given http.Server. It is equivalent to ListenAndServe from the standard library, but returns immediately. Requests will be accepted in a background goroutine. If the http.Server has a non-nil TLSConfig, a TLS enabled listener will be setup.

func (HTTP) Serve

func (h HTTP) Serve(s *http.Server, l net.Listener) Server

Serve provides the low-level API which is useful if you're creating your own net.Listener.

type Server

type Server interface {
	// Wait waits for the serving loop to finish. This will happen when Stop is
	// called, at which point it returns no error, or if there is an error in the
	// serving loop. You must call Wait after calling Serve or ListenAndServe.
	Wait() error

	// Stop stops the listener. It will block until all connections have been
	// closed.
	Stop() error
}

A Server allows encapsulates the process of accepting new connections and serving them, and gracefully shutting down the listener without dropping active connections.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL