diff options
author | Małgorzata Ksionek <mksionek@gitlab.com> | 2019-09-17 16:36:37 +0200 |
---|---|---|
committer | Małgorzata Ksionek <mksionek@gitlab.com> | 2019-09-26 12:26:53 +0200 |
commit | 7f0f6e7621cbc60504f0c1f1bf1541d5b95a4ff8 (patch) | |
tree | ba6a69dcc3574023c4b370b774b728458b64ca9f /go/internal/gitlabnet/client.go | |
parent | 659ad7f7cedab56ff48abe4d6fb8eb25a644a2a8 (diff) | |
download | gitlab-shell-7f0f6e7621cbc60504f0c1f1bf1541d5b95a4ff8.tar.gz |
Add ip address to headers
Diffstat (limited to 'go/internal/gitlabnet/client.go')
-rw-r--r-- | go/internal/gitlabnet/client.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/go/internal/gitlabnet/client.go b/go/internal/gitlabnet/client.go index dacb1d6..26c24d4 100644 --- a/go/internal/gitlabnet/client.go +++ b/go/internal/gitlabnet/client.go @@ -7,6 +7,7 @@ import ( "fmt" "io" "net/http" + "os" "strings" "gitlab.com/gitlab-org/gitlab-shell/go/internal/config" @@ -109,6 +110,9 @@ func (c *GitlabClient) DoRequest(method, path string, data interface{}) (*http.R request.Header.Set(secretHeaderName, encodedSecret) request.Header.Add("Content-Type", "application/json") + ip := ipAddr() + request.Header.Add("X_FORWARDED_FOR", ip) + request.Close = true response, err := c.httpClient.Do(request) @@ -123,6 +127,14 @@ func (c *GitlabClient) DoRequest(method, path string, data interface{}) (*http.R return response, nil } +func ipAddr() string { + address := os.Getenv("SSH_CONNECTION") + if address != "" { + return strings.Fields(address)[0] + } + return address +} + func ParseJSON(hr *http.Response, response interface{}) error { if err := json.NewDecoder(hr.Body).Decode(response); err != nil { return ParsingError |