httpseverywhere

package module
v0.0.0-...-19ae11f Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2020 License: Apache-2.0 Imports: 17 Imported by: 1

README

httpseverywhere

Go implementation of using HTTPS Everywhere rule sets to send traffic over HTTPS. Many thanks to the EFF team maintaining such an amazing project!

Example usage:

import "url"
import "github.com/getlantern/httpseverywhere"

...

httpURL, _ := url.Parse("http://name.com")
rewrite := httpseverywhere.Default()
httpsURL, changed := rewrite(httpURL)
if changed {
	// Redirect to httpsURL
	...
}

Please note that this library does not support any rules that include backtracking, specifically any rules with (?! or (?=, because those are not supported in Go's regular expressions packages for performance reasons. That excludes approximately 6,000 out of around 22,000 rule sets.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Preprocessor = &preprocessor{
	log: golog.LoggerFor("httpseverywhere-preprocessor"),
}

Preprocessor is a struct for preprocessing rules into a GOB file.

Functions

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

Types

type Exclusion

type Exclusion struct {
	Pattern string `xml:"pattern,attr"`
}

Exclusion is a RE pattern to ignore when processing a rule set.

type Rewrite

type Rewrite func(url *url.URL) (string, bool)

Rewrite changes an HTTP URL to rewrite.

func Default

func Default() Rewrite

Default returns a lazily-initialized Rewrite using the default rules

func Eager

func Eager() Rewrite

Eager returns an eagerly-initialized Rewrite using the default rules

type Rule

type Rule struct {
	From string `xml:"from,attr"`
	To   string `xml:"to,attr"`
}

Rule is a rule to apply when processing a URL.

type Ruleset

type Ruleset struct {
	Off       string       `xml:"default_off,attr"`
	Platform  string       `xml:"platform,attr"`
	Target    []*Target    `xml:"target"`
	Exclusion []*Exclusion `xml:"exclusion"`
	Rule      []*Rule      `xml:"rule"`
}

Ruleset is a set of rules to apply to a set of targets with flags for things like whether or not the set is active, targets, rules, exclusions, etc.

type Target

type Target struct {
	Host string `xml:"host,attr"`
}

Target is the target host for a given rule.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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