cleanpath

package
v0.0.0-...-363c1d9 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2016 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package cleanpath implements a middleware that cleans the requested path to a canonical form. It redirects to the clean path if the requested path is not the canonical one. Some request multiplexers already do this automatically to some extent (e.g. http.ServeMux cleans the . and .. parts of the path, others handle the trailing slash), but this middleware handles this uniformly regardless of the mux used.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CleanPath

type CleanPath struct {
	// TrailingSlash specifies how the trailing slash of the path should
	// be handled. Defaults to Leave, which keeps it as it was received.
	// The mode does not apply to the root slash, which is always present
	// if the path is otherwise empty.
	TrailingSlash TrailingSlashMode
}

CleanPath holds the configuration for the middleware.

func (*CleanPath) Wrap

func (cp *CleanPath) Wrap(h http.Handler) http.Handler

Wrap returns a handler that redirects with a status code 301 to the canonical path if the requested path is not as expected. It cleans the . and .. parts and handles the trailing slash according to the middleware configuration.

If the path is already in a canonical form, it calls the handler h.

type TrailingSlashMode

type TrailingSlashMode int

TrailingSlashMode specifies how the trailing slash should be handled on the request URL's Path.

const (
	// Leave keeps the trailing slash the way it was received.
	Leave TrailingSlashMode = iota
	// Add enforces the presence of a trailing slash.
	Add
	// Remove enforces the removal of a trailing slash.
	Remove
)

Jump to

Keyboard shortcuts

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