Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Curl should expand ~ and env vars in ~/.curlrc #2317

Closed
nagromc opened this issue Feb 16, 2018 · 4 comments
Closed

Curl should expand ~ and env vars in ~/.curlrc #2317

nagromc opened this issue Feb 16, 2018 · 4 comments

Comments

@nagromc
Copy link

nagromc commented Feb 16, 2018

I've read https://curl.haxx.se/docs/knownbugs.html, https://curl.haxx.se/docs/todo.html, and https://curl.haxx.se/docs/manpage.html. Maybe I'm missing something. If so, please excuse me.

I did this

$ echo "--config ~/.curlrc_local" > ~/.curlrc
$ cat ~/.curlrc
--config ~/.curlrc_local
$ echo "--head" > ~/.curlrc_local
$ cat ~/.curlrc_local
--head
$ curl https://example.org
Warning: error trying read config from the '~/.curlrc_local' file
<!doctype html>
<html>
<head>
    <title>Example Domain</title>
...

Curl does not expand ~ before running the command.

I've tried the following content in ~/.curlrc. None of them worked:

  • --config "~/.curlrc_local"
  • --config '~/.curlrc_local'
  • config = ~/.curlrc_local
  • config = "~/.curlrc_local"
  • config = '~/.curlrc_local'

Same if I try to replace ~ by $HOME.

I expected the following

I expected to have HTTP headers.

$ echo "--config ~/.curlrc_local" > ~/.curlrc
$ cat ~/.curlrc
--config ~/.curlrc_local
$ echo "--head" > ~/.curlrc_local
$ cat ~/.curlrc_local
--head
$ curl https://example.org
HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: max-age=604800
Content-Type: text/html
Date: Fri, 16 Feb 2018 18:03:08 GMT
Etag: "1541025663+gzip"
Expires: Fri, 23 Feb 2018 18:03:08 GMT
Last-Modified: Fri, 09 Aug 2013 23:54:35 GMT
Server: ECS (dca/2486)
X-Cache: HIT
Content-Length: 1270

When running the previous commands, I was expecting Curl to expand ~ into my home directory (here /home/morgan) to parse my custom configuration.

It does work well if:

  • I write directly in ~/.curlrc before, obviously:
    echo "--head" > ~/.curlrc
  • I "expand" manually:
    echo "--config /home/morgan/.curlrc_local" > ~/.curlrc
    echo "--head" > ~/.curlrc_local

curl/libcurl version

$ curl -V output
curl 7.55.1 (x86_64-pc-linux-gnu) libcurl/7.55.1 OpenSSL/1.0.2g zlib/1.2.11 libidn2/2.0.2 libpsl/0.18.0 (+libidn2/2.0.2) librtmp/2.3
Release-Date: 2017-08-14
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smb smbs smtp smtps telnet tftp 
Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP UnixSockets HTTPS-proxy PSL

operating system

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 17.10
Release:        17.10
Codename:       artful
$ uname -a
Linux xxx 4.13.0-32-generic #35-Ubuntu SMP Thu Jan 25 09:13:46 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
@bagder
Copy link
Member

bagder commented Feb 18, 2018

I think it's a fair suggestion. Since this is not a bug, we will probably close this issue soon unless someone wants to work on it at once. As explained here: https://curl.haxx.se/docs/bugs.html#TODO

@bagder
Copy link
Member

bagder commented Feb 19, 2018

A very easy work-around for you is to instead do:

$ echo "--config $HOME/.curlrc_local" > ~/.curlrc

... as then the shell will expand it for you to the current home directory. I'm not convinced this is a feature curl really must have.

@nagromc
Copy link
Author

nagromc commented Feb 20, 2018

Thanks for your feedback.

Of course, Curl doesn't need this feature. But it was quite confusing when I stumbled upon this issue, because Git, ssh, vim, tmux, and probably others support this.

The idea is to track my ~/.curlrc in my dotfiles repository with general options, and add an optional non-tracked ~/.curlrc_local for a specific machine. By making Curl expand ~, I can add the --insecure option to ~/.curlrc_local only at work (because of our very intrusive proxy). But at work, my username is not the same as at home. That's why I cannot use an absolute path.

So your following workaround would not work since my ~/.curlrc is tracked.

$ echo "--config $HOME/.curlrc_local" > ~/.curlrc

@bagder bagder closed this as completed in cf7b009 Mar 20, 2018
@bagder
Copy link
Member

bagder commented Mar 20, 2018

Added to the TODO file with the hopes that someone will work on it in a future.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

2 participants