Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support to list like headers ie: x-forwarded-for #1

Merged
merged 2 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# How to contribute

Thank you for your interest in improving droneip.

Here is how to contribute back some code or documentation:

- Fork repo
- Create a feature branch off of the `dev` branch
- Make some useful change
- Submit a pull request against the `dev` branch.
- Be kind

12 changes: 11 additions & 1 deletion handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (h *DroneHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {

inspectHeader := config.Get("INSPECT_HEADER")
if inspectHeader != "" {
remoteIP = r.Header.Get(inspectHeader)
remoteIP = getRemoteIP(r.Header.Get(inspectHeader))
}
cacheKey := fmt.Sprintf("droneip-%s", remoteIP)

Expand Down Expand Up @@ -79,3 +79,13 @@ func (h *DroneHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
io.Copy(w, res.Body)

}

func getRemoteIP(ips string) string {
if !strings.Contains(ips, ",") {
return ips
}

ipList := strings.Split(ips, ",")

return strings.Trim(ipList[0], " ")
}
5 changes: 2 additions & 3 deletions logger/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
[![Go Report Card](https://goreportcard.com/badge/github.com/diegohce/logger)](https://goreportcard.com/report/github.com/diegohce/logger)
[![GoDoc](https://godoc.org/github.com/diegohce/logger?status.svg)](https://godoc.org/github.com/diegohce/logger)
[![GPLv3 license](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://github.com/diegohce/logger/blob/master/LICENSE)
[![GPLv3 license](https://img.shields.io/badge/License-apache_2.0-blue.svg)](https://github.com/diegohce/logger/blob/master/LICENSE)
[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/diegohce/logger/graphs/commit-activity)
[![HitCount](http://hits.dwyl.io/diegohce/logger.svg)](http://hits.dwyl.io/diegohce/logger)
[![Sourcegraph](https://sourcegraph.com/github.com/diegohce/logger/-/badge.svg)](https://sourcegraph.com/github.com/diegohce/logger?badge)
[![Sourcegraph](https://sourcegraph.com/github.com/diegohce/droneip/logger/-/badge.svg)](https://sourcegraph.com/github.com/diegohce/droneip/logger?badge)

# logger

Expand Down
26 changes: 26 additions & 0 deletions service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,29 @@ func TestAdmin(t *testing.T) {
}

}

func TestGetRemoteIP(t *testing.T) {

cases := []struct {
ips string
want string
}{
{
ips: "10.10.0.1, 10.10.0.2, 10.10.0.3, 10.10.0.4, 10.10.0.5, 10.10.0.6",
want: "10.10.0.1",
},
{
ips: "10.10.0.1",
want: "10.10.0.1",
},
}

for _, c := range cases {
got := getRemoteIP(c.ips)
if got != c.want {
t.Errorf("got %s want %s", got, c.want)
}

}

}
Loading