New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

github.com/stanvit/go-forwarded

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/stanvit/go-forwarded

  • v0.0.0-20150905014133-9ab0287086b3
  • Source
  • Go
  • Socket score

Version published
Created
Source

go-forwarded

Build Status GoDoc

Description

forwarded is a Golang decorator/wrapper for http.Handler that parses X-Forwarded-For and X-Forwarded-Protocol headers and updates passing http.Request.RemoteAddr and http.Request.TLS accordingly.

It supports arbitrary named individual headers and RFC7239 Forwarded header.

Usage example

Extremely simplified example:

package main

import (
	"fmt"
	"github.com/stanvit/go-forwarded"
	"net/http"
)

func simpleHandler(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "text/plain")
	w.WriteHeader(http.StatusOK)
	w.Write([]byte(fmt.Sprintf("Requesting IP is %v\nHTTPS: %t\n", r.RemoteAddr, r.TLS != nil)))
}

func main() {
	wrapper, _ := forwarded.New("192.168.0.0/16, 127.0.0.1", false, false, "X-Forwarded-For", "X-Forwarded-Protocol")
	handler := wrapper.Handler(http.HandlerFunc(simpleHandler))
	http.Handle("/", handler)
	http.ListenAndServe(":8082", nil)
}
$ curl -H 'X-Forwarded-For: 1.2.3.4' -H 'X-Forwarded-Protocol: https' -v http://127.0.0.1:8082
* Rebuilt URL to: http://127.0.0.1:8082/
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 8082 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.35.0
> Host: 127.0.0.1:8082
> Accept: */*
> X-Forwarded-For: 1.2.3.4
> X-Forwarded-Protocol: https
> 
< HTTP/1.1 200 OK
< Content-Type: text/plain
< Date: Sat, 05 Sep 2015 01:16:15 GMT
< Content-Length: 43
< 
Requesting IP is 1.2.3.4:65535
HTTPS: true
* Connection #0 to host 127.0.0.1 left intact

API documentation

API documentation is avalable at Godoc

FAQs

Package last updated on 05 Sep 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc