Ability to add additional http headers to get request

Created on 29 July 2019, about 6 years ago
Updated 5 February 2023, over 2 years ago

I have a couple of feeds that I need to authenticate first with a client ID/secret combo. I was able to include these in the HttpFetcher get function:

$options[RequestOptions::HEADERS]['client_id'] = 'abcdefghij';
$options[RequestOptions::HEADERS]['client_secret'] = '1234567890';

For my use case, storing here would be OK because all of the feeds would need this. I could also see this as part of the Feed content Import Options. Or maybe there's a more elegant solution that I'm missing. I thought I'd post in case this would be useful to others.

Feature request
Status

Active

Version

3.0

Component

Code

Created by

🇺🇸United States bwoods

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇮🇹Italy kopeboy Milan

    Is there a pluggable/configurable solution yet?

  • First commit to issue fork.
  • Provided a new configuration option for specifying HTTP headers that may be specified on the Feed type or individual Feed entity level.

  • Pipeline finished with Success
    3 months ago
    Total: 477s
    #525420
  • 🇮🇹Italy kopeboy Milan

    Even if I don't have a real URL to test now, this seems working. Thanks!

  • 🇳🇱Netherlands megachriz

    Nice work so far! I've some remarks:

    1. I think that we should avoid <code> tags in translatable strings.
    2. On the feed form, it would be useful to see what the default configured headers are, maybe as a placeholder for the textarea.
    3. I think it would be better if the configured http headers are saved as an array instead of a string. For both the feed type and the feed.
    4. Needs tests.

    Test coverage

    • Functional test for configuring a feed type with http headers:
      • Assert that misconfigured headers result into a validation error.
      • Assert that empty lines are ignored and not saved as configuration.
      • Assert that configured headers are saved.
    • Functional test for configuring a feed with http headers override: test the same things as for configuring a feed type with http headers.
    • Unit test for asserting the expected headers when they are configured on the feed type.
    • Unit test for asserting the expected headers when they are configured on the feed.
    • Unit test for asserting the expected headers when they are configured on both the feed type and the feed.
  • Status changed to Needs review 21 days ago
  • 🇳🇱Netherlands megachriz

    I've addressed all remarks of mine from #9.

    Most important changes:

    • The http_headers setting is now saved as array instead of a string. So if you had used a previous diff, you would need to reconfigure your feed types/feeds. I do have made it so that the forms still work if the setting was saved as string.
    • There is now test coverage for this feature.
Production build 0.71.5 2024