hsts

package module
v0.0.0-...-a83c0b2 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2016 License: MIT Imports: 8 Imported by: 0

README

hsts

Go Report Card GoDoc Build Status

golang hsts library

Documentation

Overview

Example
package main

import (
	"fmt"
	"net/http"

	"github.com/tam7t/hsts"
)

func main() {
	hosts := hsts.NewMemStorage()

	tr := &hsts.Transport{
		Transport: http.DefaultTransport,
		Storage:   hosts,
	}
	client := &http.Client{Transport: tr}

	// http://github.com will redirect to https, then set hsts header
	fmt.Println("GET: http://github.com")
	_, err := client.Get("http://github.com")
	if err != nil {
		fmt.Println(err)
	}

	// subsequent request to http://github.com will be intercepted and forced over
	// https
	fmt.Println("GET: http://github.com")
	_, err = client.Get("http://github.com")
	if err != nil {
		fmt.Println(err)
	}
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Domain

type Domain struct {
	Host       string
	Subdomains bool
	Permanent  bool
	Created    int64
	MaxAge     int64
}

Domain holds hsts information about a domain

func (*Domain) Check

func (d *Domain) Check(h string) bool

Check returns whether the given host should use TLS based on the Domain rule

type MemStorage

type MemStorage struct {
	// contains filtered or unexported fields
}

MemStorage is threadsafe hsts host storage backed by an in-memory map

func NewMemStorage

func NewMemStorage() *MemStorage

NewMemStorage initializes hsts in-memory datastructure

func (*MemStorage) Add

func (hs *MemStorage) Add(d *Domain)

Add a domain to hsts storage

func (*MemStorage) Contains

func (hs *MemStorage) Contains(h string) bool

Contains whether storage has host

type Storage

type Storage interface {
	Contains(host string) bool
	Add(d *Domain)
}

Storage is threadsafe hsts storage interface

type Transport

type Transport struct {
	Transport http.RoundTripper
	Storage   Storage
}

Transport contains the hosts that must be https

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip satisfies the RoundTripper interface for implementing HSTS

Jump to

Keyboard shortcuts

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