aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor
diff options
context:
space:
mode:
authorGravatar Frédéric Guillot <fred@miniflux.net>2018-06-01 07:22:18 -0700
committerGravatar Frédéric Guillot <fred@miniflux.net>2018-06-01 07:22:31 -0700
commit3b39f0883c60b6978c6c6df2c0029bd4c96613fe (patch)
treef601e0fc314da8cee5001f208b46482262f5be14 /vendor
parentcf7a7e25fbf94c16ca08ff3e889bdd4373751e2c (diff)
Rewrite RealIP() to avoid returning an empty string
Diffstat (limited to 'vendor')
-rw-r--r--vendor/github.com/tomasen/realip/.travis.yml19
-rw-r--r--vendor/github.com/tomasen/realip/README.md33
-rw-r--r--vendor/github.com/tomasen/realip/realip.go89
-rw-r--r--vendor/github.com/tomasen/realip/realip_test.go95
4 files changed, 0 insertions, 236 deletions
diff --git a/vendor/github.com/tomasen/realip/.travis.yml b/vendor/github.com/tomasen/realip/.travis.yml
deleted file mode 100644
index fdfbf87..0000000
--- a/vendor/github.com/tomasen/realip/.travis.yml
+++ /dev/null
@@ -1,19 +0,0 @@
-language: go
-
-go:
- - tip
-
-before_install:
- # lint
- - go get github.com/golang/lint/golint
-
- # code complexity
- - go get github.com/on99/gocyclo
-
- # test
- - go get github.com/smartystreets/goconvey/convey
-
-script:
- - golint ./...
- - go vet ./...
- - gocyclo -skip-godeps=true -top 10 -over 10 . # over 10 is bad code
diff --git a/vendor/github.com/tomasen/realip/README.md b/vendor/github.com/tomasen/realip/README.md
deleted file mode 100644
index 085f182..0000000
--- a/vendor/github.com/tomasen/realip/README.md
+++ /dev/null
@@ -1,33 +0,0 @@
-# RealIP
-
-[![GoDoc](https://godoc.org/github.com/Tomasen/realip?status.svg)](http://godoc.org/github.com/Tomasen/realip)
-
-Go package that can be used to get client's real public IP, which usually useful for logging HTTP server.
-
-### Feature
-
-* Follows the rule of X-Real-IP
-* Follows the rule of X-Forwarded-For
-* Exclude local or private address
-
-## Example
-
-```go
-package main
-
-import "github.com/Tomasen/realip"
-
-func (h *Handler) ServeIndexPage(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
- clientIP := realip.FromRequest(r)
- log.Println("GET / from", clientIP)
-}
-```
-
-## Developing
-
-Commited code must pass:
-
-* [golint](https://github.com/golang/lint)
-* [go vet](https://godoc.org/golang.org/x/tools/cmd/vet)
-* [gofmt](https://golang.org/cmd/gofmt)
-* [go test](https://golang.org/cmd/go/#hdr-Test_packages):
diff --git a/vendor/github.com/tomasen/realip/realip.go b/vendor/github.com/tomasen/realip/realip.go
deleted file mode 100644
index e2803a2..0000000
--- a/vendor/github.com/tomasen/realip/realip.go
+++ /dev/null
@@ -1,89 +0,0 @@
-package realip
-
-import (
- "errors"
- "net"
- "net/http"
- "strings"
-)
-
-var cidrs []*net.IPNet
-
-func init() {
- maxCidrBlocks := []string{
- "127.0.0.1/8", // localhost
- "10.0.0.0/8", // 24-bit block
- "172.16.0.0/12", // 20-bit block
- "192.168.0.0/16", // 16-bit block
- "169.254.0.0/16", // link local address
- "::1/128", // localhost IPv6
- "fc00::/7", // unique local address IPv6
- "fe80::/10", // link local address IPv6
- }
-
- cidrs = make([]*net.IPNet, len(maxCidrBlocks))
- for i, maxCidrBlock := range maxCidrBlocks {
- _, cidr, _ := net.ParseCIDR(maxCidrBlock)
- cidrs[i] = cidr
- }
-}
-
-// isLocalAddress works by checking if the address is under private CIDR blocks.
-// List of private CIDR blocks can be seen on :
-//
-// https://en.wikipedia.org/wiki/Private_network
-//
-// https://en.wikipedia.org/wiki/Link-local_address
-func isPrivateAddress(address string) (bool, error) {
- ipAddress := net.ParseIP(address)
- if ipAddress == nil {
- return false, errors.New("address is not valid")
- }
-
- for i := range cidrs {
- if cidrs[i].Contains(ipAddress) {
- return true, nil
- }
- }
-
- return false, nil
-}
-
-// FromRequest return client's real public IP address from http request headers.
-func FromRequest(r *http.Request) string {
- // Fetch header value
- xRealIP := r.Header.Get("X-Real-Ip")
- xForwardedFor := r.Header.Get("X-Forwarded-For")
-
- // If both empty, return IP from remote address
- if xRealIP == "" && xForwardedFor == "" {
- var remoteIP string
-
- // If there are colon in remote address, remove the port number
- // otherwise, return remote address as is
- if strings.ContainsRune(r.RemoteAddr, ':') {
- remoteIP, _, _ = net.SplitHostPort(r.RemoteAddr)
- } else {
- remoteIP = r.RemoteAddr
- }
-
- return remoteIP
- }
-
- // Check list of IP in X-Forwarded-For and return the first global address
- for _, address := range strings.Split(xForwardedFor, ",") {
- address = strings.TrimSpace(address)
- isPrivate, err := isPrivateAddress(address)
- if !isPrivate && err == nil {
- return address
- }
- }
-
- // If nothing succeed, return X-Real-IP
- return xRealIP
-}
-
-// RealIP is depreciated, use FromRequest instead
-func RealIP(r *http.Request) string {
- return FromRequest(r)
-}
diff --git a/vendor/github.com/tomasen/realip/realip_test.go b/vendor/github.com/tomasen/realip/realip_test.go
deleted file mode 100644
index e80efe0..0000000
--- a/vendor/github.com/tomasen/realip/realip_test.go
+++ /dev/null
@@ -1,95 +0,0 @@
-package realip
-
-import (
- "net/http"
- "testing"
-)
-
-func TestIsPrivateAddr(t *testing.T) {
- testData := map[string]bool{
- "127.0.0.0": true,
- "10.0.0.0": true,
- "169.254.0.0": true,
- "192.168.0.0": true,
- "::1": true,
- "fc00::": true,
-
- "172.15.0.0": false,
- "172.16.0.0": true,
- "172.31.0.0": true,
- "172.32.0.0": false,
-
- "147.12.56.11": false,
- }
-
- for addr, isLocal := range testData {
- isPrivate, err := isPrivateAddress(addr)
- if err != nil {
- t.Errorf("fail processing %s: %v", addr, err)
- }
-
- if isPrivate != isLocal {
- format := "%s should "
- if !isLocal {
- format += "not "
- }
- format += "be local address"
-
- t.Errorf(format, addr)
- }
- }
-}
-
-func TestRealIP(t *testing.T) {
- // Create type and function for testing
- type testIP struct {
- name string
- request *http.Request
- expected string
- }
-
- newRequest := func(remoteAddr, xRealIP string, xForwardedFor ...string) *http.Request {
- h := http.Header{}
- h.Set("X-Real-IP", xRealIP)
- for _, address := range xForwardedFor {
- h.Set("X-Forwarded-For", address)
- }
-
- return &http.Request{
- RemoteAddr: remoteAddr,
- Header: h,
- }
- }
-
- // Create test data
- publicAddr1 := "144.12.54.87"
- publicAddr2 := "119.14.55.11"
- localAddr := "127.0.0.0"
-
- testData := []testIP{
- {
- name: "No header",
- request: newRequest(publicAddr1, ""),
- expected: publicAddr1,
- }, {
- name: "Has X-Forwarded-For",
- request: newRequest("", "", publicAddr1),
- expected: publicAddr1,
- }, {
- name: "Has multiple X-Forwarded-For",
- request: newRequest("", "", localAddr, publicAddr1, publicAddr2),
- expected: publicAddr2,
- }, {
- name: "Has X-Real-IP",
- request: newRequest("", publicAddr1),
- expected: publicAddr1,
- },
- }
-
- // Run test
- for _, v := range testData {
- if actual := FromRequest(v.request); v.expected != actual {
- t.Errorf("%s: expected %s but get %s", v.name, v.expected, actual)
- }
- }
-}