This repository was archived by the owner on Jun 27, 2018. It is now read-only.
Added support for using custom HTTP clients#12
Open
jeremeamia wants to merge 1 commit into1EdTech:masterfrom
Open
Added support for using custom HTTP clients#12jeremeamia wants to merge 1 commit into1EdTech:masterfrom
jeremeamia wants to merge 1 commit into1EdTech:masterfrom
Conversation
jeremeamia
commented
Nov 11, 2016
| if ($message->ok) { | ||
| $chResp = str_replace("\r\n", "\n", $chResp); | ||
| $chRespSplit = explode("\n\n", $chResp, 2); | ||
| if ((count($chRespSplit) > 1) && (substr($chRespSplit[1], 0, 5) === 'HTTP/')) { |
Author
There was a problem hiding this comment.
Why was this behavior originally included?
Contributor
|
Thanks very much for working on this. It will help Moodle to better control over the LTI requests and give it the same checks as we have for other HTTP requests. If I get spare time I'll see if I will take a closer look |
Author
|
@spvickers Let me know what your thoughts are here and if you'd like to talk more about it. |
…way. Also added a test suite that covers the HTTPMessage and client classes.
75ec937 to
6c5a558
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I have added support for using custom HTTP clients in a backward-compatible way. The way this works, is that I made an HTTP
Clientinterface, with two implementations:CurlClientandStreamClient. The code for these implementations was refactored out of the originalHTTPMessage::send()method.You can use the new
HTTPMessage::setHttpClient()method to inject any HTTP client that conforms to the aforementioned interface. If none is injected, theHTTPMessagechooses one for you, using a similar strategy found in the original class.I also improved the code for the
fopen-based client, since it was not handling the response data properly like cURL code was doing.Additional Changes
.editorconfigwith a basic PSR-compliant configuration.gitignorefor excluding composer files that should not be committedphpunit.xml.distfor configuring PHPUnit. To override this file in your own development environment, you can copy it tophpunit.xmland make changes.HTTPMessage,CurlClient, andStreamClientclasses.curl_execandfopenis not easy. I opted to use PHP's built-in server (with an object-oriented wrapper) to respond with canned results that I can test against. This setup worked fine in my Mac-based PHP environment, but I'm not sure how well it works in non-bash environments. Can be changed in the future, but wanted to be thorough on the tests.Test Output