hsts

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2017 License: MIT Imports: 5 Imported by: 0

README

hsts

Go Report Card GoDoc

HSTS middleware for Golang net/http

Example
package main

import (
	"fmt"
	"net/http"
	"time"

	"github.com/acoshift/hsts"
	"github.com/acoshift/middleware"
)

func handler(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "OK")
}

func main() {
	h := middleware.Chain(
		hsts.New(hsts.Config{
			Skipper:           middleware.SkipHTTP,
			MaxAge:            31536000 * time.Second,
			IncludeSubDomains: true,
			Preload:           true,
		}),
	)(http.HandlerFunc(handler))
	http.ListenAndServe(":8080", h)
}

Documentation

Overview

Package hsts provides net/http middleware for hsts see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultConfig = Config{
		Skipper:           middleware.SkipHTTP,
		MaxAge:            31536000 * time.Second,
		IncludeSubDomains: false,
		Preload:           false,
	}

	PreloadConfig = Config{
		Skipper:           middleware.SkipHTTP,
		MaxAge:            63072000 * time.Second,
		IncludeSubDomains: true,
		Preload:           true,
	}
)

Pre-defiend config

Functions

func New

func New(config Config) middleware.Middleware

New creates new HSTS middleware

Types

type Config

type Config struct {
	Skipper           middleware.Skipper
	MaxAge            time.Duration
	IncludeSubDomains bool
	Preload           bool
}

Config is the HSTS config

Jump to

Keyboard shortcuts

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