Skip to content

Adds switchable http clients with configuration options #290

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

Merged
merged 1 commit into from
Mar 8, 2017

Conversation

montymxb
Copy link
Contributor

@montymxb montymxb commented Feb 25, 2017

This is for #59, dating back to late 2014. It addresses the issue that not everyone can use the same transport layer to power the sdk. For example curl may not be available (or discouraged) over an alternative implementation. One such case would be the http api on wordpress. In a general sense environments where the user does not have control over their php installation should be given a variety of http clients to choose from.

This introduces pluggable transport layers, where the underlying http client may be changed using either one of the provided clients or even a custom user implementation. This PR provides two such clients, ParseCurlHttpClient and ParseStreamHttpClient, where the former is the default.

Setting a client can be achieved via the newly added ParseClient::setHttpClient as follows:

// set a stream client instead of the default cURL client
ParseClient::setHttpClient(new ParseStreamHttpClient());

This is closely related to facebook's implementation in their php graph sdk. To that end there is a ParseHttpable interface which can be implemented to provide additional transport layers. Http clients can implement this to provide additional choices, such as in the case of wordpress (but not included in this PR).

Additionally in some shared hosting implementations it may be required to provide an alternative CA bundle, which if not present could lead to an inability to verify peer's certificates. To account for this I have added ParseClient::setCAFile and updated the README with an appropriate usage (including a brief explanation of where to obtain a bundle). I have seen some instances of individuals attempting to disable peer verification to bypass such issues. This should incentivize trying to set an alternative CA bundle instead over disabling verification altogether.

The README and tests have been updated to document and cover this newly added functionality.

@montymxb montymxb merged commit cd27a86 into parse-community:master Mar 8, 2017
@montymxb montymxb deleted the transport-layers branch March 8, 2017 03:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant