mpratt / Embera

A Oembed consumer library, that gives you information about urls. It helps you replace urls to youtube or vimeo for example, with their html embed code. It has advanced features like offline support, responsive embeds and caching support.
MIT License
335 stars 59 forks source link

Support custom request headers #89

Closed uxweb closed 3 years ago

uxweb commented 3 years ago

Hello!

I was wondering if it is possible to send custom headers when using the $embera->getUrlData()?

I'm having an issue with private videos from Vimeo, the endpoint returns a different response for this kind of videos and the thumbnail fields are not included.

According to the Vimeo docs a Referer header must be sent with the whitelisted domain so it can return the private metadata which includes the thumbnail data.

Thank you!

mpratt commented 3 years ago

Hi @uxweb

On Version 2.0.21 you can use the referer configuration option.

$embera = new Embera([
    'referer' => 'https://referrer.com/'
]);

This will set the referer for all http requests.

On the other hand, you could write a new class implementing the Embera\Http\HttpClientInterface interface and setting the referer for example.

Once you have the class you only need to inject it to the constructor.

$embera = new Embera($config, new DefaultProviderCollection($config), new YourImplementationOfHttpClient());

Let me know if this helps.

uxweb commented 3 years ago

Hey @mpratt

Much appreciated for your response. Setting the referer option when creating a new Embera worked just fine!

Thank you for taking the time to answer my question.