router

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

MethodNotAllowed is the handler which returns 405 for any request

NotFound is the handler which returns 404 for any request

Functions

This section is empty.

Types

type Router

type Router struct {
	// Default specifies handler to serve non-CONNECT proxy requests. If not set, NotFound will be used.
	Default http.Handler

	// Connect sets fallback CONNECT handler which will be used if no host matches. If no fallback handler specified,
	// MethodNotAllowed will be used as a fallback.
	Connect http.Handler

	// NotFound sets handler to serve non-proxy requests. If not set, http.NotFound will be used.
	NotFound http.Handler
	// contains filtered or unexported fields
}

Router is a router to dispatch proxy requests to proper handlers according to method and host rules.

Zero value of Router is a usable proxy server in the sense it will return valid HTTP responses. It will not forward any requests to upstream or target servers though.

func (*Router) HandleConnectHost

func (r *Router) HandleConnectHost(host string, handler http.Handler)

HandleConnectHost sets handler to serve CONNECT requests for target hosts.

Hostname specification:

  • `example.com` matches exactly the host name
  • `www.example.com` matches exactly the host name as well
  • `.example.com` matches both `example.com` and all of it's subdomains

Patterns will be matched exactly in the order they were added. The pattern that matches aborts matching cycle. E.g.

    r.HandleConnectHost(".example.com", A)
    r.HandleConnectHost("example.com", B)

would match handler A for the target host `example.com`

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(rw http.ResponseWriter, rq *http.Request)

Jump to

Keyboard shortcuts

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