Welcome Guest, Not a member yet? Register   Sign In
CURL and clearing query after send


I'm using `curlrequest` but I found a problem. When we use a service `curlrequest` we could set an option for the client. For API which I'm trying to call auth is passed as a query params so I set options like this:

PHP Code:
        $client = \Config\Services::curlrequest([
            'baseURI' => 'API',
            'query' => [
                'key' => 'key',
                'token' => 'token'

and everything works ok for the first request but next don't get that `query` option because it's cleared in `system/HTTP/CURLRequest.php:429`. It's this part of code:

PHP Code:
    public function send(string $methodstring $url)
// Reset our curl options so we're on a fresh slate.
$curl_options = [];

        if (! empty(
$this->config['query']) && is_array($this->config['query']))
// This is likely too naive a solution.
            // Should look into handling when $url already
            // has query vars on it.
$url .= '?' http_build_query($this->config['query']);

and I'm not sure if it's proper behavior?

What would happen if the options were not cleared and you wanted to do another request that was different from the previous one. In that case, you would need to clear out all the options and start again. This seems like a clean deterministic way of making sure no old options sneak through to subsequent queries.

What behaviour would you like to see and how would it work for all cases?

(This post was last modified: 08-27-2020, 05:16 AM by Michal_PB1.)

I think if someone sets a new `query` option then previously added query should be overridden. The second resolution of that problem could be a new property for setting a global `query` for the client.

For now, it is a bit problematic to pass these parameters to each curl request instead of passing the configured client.


The best solution for that probably could be a new type for auth

I can see the value of having a global set of options and a per request set of options and then merging them into the curl request when it is executed.

That might be a good thing to mention in the Feature Request forum.

Theme © iAndrew 2016 - Forum software by © MyBB