redirecthttps

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2017 License: MIT Imports: 3 Imported by: 0

README

Logo

RedirectHTTPS: HTTPS Redirection Middleware

A minimalistic middleware that redirects all network traffic from the insecure HTTP protocol to the HTTPS transport, all written in Go


Go Report Card Build Status Coverage Status github issues release chat license


Installation

go get github.com/acoshift/redirecthttps

Usage Example

This middleware can be applied in the middleware chain, as follows:

middlewares := middleware.Chain(
  // We can put our redirection middleware right here.
  redirecthttps.New(redirecthttps.Config{
    // The redirection mode can be specified below.
    Mode: redirecthttps.OnlyProxy
  }),
)

mux.Handle("/", middlewares(app.Handler()))

Configuration: Redirection Modes

There are three redirection modes, which can be specified before instantiating the middleware.

First, the OnlyConnectionState Mode, which only checks the connection state from request.TLS, and perform the redirection if TLS is not present in the request.

Second, the OnlyProxy Mode, which only checks the X-Forwarded-Proto header from the request in order to determine if it's using plain HTTP or not. If so, perform the redirection.

Finally, the All Mode, which checks both the X-Forwarded-Proto Header AND the request.TLS variable.

Contribution

If you found an issue in this library, please file file an issue at https://github.com/acoshift/redirecthttps/issues.

If you wanted to help improve this middleware, feel free to fork this project and submit a pull request through GitHub. Thanks!

License

MIT License

Copyright (c) 2017 Thanatat Tamtan

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(config Config) middleware.Middleware

New creates new redirect https middleware

Types

type Config

type Config struct {
	Skipper middleware.Skipper
	Mode    Mode
}

Config is redirect https middleware config

type Mode

type Mode int

Mode is the redirect https mode

const (
	// OnlyConnectionState check only connection state from r.TLS
	OnlyConnectionState Mode = iota

	// OnlyProxy check only X-Forwarded-Proto in request header
	OnlyProxy

	// All check both X-Forwarded-Proto and Request
	All
)

Jump to

Keyboard shortcuts

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