httputils

package module
v0.0.0-...-27fdf7d Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2019 License: BSD-3-Clause Imports: 10 Imported by: 5

README

httputils

GoDoc Build Status Go Report Card

A collection of small utility functions for Golang's net/http.

Documentation

Overview

Package httputils is a collection of small utility functions for net/http.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MIMETypeMatches

func MIMETypeMatches(mime string, types []string) bool

MIMETypeMatches returns whether a MIME type is found within a given list.

MIME types are compared in a case-insensitive manner.

A MIME type without any subtype will match any more precise MIME type, i.e. image/* will match image/png, image/svg, image/gif and any other image types.

Any directives that may be present in the MIME type will be skipped when comparing, i.e. text/html will match 'text/html; charset=utf-8'.

func Negotiate

func Negotiate(header http.Header, name string, offers ...string) (match string)

Negotiate performs HTTP content negotiation via the Accept, Accept-Charset, Accept-Encoding, and Accept-Language HTTP headers.

The highest ranking match is returned, or an empty string if none found.

It does not resolve wildcard MIME subtypes when used with the Accept header. If this is important to you, include the relevant wildcards in offers.

It does not resolve language subtypes, such as en-US to en. If this is important to you, include the relevant subtype in offers.

It also does not handle the rejected identity (identity;q=0 or *;q=0 or */*;q=0), instead returning an empty string.

func Newest

func Newest(t ...time.Time) time.Time

Newest takes multiple time.Time and returns the newest time.

It is useful for selecting the newest modification time for templated resources.

func NewestModTime

func NewestModTime(info ...os.FileInfo) time.Time

NewestModTime takes multiple os.FileInfo and returns the newest ModTime.

Any of info may be nil.

It is useful for selecting the newest modification time for templated resources.

func RequestLogf

func RequestLogf(r *http.Request, format string, v ...interface{})

RequestLogf prints a message to the logger attached to the *http.Server that served the request. If nil, logging goes to os.Stderr via the log package's standard logger.

Arguments are handled in the manner of fmt.Printf.

func Shutdown

func Shutdown(ctx context.Context, srvs ...*http.Server) error

Shutdown gracefully shutsdown several http.Server's.

func TCPKeepAliveListener

func TCPKeepAliveListener(ln *net.TCPListener, period time.Duration) net.Listener

TCPKeepAliveListener sets TCP keep-alive timeouts on accepted connections.

If period is zero, it defaults to three minutes.

It is an unexported net/http type that is used by net/http.ListenAndServe and net/http.ListenAndServeTLS so dead TCP connections (e.g. closing laptop mid-download) eventually go away.

Types

This section is empty.

Jump to

Keyboard shortcuts

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