Hi,
I am trying to import a feed from a website that requires the User-Agent not be empty/null. I noticed that whenever the get request is made from https://git.drupalcode.org/project/feeds/-/blob/8.x-3.x/src/Feeds/Fetche... the User-Agent is empty. This could be GuzzleHttp issue with this function https://github.com/guzzle/guzzle/blob/6.5/src/Client.php#L287 but I didn't find any issues calling it out there so I am starting here.
I am suggesting for now as a workaround to add the User-Agent to the get function by getting the default from GuzzleHttp client.
Attaching the patch in a new comment. Any other suggestions?
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | missingUserAgent-3159688-7.patch | 786 bytes | dmundra |
Issue fork feeds-3159688
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
dmundraAttaching patch.
Comment #3
jamesdixon commentedI see what you're going for there.
@megachriz: I don't think it would hurt to add user agent here if it were configured, what do you think?
Comment #4
dmundraThanks.
Some more background. I did figure out that a WordPress vendor was blocking User-Agent with the string 'PHP/' in it. I am working with them to find out why they are doing that.
The generated User-Agent that is getting deleted will be like 'Drupal/8.9 (+https://www.drupal.org/) GuzzleHttp/6.5.5 curl/7.64.0 PHP/7.2.27' (from https://git.drupalcode.org/project/drupal/-/blob/8.9.x/core/lib/Drupal/C...)
Comment #5
irinaz commented@dmundra, thanks for putting together this patch. I am testing and still getting error - is there way to see which user agent is added by this patch? thanks in advance.
Comment #6
andypostHaving a code comment explaining why only user-agent headers added would be great
Moreover not clear why
is_array()used here because headers are always defined via\Drupal\Core\Http\ClientFactory::fromOptions()https://git.drupalcode.org/project/drupal/-/blob/8.9.x/core/lib/Drupal/C...Comment #7
dmundra@irinaz here is an example of the User-Agent but it will depend on your version of the site and what server it is running on:
Drupal/9.1.0 (+https://www.drupal.org/) GuzzleHttp/6.5.5 curl/7.64.0 PHP/7.4.13
@andypost
Adding an updated patch with a comment and switched from is_array to isset() (which is probably what I was wanting to do).
Comment #8
andypostThank you, looks great 👍
Does it make sense to allow more headers?
Comment #9
dmundra@andypost, I think it would be beneficial to even allow customization of the headers including user-agent.
Comment #10
megachrizWe could add a field for setting additional headers in the Feeds UI. Are extra headers to be set usually static values? Or is it more common that they depend on other data, like the current date for example? Maybe the option for setting extra headers should be handled in an other issue.
Comment #11
dmundra@megachriz agreed that setting extra headers should be handled in another issue that can cover the complexity. Following Postman app example it could be static or dynamic. Maybe an API hook would be beneficial for those who want to provide dynamic headers but they can also just extend the class. That is my two cents.
Comment #12
andypostI bet http-client should allow to hook-in and customize headers
Quickly skimmed and found https://www.drupal.org/docs/8/modules/http-client-manager/the-handler-stack
Comment #13
dmundraGood find @andypost.
Comment #14
irinaz commentedComment #16
megachrizI tried to reproduce the issue about no user agent being sent, but in my case an user agent is being sent even without the patch. But apparently, there is a situation where this doesn't happen and it doesn't look like the patch does any harm either, so committed #7 - with coding standards fixed.
Comment #18
megachrizGuzzleHttp decided to deprecate the
getConfig()and it looks there is no easy replacement for it: https://github.com/guzzle/guzzle/issues/3114That means I either have to remove this feature, find another way to implement it or ignore the deprecation warning for now. Ignoring it could mean that at some point in the future this feature might stop working.
Since no test coverage for this was added, it will be harder to try to find a replacement for this. Also because in #16 I said I wasn't able to reproduce the bug.
@dmundra, @andypost
Can you help with this?
Comment #20
megachrizMR 182 is merged manually.
Since this issue is now no longer fixed, I reopen it.
@dmundra said the following about this issue in Slack:
See also https://drupal.slack.com/archives/C033S2JUMLJ/p1720346469627799
Comment #22
dmundraSo I think this is no longer an issue and so no fix is needed. I tested with a new Drupal site and the latests feeds branch and the requests working to even the site I had an issue with. So I think this should be closed.