clientip

package
v0.0.57-rc.9 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package clientip provides(in a best effort manner) a client's IP address.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DirectAddress

func DirectAddress(remoteAddr string) string

DirectAddress returns the client socket IP, stripped of port. This strategy should be used if the server accepts direct connections, rather than through a proxy.

func Get

func Get(r *http.Request) string

Get returns the "real" client IP address. See github.com/komuw/ong/middleware.ClientIP

func Leftmost

func Leftmost(headers http.Header) string

Leftmost derives the client IP from the leftmost valid and non-private IP address in the X-Fowarded-For or Forwarded header. This strategy should be used when a valid, non-private IP closest to the client is desired. Note: This MUST NOT be used for security purposes. This IP can be trivially SPOOFED.

The returned IP may contain a zone identifier. If no valid IP can be derived, empty string will be returned.

func ProxyHeader added in v0.0.47

func ProxyHeader(headers http.Header) string

ProxyHeader derives an IP address based off the PROXY protocol v1.

func Rightmost

func Rightmost(headers http.Header) string

Rightmost derives the client IP from the rightmost valid and non-private IP address in the X-Fowarded-For or Forwarded header. This strategy should be used when all reverse proxies between the internet and the server have private-space IP addresses.

The returned IP may contain a zone identifier. If no valid IP can be derived, empty string will be returned.

func SingleIPHeader

func SingleIPHeader(headerName string, headers http.Header) string

SingleIPHeader derives an IP address from a single-IP header. A non-exhaustive list of such single-IP headers is: X-Real-IP, CF-Connecting-IP, True-Client-IP, Fastly-Client-IP, X-Azure-ClientIP, X-Azure-SocketIP, Fly-Client-IP. This strategy should be used when the given header is added by a trusted reverse proxy. You MUST ensure that this header is not spoofable (as is possible with Akamai's use of True-Client-IP, Fastly's default use of Fastly-Client-IP, and Azure's X-Azure-ClientIP). See the single-IP wiki page for more info.

The returned IP may contain a zone identifier. If no valid IP can be derived, empty string will be returned.

func With

func With(r *http.Request, clientAddr string) *http.Request

With returns a *http.Request whose context contains a client IP address.

Types

This section is empty.

Jump to

Keyboard shortcuts

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