Skip to content

No support for HTTP proxies #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
willemstuursma opened this issue Jul 11, 2017 · 8 comments
Closed

No support for HTTP proxies #48

willemstuursma opened this issue Jul 11, 2017 · 8 comments
Labels
Milestone

Comments

@willemstuursma
Copy link

We would like to connect to the MessageBird API using an HTTP proxy.

Unfortunately there is no option available to set this.

@samwierema
Copy link
Contributor

Hi @willemstuursma, thanks for opening an issue. I think we could potentially add this as an option and to use something like CURLOPT_PROXY to manage it.

We'll review this some more and see if we can change some code soon. Or, should you have the inclination, we'd love to see a pull request.

@CoonHouse
Copy link

Hello, I managed to successfully post messages to the Messagebird API from behind a proxy. I modified the "performHttpRequest" in "HttpClient.php" to let cUrl use the "CURLOPT_PROXY" option. The problem is that it seems I do not get the same response I would get when using no proxy. The "processRequest" in "Base.php" throws an error because the response is not valid JSON.

..../MessageBird/Resources/Base.php:163:Got an invalid JSON response from the server

When i dump the response, I get the following data:

HTTP/1.1 201 Created
Server: nginx
Date: Fri, 22 Sep 2017 08:00:23 GMT
Content-Type: application/json; charset=UTF-8
Content-Length: 674
Connection: keep-alive
Access-Control-Allow-Headers: Authorization, Content-Type
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, PUT, PATCH, DELETE
Access-Control-Allow-Credentials: true
Pragma: no-cache
Expires: 0
Cache-Control: must-revalidate, post-check=0, pre-check=0

Any idea how to fix this, or where to search?

Like I said, the messages are successfully posted and also texted to the mobile numbers. I'm only missing the correct response.

@samwierema
Copy link
Contributor

@CoonHouse could it be that the proxy is filtering the content when sending back the response? The headers you've sent seem to be good (and it even has Content-Length), but the body seems to be missing.

@Matthijsvdorp
Copy link

@samwierema I can imagine this is not really high on your list but I would like to use it behind a proxy as well. If there was some way to access the CURL handler before doing the requests everyone could just add their own configuration tweaks (i.e. SSL options, proxy, timeouts etc). That will solve more then this issue alone.

@CoonHouse
Copy link

@Matthijsvdorp, I have this working behind a proxy by modifying the source. I am not at the code right now, so I can not share my solution right now. And i made it work for my situation and did not test all other possible situations that might occur!! If you are interested, I will look into it and share you my modifications.

Best Regards,

Wilco

@fas3r
Copy link

fas3r commented Jan 13, 2018

Please do.

Thanks.

@Matthijsvdorp
Copy link

@CoonHouse I got it working as well but by changing a file in my vendor/ directory and that feels wrong. Would be nice to have a better solution available. I'll think about and try to PR something.

Matthijsvdorp pushed a commit to Matthijsvdorp/php-rest-api that referenced this issue Jan 15, 2018
epels added a commit that referenced this issue Jul 25, 2018
@epels epels added this to the v1.10.0 milestone Jul 25, 2018
@epels
Copy link
Contributor

epels commented Jul 25, 2018

Hi @willemstuursma, thanks for opening this issue - version 1.10.0 has just been released and you should now be able to use proxies with the MessageBird client.

HTTP options, and therefore proxies, can be set as follows:

$httpClient = new HttpClient(Client::endpoint);
$httpClient->addHttpOption(CURLOPT_PROXY, 'YOUR_PROXY');

$client = new Client('YOUR_ACCESS_KEY', $httpClient);

// Do something with $client...

Please do not hesitate to let me know if you have any questions about this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants