いや、ホント、man読めって話しと、思い込み危険って話しなんですけど。
curlのバージョンは以下の通り。
$ curl -V
curl 7.51.0 (x86_64-apple-darwin16.0) libcurl/7.51.0 SecureTransport zlib/1.2.8
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: AsynchDNS IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz UnixSockets
curlには7.19.4以降--noproxy
というオプションが追加されています。
manを読むと、proxyを使いたくない宛先ホスト名をカンマ区切りで並べろということです。
--noproxy <no-proxy-list>
Comma-separated list of hosts which do not use a proxy, if one is specified. The only wildcard is a
single * character, which matches all hosts, and effectively disables the proxy. Each name in this
list is matched as either a domain which contains the hostname, or the hostname itself. For example,
local.com would match local.com, local.com:80, and www.local.com, but not www.notlocal.com. (Added
in 7.19.4).
オプション名だけ見て↓な感じでcurlぶん投げてて、そりゃ届かんよなって感じになってました…
$ curl --noproxy -i -X POST -H "Content-Type: application/json" http://example.com/users -d @user.json
以下のように、proxyを通したくないホスト名を指定するのが正しいです。
$ curl --noproxy example.com -i -X POST -H "Content-Type: application/json" http://example.com/users -d @user.json
ちなみに7.53.0からは、空文字(""
)を指定することで、環境変数に設定したno_proxy
を打ち消すこともできるようになる(まだリリースされていないはず?)みたいです。
--noproxy <no-proxy-list>
Comma-separated list of hosts which do not use a proxy, if one is specified. The only wildcard is a single * character, which matches all hosts, and effectively disables the proxy. Each name in this list is matched as either a domain which contains the hostname, or the hostname itself. For example, local.com would match local.com, local.com:80, and www.local.com, but not www.notlocal.com.
Since 7.53.0, This option overrides the environment variables that disable the proxy. If there's an environment variable disabling a proxy, you can set noproxy list to "" to override it.
Added in 7.19.4.
おまけ
常にproxyを通さないで良い場合は環境変数no_proxy
に設定すれば良いわけですが、172.19.*
といった形でワイルドカード指定してもうまく動いてくれません。(ここもボケていて、ワイルドカード指定していて効いてませんでした…)