proxyhead

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package proxyhead implements a middleware around HTTP proxies headers.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMiddleware

func NewMiddleware(opts ...Option) func(http.Handler) http.Handler

NewMiddleware returns a middleware that injects client information into r, overriding r's original values even if information from proxy can't be found, ensuring only proxy is trusted.

Example
package main

import (
	"fmt"
	"net/http"

	"codeberg.org/kema/kmicro/pkg/http/middleware/proxyhead"
	"codeberg.org/kema/kmicro/pkg/http/router"
)

func main() {
	r := router.New()
	r.Use(proxyhead.NewMiddleware())
	// curl -H 'X-Forwarded-For: 1.2.3.4' -H 'X-Forwarded-Proto: http' -H 'X-Forwarded-Host: www.example.com' localhost:8080/
	r.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) {
		_, _ = fmt.Fprintf(w, "remoteAddr: %s, proto: %s, host: %s\n", r.RemoteAddr, r.Proto, r.Host)
	})

	_ = http.ListenAndServe("[::]:8080", r.Compile())
}

func WrapHandler

func WrapHandler(next http.Handler, opts ...Option) http.Handler

WrapHandler wraps next with proxied client information injection into r, overriding r's original values even if information from proxy can't be found, ensuring only proxy is trusted.

Types

type Option

type Option func(*config)

Option configures http.TimeoutHandler.

func WithHostExtractor

func WithHostExtractor(extractor func([]string) string) Option

WithRemoteAddrExtractor sets the extractor to use to extract host.

func WithHostHeadKey

func WithHostHeadKey(headKey string) Option

WithHostHeadKey sets the header key used to extract host.

func WithProtoExtractor

func WithProtoExtractor(extractor func([]string) string) Option

WithRemoteAddrExtractor sets the extractor to use to extract protocol.

func WithProtoHeadKey

func WithProtoHeadKey(headKey string) Option

WithProtoHeadKey sets the header key used to extract protocol.

func WithRemoteAddrExtractor

func WithRemoteAddrExtractor(extractor func([]string) *netip.Addr) Option

WithRemoteAddrExtractor sets the extractor to use to extract remote address.

func WithRemoteAddrHeadKey

func WithRemoteAddrHeadKey(headKey string) Option

WithRemoteAddrHeadKey sets the header key used to extract remote address.

Jump to

Keyboard shortcuts

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