Change User-Agent in GuzzleHttp

Jonathan Gilpin

New Member
hello, I've just upgraded from Mailwizz 1 to Mailwizz 2 and suddenly importing a URL has stopped working with a 401 Gone Error.

I believe this is down to the UserAgent being blocked from our server to stop bot traffic.

I am looking how to change the User-Agent of Guzzle in Mailwizz 2 so that our server works fine. As the url works fine in Fetch and Wget but not Curl or Guzzle for some reason, can anyone tell me which part of the code to find the Guzzle call for Importing a URL OR if its possible to overwrite the user agent in the main options file?

Any help appreciated...
 
Currently there is no way to modify the guzzle client in any way BUT from the next release, I have added a few hooks and new classes and functions to make this easier, so after releasing v2.7.8 you should be able to add a new hook like:
PHP:
<?php
    // apps/init-custom.php
    hooks()->addFilter('http_client_maker_make_client_user_agent', function() {
        return 'My User Agent';
    });
(you can add this code by now, it will take effect after release only)

Meanwhile, your only option is to open /apps/common/models/ListUrlImport.php and look for
Code:
(new GuzzleHttp\Client())
which is in two places, and modify it like:
PHP:
(new GuzzleHttp\Client([
    'headers' => [
        'User-Agent' => 'My User Agent',
    ]
]))
 
Back
Top