Documentation
¶
Overview ¶
Package xhttp provides HTTP-related utilities.
Index ¶
- Constants
- func DisableCaching(w http.ResponseWriter)
- func ErrorStatus(w http.ResponseWriter, statusCode int)
- type BasicAuth
- type Metadata
- type Server
- type StatusResponseWriter
- func (w *StatusResponseWriter) BytesWritten() int
- func (w *StatusResponseWriter) Flush()
- func (w *StatusResponseWriter) Header() http.Header
- func (w *StatusResponseWriter) Status() int
- func (w *StatusResponseWriter) Write(data []byte) (int, error)
- func (w *StatusResponseWriter) WriteHeader(status int)
Constants ¶
const ( ProtocolHTTP = "http" ProtocolHTTPS = "https" )
Constants for protocols the server can provide.
Variables ¶
This section is empty.
Functions ¶
func DisableCaching ¶ added in v1.104.0
func DisableCaching(w http.ResponseWriter)
DisableCaching disables caching for the given response writer. To be effective, should be called before any data is written.
func ErrorStatus ¶ added in v1.103.0
func ErrorStatus(w http.ResponseWriter, statusCode int)
ErrorStatus sends an HTTP response header with 'statusCode' and follows it with the standard text for that code as the body.
Types ¶
type BasicAuth ¶
type BasicAuth struct { Realm string // Lookup provides a way to map a user in a realm to a password. The returned password should have already been // passed through the Hasher function. Lookup func(user, realm string) ([]byte, bool) Hasher func(input string) []byte }
BasicAuth provides basic HTTP authentication.
type Metadata ¶ added in v1.103.0
Metadata holds auxiliary information for a request.
func MetadataFromRequest ¶ added in v1.103.0
MetadataFromRequest returns the Metadata from the request.
type Server ¶ added in v1.103.0
type Server struct { WebServer *http.Server Logger *slog.Logger CertFile string KeyFile string StartedChan chan any // If not nil, will be closed once the server is ready to accept connections ShutdownGracePeriod time.Duration ShutdownCallback func(*slog.Logger) // contains filtered or unexported fields }
Server holds the data necessary for the server.
func (*Server) Addresses ¶ added in v1.103.0
Addresses returns the host addresses being listened to.
func (*Server) LocalBaseURL ¶ added in v1.103.0
LocalBaseURL returns the local base URL that will reach the server.
func (*Server) Run ¶ added in v1.103.0
Run the server. Does not return until the server is shutdown.
func (*Server) ServeHTTP ¶ added in v1.103.0
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements the http.Handler interface.
type StatusResponseWriter ¶
type StatusResponseWriter struct { Original http.ResponseWriter Head bool // contains filtered or unexported fields }
StatusResponseWriter wraps an http.ResponseWriter and provides methods to retrieve the status code and number of bytes written.
func (*StatusResponseWriter) BytesWritten ¶
func (w *StatusResponseWriter) BytesWritten() int
BytesWritten returns the number of bytes written.
func (*StatusResponseWriter) Flush ¶
func (w *StatusResponseWriter) Flush()
Flush implements http.Flusher.
func (*StatusResponseWriter) Header ¶
func (w *StatusResponseWriter) Header() http.Header
Header implements http.ResponseWriter.
func (*StatusResponseWriter) Status ¶
func (w *StatusResponseWriter) Status() int
Status returns the status that was set, or http.StatusOK if no call to WriteHeader() was made.
func (*StatusResponseWriter) Write ¶
func (w *StatusResponseWriter) Write(data []byte) (int, error)
Write implements http.ResponseWriter.
func (*StatusResponseWriter) WriteHeader ¶
func (w *StatusResponseWriter) WriteHeader(status int)
WriteHeader implements http.ResponseWriter.