headr

package module
v0.0.0-...-14575e6 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2022 License: NCSA Imports: 5 Imported by: 1

README

headr

This project is currently in a state of development and therefore flux. Any public API presented herein should be considered unstable and unusable.

This notice will be removed when the API has stabilized and the project sees regular use.

What's This?

go/headr is an HTTP header parsing library that, at present, fixates primarily on processing various incantations of forwarding headers injected by interstitial proxies that perversely manipulate the remote address of the requesting client. This library attempts to normalize access to these headers thereby presenting a uniform context through which they may be inspected and used.

It is not currently ready for production use, or any use, as of this writing.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NormalizeForwarded

func NormalizeForwarded(r *http.Request) (cr *http.Request)

NormalizeForwarded proxy headers for the given request.

This will always return a new, cloned request from `r`.

Types

type AddrSpec

type AddrSpec struct {
	IP   net.IP
	Name string
}

func (AddrSpec) FormattedString

func (s AddrSpec) FormattedString() string

func (AddrSpec) HasAddress

func (s AddrSpec) HasAddress() bool

func (AddrSpec) String

func (s AddrSpec) String() string

type ForwardProxy

type ForwardProxy struct {
	// Interface from which the request originated. This may not always be
	// populated, and when processing X-Forwarded-* and X-Real-IP headers, this
	// will always contain localhost.
	//
	// Forwarded header: "by"
	Interface AddrSpec

	// Source address initiating the request. May be a chain of proxies.
	Source []AddrSpec

	// Host header.
	Host string

	// Port used to connect to us.
	Port int

	// Protocol; usually "http" or "https" in most cases.
	Protocol string
}

func Parse

func Parse(r *http.Request) (fp *ForwardProxy)

Parse, in order, the following headers: Forwarded, X-Forwarded-For, and X-Real-IP. Precedence is given in aforementioned list; if a previous header is present, any additional headers are ignored and the first match is returned. For instance, if "Forwarded" is present, no further headers will be processed.

func (*ForwardProxy) Client

func (fp *ForwardProxy) Client() AddrSpec

Client returns the source client that initiated the request or an empty IP address if no forwarded chain exists via the request headers.

Use HasProxy() first to determine if an intermediate proxy was present via any of the supported fowarding headers.

func (*ForwardProxy) HasProxy

func (fp *ForwardProxy) HasProxy() bool

func (*ForwardProxy) MakeHeader

func (fp *ForwardProxy) MakeHeader() string

Jump to

Keyboard shortcuts

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