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

In a config file, headers are not handled the same as on the CLI (header not sent) #12409

Closed
Jiehong opened this issue Nov 27, 2023 · 3 comments
Labels
cmdline tool not-a-bug This is not a bug in curl

Comments

@Jiehong
Copy link

Jiehong commented Nov 27, 2023

I did this

When using --config, and with the cli, I get different results.

Using the CLI

$ curl -v --request POST --header 'Authorization: Bearer xxxx' --url https://example.com

I get the following output:

*   Trying 93.184.216.34:443...
* Connected to example.com (93.184.216.34) port 443
(...)
> POST / HTTP/1.1
> Host: example.com
> User-Agent: curl/8.4.0
> Accept: */*
> Authorization: Bearer xxxx
>
(...)
< HTTP/1.1 200 OK

Using a config file

With the following config file named test.curl:

request = POST
header = Authorization: Bearer xxxx
url = https://example.com

And then running it:

$ curl -v --config test.curl
Warning: ./test.curl:2: warning: 'header' uses unquoted whitespace in the line
Warning: that may cause side-effects
*   Trying 93.184.216.34:443...
* Connected to example.com (93.184.216.34) port 443
(...)
> POST / HTTP/1.1
> Host: example.com
> User-Agent: curl/8.4.0
> Accept: */*
>
(...)
< HTTP/1.1 200 OK

I expected the following

Using the config file, I expected the exact same as the CLI output.

In particular, the Authorization header should be sent as described.

Note that changing the header line in the config file to:

header = 'Authorization: Bearer xxx'

Does not remove the curl warning, and still does not send that header.

By the way, I realise it should be better to just use oauth2-bearer instead of creating the header by hand, but I have the same issue with any other headers.

curl/libcurl version

curl 8.4.0 (aarch64-apple-darwin22.6.0) libcurl/8.4.0 (SecureTransport) OpenSSL/3.1.4 zlib/1.2.11 brotli/1.1.0 zstd/1.5.5 libidn2/2.3.4 libssh2/1.11.0 nghttp2/1.58.0 librtmp/2.3 OpenLDAP/2.6.6
Release-Date: 2023-10-11
Protocols: dict file ftp ftps gopher gophers http https imap imaps ldap ldaps mqtt pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS brotli GSS-API HSTS HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz MultiSSL NTLM SPNEGO SSL threadsafe TLS-SRP UnixSockets zstd

operating system

Darwin my-name 22.6.0 Darwin Kernel Version 22.6.0: Thu Nov 2 07:43:25 PDT 2023; root:xnu-8796.141.3.701.17~6/RELEASE_ARM64_T6020 arm64

@bagder
Copy link
Member

bagder commented Nov 27, 2023

Let me quote a relevant part of the man page for the --config option:

If the parameter contains whitespace or starts with a colon (:) or equals sign (=), it must be specified enclosed within double quotes (").

@bagder bagder added the not-a-bug This is not a bug in curl label Nov 27, 2023
@Jiehong
Copy link
Author

Jiehong commented Nov 27, 2023

@bagder : I was reading https://everything.curl.dev/cmdline/configfile, and even saw that section, but used single quotes instead of double quotes.

Not entirely sure why. I guess the warning message was using single quotes, and I didn't think well enough:

Warning: ./test.curl:2: warning: 'header' uses unquoted whitespace in the line

Perhaps the warning message could be extended a little bit with: "header" uses unquoted whitespace in the line. Consider quoting its value with double quotes. ?

Thank you for answering so fast!

bagder added a commit that referenced this issue Nov 27, 2023
When the config file parser detects a word that *probably* should be
quoted, mention double-quotes as a possible remedy.

Test 459 verifies.

Proposed-by: Jiehong on github
Fixes #12409
@bagder bagder closed this as completed in 97ccc44 Nov 27, 2023
@Jiehong
Copy link
Author

Jiehong commented Nov 27, 2023

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cmdline tool not-a-bug This is not a bug in curl
Development

Successfully merging a pull request may close this issue.

2 participants