httputil

package
v0.0.0-...-e463486 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2024 License: MIT Imports: 19 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(uri string) ([]byte, error)

func GetBestRemoteAddress

func GetBestRemoteAddress(r *http.Request) string

GetRequestIPAddress returns IP address of the request even for proxied requests

func GetRequestInfo

func GetRequestInfo(r *http.Request, m map[string]interface{}, key string)

func GetToFile

func GetToFile(uri string, f *os.File) error

func JoinURL

func JoinURL(s1, s2 string) string

func MakeFullRedirectURL

func MakeFullRedirectURL(path string, reqURL *url.URL) string

func NewDefaultTimeoutClient

func NewDefaultTimeoutClient() *http.Client

func NewTimeoutClient

func NewTimeoutClient(connectTimeout time.Duration, readWriteTimeout time.Duration) *http.Client

can be used for http.Get() requests with better timeouts. New one must be created for each Get() request

func Post

func Post(uri string, body []byte) ([]byte, error)

func PostMultiPart

func PostMultiPart(uri string, files map[string]string) ([]byte, error)

func SimpleServer

func SimpleServer(opts SimpleServerOptions) error

run HTTP server serving a given directory

func SmartPermanentRedirect

func SmartPermanentRedirect(w http.ResponseWriter, r *http.Request, uri string)

func SmartRedirect

func SmartRedirect(w http.ResponseWriter, r *http.Request, uri string, code int)

SmartRedirect redirects to uri but also adds query / fragment from r.URL

func TryServeFileFromFS

func TryServeFileFromFS(w http.ResponseWriter, r *http.Request, opts *ServeFileOptions, fsPath string) bool

func TryServeURLFromFS

func TryServeURLFromFS(w http.ResponseWriter, r *http.Request, opts *ServeFileOptions) bool

Types

type ServeFileOptions

type ServeFileOptions struct {
	FS               fs.FS
	DirPrefix        string // e.g. dist/
	SupportCleanURLS bool
	ForceCleanURLS   bool
	ServeCompressed  bool
	// list of url prefixes that should be served as long-lived (e.g. /static/, /assets/)
	LongLivedURLPrefixes []string
	// contains filtered or unexported fields
}

type SimpleServerOptions

type SimpleServerOptions struct {
	Dir         string
	HTTPAddress string // e.g. ":8080" or
}

Jump to

Keyboard shortcuts

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