-
Notifications
You must be signed in to change notification settings - Fork 327
Curl backend should set user agent #2562
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
Conversation
| int sttp_curl_setopt_pointer(CURL *curl, CURLoption opt, void* arg) {return curl_easy_setopt(curl, opt, arg); } | ||
|
|
||
| const char* sttp_curl_get_version() { | ||
| return curl_version_info(CURLVERSION_NOW)->version; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a FFI method instead of defining the full struct for what curl_version_info returns.
| } | ||
| } | ||
|
|
||
| private lazy val curlUserAgent = "sttp-curl/" + fromCString(CCurl.getVersion()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sttp-curl/8.7.1 is what I get on my machine
Right({
"method": "GET",
"protocol": "https",
"host": "echo.free.beeceptor.com",
"path": "/",
"ip": "195.26.120.14:57556",
"headers": {
"Host": "echo.free.beeceptor.com",
"User-Agent": "sttp-curl/8.7.1",
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate"
},
"parsedQueryParams": {}
})
| curl.option( | ||
| UserAgent, | ||
| userAgent | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's a reasonable default to always set the user agent – user still can circumvent that by using an empty string in the headers.
|
Looks good, thanks! |
|
@adamw would it be possible to get a patch release? I see 4.0.5 was cutoff just before this commit |
|
@keynmol yes, sorry, I forgot to push the tag 🤦 doing that now |
This PR adds a reasonable default user agent for the curl native backend, because it's a better default behaviour, see explanation below.
Consider this simple usage of sttp:
Notice how on JVM,
User-Agentis added automatically by the client implementation.Now, if you run this on Native:
There is no user agent, because libcurl does not add it by default.
Apparently there are some hosts that prohibit empty user agents – one of them being Scaladex!
Lack of user agent on native prevents parity between JVM and Native usage of sttp.