forwarded

package module
v0.0.0-...-604b053 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2019 License: MIT Imports: 7 Imported by: 0

README

Forwarded

GoDoc Build Status

Forwarded HTTP header (RFC7239).

go get github.com/utisam/go-forwarded
import "github.com/utisam/go-forwarded"

f := forwarded.Parse("for=192.0.2.43, for=\"[2001:db8:cafe::17]\", for=unknown")
fmt.Printf("%s\n", f)
fmt.Printf("% s\n", f) // With spaces
// Output:
// for=192.0.2.43,for=[2001:db8:cafe::17],for=unknown
// for=192.0.2.43, for=[2001:db8:cafe::17], for=unknown

Documentation

Overview

Example
f, _ := forwarded.Parse("for=192.0.2.43, for=\"[2001:db8:cafe::17]\", for=unknown")
fmt.Printf("%s\n", f)
fmt.Printf("% s\n", f) // With spaces
Output:

for=192.0.2.43,for=[2001:db8:cafe::17],for=unknown
for=192.0.2.43, for=[2001:db8:cafe::17], for=unknown

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrInvalidLength = errors.New("invalid length")
View Source
var ErrNoHeaderFound = errors.New("no forwarded header found")

ErrNoHeaderFound is an error when no forwarded header found.

Functions

This section is empty.

Types

type Element

type Element struct {
	By    string `json:"by,omitempty"`
	For   string `json:"for,omitempty"`
	Host  string `json:"host,omitempty"`
	Proto string `json:"proto,omitempty"`
}

Element is a step of proxy.

func (*Element) String

func (e *Element) String() string

String returns a string value without extra spaces.

func (*Element) StringSpace

func (e *Element) StringSpace() string

StringSpace returns a string value with spaces.

type Forwarded

type Forwarded []*Element

Forwarded is a slice of each step.

func AlignAllX

func AlignAllX(header http.Header) Forwarded

func AlignX

func AlignX(fields ...XField) Forwarded

func FromX

func FromX(fields ...XField) (Forwarded, error)
Example
f, _ := forwarded.FromX(
	forwarded.For("203.0.113.1, 203.0.113.2"),
	forwarded.Host("example.com, example.org"),
)
fmt.Println("Forwarded: " + f.String())
Output:

Forwarded: for=203.0.113.1;host=example.com,for=203.0.113.2;host=example.org

func Parse

func Parse(forwarded string, opts ...ParseOption) (Forwarded, error)

Parse forwarded field

func ParseHeader

func ParseHeader(header http.Header, opts ...ParseOption) (Forwarded, error)

ParseHeader parse forwarded header fields

func (Forwarded) Format

func (f Forwarded) Format(s fmt.State, c rune)

Format is a method for fmt.Formatter.

func (Forwarded) String

func (f Forwarded) String() string

String returns a string value without extra spaces.

func (Forwarded) StringSpace

func (f Forwarded) StringSpace() string

StringSpace returns a string value with spaces.

type ParseOption

type ParseOption func(*parser)

ParseOption is a option to configure parser.

func InitialCapacity

func InitialCapacity(n int) ParseOption

InitialCapacity is a option of perser to configure initial capacity of Forwarded slice.

type XField

type XField interface {
	// contains filtered or unexported methods
}

func By

func By(s string) XField

func For

func For(s string) XField

func Host

func Host(s string) XField

func Proto

func Proto(s string) XField

func RealHost

func RealHost(s string) XField

func RealIP

func RealIP(s string) XField

Jump to

Keyboard shortcuts

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