forwarded

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

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

Go to latest
Published: Sep 22, 2025 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package forwarded implements a RFC 7239 (Forwarded HTTP Extension) parser.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(line string, reverse bool) iter.Seq2[*Element, error]

Parse parses elements in the given line. If reverse is true, the elements are parsed in reverse. The error returned is of type *ParseError.

func ParseRequest

func ParseRequest(r *http.Request, reverse bool) iter.Seq2[*Element, error]

ParseRequests parses elements in the Forwarded header in request r. If reverse is true, the elements are parsed in reverse. The error returned is of type *ParseError.

Types

type Element

type Element struct {
	By    Node
	For   Node
	Proto string
	Host  string
	Extra []Paramater
}

Element contains information about a proxy.

func Last

func Last(line string) (*Element, error)

Last returns the last element in the given line. The error returned is of type *ParseError.

func LastRequest

func LastRequest(r *http.Request) (*Element, error)

LastRequest returns the last element in the Forwarded header in request r. The error returned is of type *ParseError.

func (Element) String

func (e Element) String() string

String returns the string equivalent of element e. It assumes that element e is valid.

type Node

type Node string

A Node identifier is one of the following:

  • The client's IP address, with an optional port number.
  • A token indicating that the IP address of the client is not known to the proxy server.
  • A generated token, allowing for tracing and debugging, while allowing the internal structure or sensitive information to be hidden.

func (Node) AddrPort

func (n Node) AddrPort() (netip.Addr, NodePort, bool)

AddrPort attempts to parse node n as a IP address and port. Either addr or node port returned may be invalid.

func (Node) IsObfuscated

func (n Node) IsObfuscated() bool

IsObfuscated returns true if node n is a generated token.

func (Node) IsUnknown

func (n Node) IsUnknown() bool

IsUnknown returns true if node n is the unknown token.

type NodePort

type NodePort string

NodePort represents the port of a node, either a uint16 value or obfuscated.

func (NodePort) IsObfuscated

func (np NodePort) IsObfuscated() bool

IsObfuscated returns true if node port np is obfuscated.

func (NodePort) IsValid

func (np NodePort) IsValid() bool

IsValid returns true if node port np is not empty.

func (NodePort) Uint16

func (np NodePort) Uint16() (uint16, bool)

Uint16 attempts to parse the port as a uint16 value.

type Paramater

type Paramater struct {
	Key, Value string
}

Pair represents a key-value pair making up a element parameter.

type ParseError

type ParseError struct {
	Msg  string
	Text string
}

ParseError is returned if a line cannot be parsed.

func (*ParseError) Error

func (e *ParseError) Error() string

Jump to

Keyboard shortcuts

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