diff options
author | Alejandro RodrÃguez <alejorro70@gmail.com> | 2022-06-30 21:37:31 +0200 |
---|---|---|
committer | Alejandro RodrÃguez <alejorro70@gmail.com> | 2022-06-30 22:27:33 +0200 |
commit | 9b60ce49460876d0e599f2fec65f02856930dbcd (patch) | |
tree | 9179705f9e8b6ee309d456323fbaedaa70141c7e /client/gitlabnet.go | |
parent | 01f4e022c04b29b896eb383e6e6a33f96a6beeb1 (diff) | |
download | gitlab-shell-9b60ce49460876d0e599f2fec65f02856930dbcd.tar.gz |
Pass original IP from PROXY requests to internal API calls
Diffstat (limited to 'client/gitlabnet.go')
-rw-r--r-- | client/gitlabnet.go | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/client/gitlabnet.go b/client/gitlabnet.go index 31131d2..c34f148 100644 --- a/client/gitlabnet.go +++ b/client/gitlabnet.go @@ -41,6 +41,9 @@ type ApiError struct { Msg string } +// To use as the key in a Context to set an X-Forwarded-For header in a request +type OriginalRemoteIPContextKey struct{} + func (e *ApiError) Error() string { return e.Msg } @@ -150,6 +153,11 @@ func (c *GitlabNetClient) DoRequest(ctx context.Context, method, path string, da } request.Header.Set(apiSecretHeaderName, tokenString) + originalRemoteIP, ok := ctx.Value(OriginalRemoteIPContextKey{}).(string) + if ok { + request.Header.Add("X-Forwarded-For", originalRemoteIP) + } + request.Header.Add("Content-Type", "application/json") request.Header.Add("User-Agent", c.userAgent) request.Close = true |