2

The following curl command works as expected:

$ curl -H @- -vso/dev/null http://www.example.com <<<"Foo:Bar"
* Rebuilt URL to: http://www.example.com/
...
> Accept: */*
> Foo:Bar
> 
< HTTP/1.1 200 OK
...

since I can see my custom header (Foo:Bar), but it doesn't work when running via ssh:

$ ssh user@localhost curl -H @- -vso/dev/null http://www.example.com <<<"Foo:Bar"
* Rebuilt URL to: http://www.example.com/
...
> Accept: */*
> 
< HTTP/1.1 200 OK
...

I can confirm that the stdin works on the remote by:

$ ssh user@localhost cat <<<"Foo:Bar"
Foo:Bar

My goal is to pass the headers from stdin or local file (not from the variable) into remote curl.

And I'm not quite sure why the above doesn't work.

1 Answer 1

2

The argument in @filename style for -H has been added in 7.55.0 (man curl).

-H/--header <header/@file>

Starting in 7.55.0, this option can take an argument in @filename style, which then adds a header for each line in the input file. Using @- will make curl read the header file from stdin.


The problem with ssh happened because older curl version was used.

So basically two different versions of curl were involved.

$ which curl && curl --version
/usr/local/bin/curl
curl 7.59.0 (x86_64-apple-darwin17.3.0) libcurl/7.59.0 OpenSSL/1.0.2o zlib/1.2.11 libidn2/2.0.4
$ ssh user@localhost 'which curl && curl --version'
/usr/bin/curl
curl 7.54.0 (x86_64-apple-darwin17.0) libcurl/7.54.0 LibreSSL/2.0.20 zlib/1.2.11 nghttp2/1.24.0

So hardcoding the path to newer /usr/local/bin/curl (v7.59/OpenSSL) it seems to work fine:

$ ssh user@localhost /usr/local/bin/curl -H @- -vso/dev/null http://www.example.com <<<"Foo:Bar"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .