Skip to content

use proxy for omnifunc when configured in .gitconfig or .git/config#52

Closed
shadowwa wants to merge 1 commit into
shumphrey:masterfrom
shadowwa:proxy-support
Closed

use proxy for omnifunc when configured in .gitconfig or .git/config#52
shadowwa wants to merge 1 commit into
shumphrey:masterfrom
shadowwa:proxy-support

Conversation

@shadowwa
Copy link
Copy Markdown

When using a gitlab instance behind a proxy, I need to configure the proxy in ~/.gitconfig or .git/config file.

[http "https://gitlab-url.private"]
    proxy = socks5h://proxy-url:8082
# or
[http]
    proxy = socks5h://proxy-url:8082

In fugitive-gitlab.vim, curl requests are not using this proxy hence the omnifunc does not works.

With this commit, if a proxy is configured in git config files, it will by used.

@shumphrey
Copy link
Copy Markdown
Owner

hmm, I would have expected that config to be part of your ~/.curlrc

@shumphrey
Copy link
Copy Markdown
Owner

I haven't fully thought this through, but I think it used to be common for the git config of gitlab to be different to the api/http stuff.
I'm a bit concerned this could break other use cases.
curl supports both the HTTP_PROXY environment variables and the ~/.curlrc config file.
Is there something you can do with those for your use case?

@shumphrey
Copy link
Copy Markdown
Owner

I had a quick scan of rhubarb to see if it supports doing anything with gitconfig http proxy and it doesn't appear to.

@shadowwa
Copy link
Copy Markdown
Author

I haven't fully thought this through, but I think it used to be common for the git config of gitlab to be different to the api/http stuff. I'm a bit concerned this could break other use cases.

Do you mean when git use

[remote "origin"]
  url = git@my-ssh.gitlab.private

and the gitlab api is accessible via https://gitlab-url.private ?
I did not thought about this case. A quick test show that it is working but means having a proxy conf in .gitconfig only to be used by fugitive-gitlab and not git.
It maybe cleaner to have a new option like

let g:gitlab_proxies = {'gitlab-url.private': 'socks5h://proxy-url:8082'}

curl supports both the HTTP_PROXY environment variables and the ~/.curlrc config file. Is there something you can do with those for your use case?

It was my first idea but unfortunately, proxies can only be set global from HTTP_PROXY environment variables or in ~/.curlrc not per host basis

@shumphrey
Copy link
Copy Markdown
Owner

I have to say I am a bit baffled by this use case.
I don't understand why GitLab and only GitLab is behind a non-transparent proxy.

@shadowwa
Copy link
Copy Markdown
Author

shadowwa commented May 6, 2026

Unfortunately, due to heterogeneous private networks, we don't have a transparent proxy, we have to use a proxy.pac file that set differents proxies for differents set of urls.
Pac files are supported by browser hence no problems for using :GBrowse, but as curl does not support pac file (or even multi proxy configuration) the omnifunc of this plugin did not worked.

I've modified my MR to use a gitlab_proxie configuration variable set in .vimrc, if it's ok for you I'll add test and documentation.

@shumphrey
Copy link
Copy Markdown
Owner

shumphrey commented May 7, 2026

How about a wrapper for curl?

something like:

~/.bin/curl

#!/usr/bin/env bash

TARGET_URL="${@: -1}"
PROXY_ADDRESS=$(pactester -p /path/to/proxy.pac -u $TARGET_URL)

if [[ "$PROXY_SERVER" == "DIRECT" ]]; then
    # Call the REAL curl without proxy
    /usr/bin/curl "$@"
else
    # Format "PROXY host:port" to "http://host:port"
    PROXY_CLEAN=$(echo $PROXY_SERVER | sed 's/PROXY //;s/;//')
    /usr/bin/curl -x "$PROXY_CLEAN" "$@"
fi
export PATH="~/.bin:$PATH"
vim

I've not tested any of that as I don't have any pac files, the example is mostly AI generated, but will any of that work?
I'm also open to overriding the executable fugitive-gitlab uses so it calls this script instead of real curl via a variable in vimrc.
I'm not keen on giving this plugin knowledge of proxies.

@shadowwa
Copy link
Copy Markdown
Author

After few fixes, I've ended up using this wrapper and it works fine.

#!/usr/bin/env bash

# FIXME does not work if url is not the last argument
TARGET_URL="${*: -1}"
PROXY_SERVER=$(pactester -p /path/to/proxy.pac -u "$TARGET_URL")

if [[ "$PROXY_SERVER" == 'DIRECT' || -z "$PROXY_SERVER" ]]; then
    # Call the REAL curl without proxy
    /usr/bin/curl "$@"
else
    # only keep the first proxy.
    # TODO implement fallback if several proxies are defined
    PROXY_SERVER="${PROXY_SERVER%;*}"
    # Format "PROXY host:port" to "host:port"
    # and "SOCKS5 host:port" to "socks5://port:host"
    PROTOCOL="${PROXY_SERVER% *}"
    PROXY_URL=${PROXY_SERVER##* }
    if [[ "$PROTOCOL" == 'PROXY' ]]; then
        PROTOCOL=''
    else
        PROTOCOL="${PROTOCOL,,}://"
    fi
    /usr/bin/curl -x "${PROTOCOL}${PROXY_URL}" "$@"
fi

I'm also open to overriding the executable fugitive-gitlab uses so it calls this script instead of real curl via a variable in vimrc.

It can be useful to avoid running problem with other script using curl (for instance putting option after the URL).

@shadowwa shadowwa closed this May 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants