summaryrefslogtreecommitdiff
path: root/go/internal/gitlabnet/client.go
diff options
context:
space:
mode:
Diffstat (limited to 'go/internal/gitlabnet/client.go')
-rw-r--r--go/internal/gitlabnet/client.go12
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