perllwpcpanm

How can cpanm retrieve settings for a proxy that requires username and password


I'm working with CPANM to interact with a proxy that requires username and password. I specified the settings when running "o conf init /proxy/ under cpan". My perception is the variables used in a unix environment for specifying proxies are not standard throughout the environment. Other unix utilities are working correctly through the proxy after setting environment variables to the correct values.

My questions are the following:

  1. How does CPANM interfaces with any environment variables? What would they be?

  2. Is there a relevant area of the code we can look to help remove ambiguity, I'm thinking there is an LWP interface inside of CPANM? https://github.com/miyagawa/cpanminus/blob/devel/App-cpanminus/cpanm

####:/mnt/c/Projects$ sudo cpanm install Catalyst::Helper -v
cpanm (App::cpanminus) 1.7040 on perl 5.022001 built for x86_64-linux-gnu-thread-multi
Work directory is /home/####/.cpanm/work/1543605706.124
You have make /usr/bin/make
You have LWP 6.36
You have /bin/tar: tar (GNU tar) 1.28
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by John Gilmore and Jay Fenlason.
Searching install () on cpanmetadb ...

########:/mnt/c/Projects$ env | grep HTTP_proxy
HTTP_proxy=http://####:###

Solution

  • As far as I can see, cpanm (actually App::Cpanminus relies on HTTP::Tiny to run HTTP requests.

    From the docs of HTTP::Tiny :

    HTTP::Tiny can proxy both http and https requests. Only Basic proxy authorization is supported and it must be provided as part of the proxy URL: http://user:pass@proxy.example.com/.

    HTTP::Tiny supports the following proxy environment variables: http_proxy or HTTP_PROXY, https_proxy or HTTPS_PROXY, all_proxy or ALL_PROXY

    Hence you should try and specify the proxy username and password as part of the url, like :

    $ export HTTP_PROXY=http://<user>:<password>@<url>:<port>
    $ export HTTPS_PROXY=http://<user>:<password>@<url>:<port>
    

    Also, as per documentation, the HTTP_PROXY setting is accepted by LWP::UserAgent (the primary HTTP client used by the cpan command line utility), while HTTPS_PROXY is supported by curl (fallback of cpan when LWP fails). See the LWP::UserAgent docs and the curl docs.

    Hence HTTP_PROXY/HTTPS_PROXY should be the common environment variables that are supported by all CPAN clients.