forwarded

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package forwarded parses the X-Forwarded-For header along with a socket remote address to produce the chain of addresses that a request traversed.

It is a Go port of the npm module "forwarded". The returned slice always begins with the socket remote address, followed by the addresses parsed from the X-Forwarded-For header value in reverse order (that is, the proxy closest to the server first).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Forwarded

func Forwarded(remoteAddr string, xff string) []string

Forwarded returns the list of addresses in the request chain.

The first element is remoteAddr (with any port stripped). The remaining elements are the comma-separated entries of the X-Forwarded-For value (xff), trimmed of surrounding whitespace and appended from the rightmost entry to the leftmost entry. Empty entries in the header are preserved as empty strings, matching the behavior of the npm "forwarded" module.

func FromRequest

func FromRequest(r *http.Request) []string

FromRequest returns the address chain for an *http.Request, reading r.RemoteAddr (with the port stripped) and the X-Forwarded-For header.

Types

This section is empty.

Jump to

Keyboard shortcuts

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