Skip to content
This repository has been archived by the owner on Jan 24, 2020. It is now read-only.

Allow setting User-Agent #1

Closed
asbjornu opened this issue Apr 29, 2016 · 1 comment
Closed

Allow setting User-Agent #1

asbjornu opened this issue Apr 29, 2016 · 1 comment

Comments

@asbjornu
Copy link
Contributor

To be able to distinguish different implementaions of this library from one another, it should be possible to set a $userAgent parameter that is used in a User-Agent header which is sent every HTTP request against PayEx' API.

It should be possible to set custom HTTP headers in the stream_context key of the options array parameter of the SoapClient constructor:

// We should of course figure out which version this library as well as PHP we're running dynamically and not hard coded liket his:
$userAgent = $this->_userAgent . 'PayEx.Ecommerce.Php/1.0.2 php/7.0.6';
// The stream_context needs to include the 'ssl' key if 'ssl_verify' is set to true.
$context = stream_context_create(array('http' => array('header' => "User-Agent: $userAgent"));
$options = array('stream_context' => $context);
$client = new \SoapClient($wsdl, $options);

Since the stream_context is already initialized in __construct(), the header key can just be added there along with the already existing ssl key being set if ssl_verify is true.

The format of the User-Agent header should be as per RFC 7231 section 5.5.3. We should include as much information in the header as possible, such as the version of PHP and any library relevant to the HTTP request. Simply put, it should look something like this:

User-Agent: PayEx.Magento/1.2.3 PayEx.Ecommerce.Php/1.0.2 Magento/1.9.2.4 PHP/7.0.6
@aait
Copy link
Collaborator

aait commented Jul 21, 2016

Solved in 3042b84

@aait aait closed this as completed Jul 21, 2016
aait pushed a commit that referenced this issue May 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants