netutil

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientAddrFromHeaders

func ClientAddrFromHeaders(header http.Header) (ip netip.Addr, port uint16)

ClientAddrFromHeaders returns the IP address, and optionally port, of the client for an HTTP request from one of various headers in order: Forwarded, X-Real-IP, X-Forwarded-For. For the multi-valued Forwarded and X-Forwarded-For headers, the first value in the list is returned. If the port is unknown, it will be zero.

If the client is able to control the headers, they can control the result of this function. The result should therefore not necessarily be trusted to be correct; that depends on the presence and configuration of proxies in front of apm-server.

func SplitAddrPort

func SplitAddrPort(in string) (netip.Addr, uint16)

SplitAddrPort splits a network address of the form "host", "host:port", "[host]:port" or "[host]:port" into a netip.Addr and port.

If input has no port, 0 will be returned for the port. If input cannot be parsed or it is empty, (invalidip, 0) will be returned.

Types

This section is empty.

Jump to

Keyboard shortcuts

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