GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Why Go
  • Case Studies
  • Use Cases
  • Security
  • Learn
  • Effective Go
  • Go User Manual
  • Standard library
  • Release Notes
  • API
  • Packages
  • Recorded Talks
  • Meetups
  • Conferences

This view

  • Original page
  • New address

GeezerVison is showing pkg.go.dev — xff package - github.com/sebest/xff - Go Packages

Details

  • unchecked Valid go.mod file

    The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.

  • checked Redistributable license

    Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.

  • unchecked Tagged version

    Modules with tagged versions give importers more predictable builds.

  • unchecked Stable version

    When a project reaches major version v1 it is considered stable.

  • Learn more about best practices

Repository

github.com/sebest/xff

Links

  • Open Source Insights Logo Open Source Insights

README ¶

X-Forwarded-For middleware fo Go godoc Build Status

Package xff is a net/http middleware/handler to parse Forwarded HTTP Extension in Golang.

Example usage

Install xff:

go get github.com/sebest/xff

Edit server.go:

package main

import (
  "net/http"

  "github.com/sebest/xff"
)

func main() {
  handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
    w.Write([]byte("hello from " + r.RemoteAddr + "\n"))
  })

  xffmw, _ := xff.Default()
  http.ListenAndServe(":8080", xffmw.Handler(handler))
}

Then run your server:

go run server.go

The server now runs on localhost:8080:

$ curl -D - -H 'X-Forwarded-For: 42.42.42.42' http://localhost:8080/
HTTP/1.1 200 OK
Date: Fri, 20 Feb 2015 20:03:02 GMT
Content-Length: 29
Content-Type: text/plain; charset=utf-8

hello from 42.42.42.42:52661

Documentation ¶

Index ¶

  • func GetRemoteAddr(r *http.Request) string
  • func GetRemoteAddrIfAllowed(r *http.Request, allowed func(sip string) bool) string
  • func IsPublicIP(ip net.IP) bool
  • func Parse(ipList string) string
  • type Options
  • type XFF
    • func Default() (*XFF, error)
    • func New(options Options) (*XFF, error)
    • func (xff *XFF) Handler(h http.Handler) http.Handler
    • func (xff *XFF) HandlerFunc(w http.ResponseWriter, r *http.Request)
    • func (xff *XFF) ServeHTTP(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)

Constants ¶

This section is empty.

Variables ¶

This section is empty.

Functions ¶

func GetRemoteAddr ¶

func GetRemoteAddr(r *http.Request) string

GetRemoteAddr parses the given request, resolves the X-Forwarded-For header and returns the resolved remote address.

func GetRemoteAddrIfAllowed ¶

func GetRemoteAddrIfAllowed(r *http.Request, allowed func(sip string) bool) string

GetRemoteAddrIfAllowed parses the given request, resolves the X-Forwarded-For header and returns the resolved remote address if allowed.

func IsPublicIP ¶

func IsPublicIP(ip net.IP) bool

IsPublicIP returns true if the given IP can be routed on the Internet.

func Parse ¶

func Parse(ipList string) string

Parse parses the value of the X-Forwarded-For Header and returns the IP address.

Types ¶

type Options ¶

type Options struct {
	// AllowedSubnets is a list of Subnets from which we will accept the
	// X-Forwarded-For header.
	// If this list is empty we will accept every Subnets (default).
	AllowedSubnets []string
	// Debugging flag adds additional output to debug server side XFF issues.
	Debug bool
}

Options is a configuration container to setup the XFF middleware.

type XFF ¶

type XFF struct {
	// Debug logger
	Log *log.Logger
	// contains filtered or unexported fields
}

XFF http handler

func Default ¶

func Default() (*XFF, error)

Default creates a new XFF handler with default options.

func New ¶

func New(options Options) (*XFF, error)

New creates a new XFF handler with the provided options.

func (*XFF) Handler ¶

func (xff *XFF) Handler(h http.Handler) http.Handler

Handler updates RemoteAdd from X-Fowarded-For Headers.

func (*XFF) HandlerFunc ¶

func (xff *XFF) HandlerFunc(w http.ResponseWriter, r *http.Request)

HandlerFunc provides Martini compatible handler

func (*XFF) ServeHTTP ¶

func (xff *XFF) ServeHTTP(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)

Negroni compatible interface

Source Files ¶

View all Source files
  • xff.go

Directories ¶

Path Synopsis
examples
negroni command
nethttp command
Click to show internal directories.
Click to hide internal directories.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.