whredir

package
v1.0.0-...-3f30213 Latest Latest
Warning

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

Go to latest
Published: May 30, 2017 License: Apache-2.0 Imports: 6 Imported by: 7

Documentation

Overview

Package whredir provides some helper methods and handlers for redirecting incoming requests to other URLs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FullURL

func FullURL(r *http.Request) (*url.URL, error)

FullURL returns the full url from the incoming request, regardless of what current whmux.Dir is involved or how req.URL.Path has been edited.

func Redirect

func Redirect(w http.ResponseWriter, r *http.Request, redirectTo string)

Redirect is just http.Redirect with http.StatusSeeOther which I always forget.

func RedirectHandler

func RedirectHandler(url string) http.Handler

RedirectHandler returns an http.Handler that redirects all requests to url.

func RequireHTTPS

func RequireHTTPS(handler http.Handler) http.Handler

RequireHTTPS returns a handler that will redirect to the same path but using https if https was not already used.

func RequireHost

func RequireHost(host string, handler http.Handler) http.Handler

RequireHost returns a handler that will redirect to the same path but using the given host if the given host was not specifically requested.

func RequireNextSlash

func RequireNextSlash(h http.Handler) http.Handler

func RequireTrailingSlash

func RequireTrailingSlash(h http.Handler) http.Handler

RequireTrailingSlash makes sure all handled paths have a trailing slash. This helps with relative URLs for other resources.

Types

type RedirectHandlerFunc

type RedirectHandlerFunc func(r *http.Request) string

RedirectHandlerFunc is an http.Handler that redirects all requests to the returned URL.

func (RedirectHandlerFunc) Routes

func (f RedirectHandlerFunc) Routes(
	cb func(method, path string, annotations map[string]string))

Routes implements whroute.Lister

func (RedirectHandlerFunc) ServeHTTP

func (f RedirectHandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.handler

Jump to

Keyboard shortcuts

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