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
Fix/Rationalize transports #143
Conversation
@rmccue ping? |
I think @rmccue will want unit tests before considering a merge, as always :) |
Thank you @ozh :) I will add them in the next days! |
I'm currently adding tests but I can't get them passing for the master branch on my computer. Here, the PHPunit output: PHPUnit 4.6.4 by Sebastian Bergmann and contributors.
Configuration read from /home/gelo/Workspace/Rmccue/Requests/tests/phpunit.xml.dist
....FF....F....F...F..F........................................ 63 / 814 ( 7%)
............................................................... 126 / 814 ( 15%)
..................................................F...F....F... 189 / 814 ( 23%)
.F...F..F...................................................... 252 / 814 ( 30%)
............................................................... 315 / 814 ( 38%)
....................................F...F...................... 378 / 814 ( 46%)
............................................................... 441 / 814 ( 54%)
............................................................... 504 / 814 ( 61%)
............................................................... 567 / 814 ( 69%)
............................................................... 630 / 814 ( 77%)
............................................................... 693 / 814 ( 85%)
............................................................... 756 / 814 ( 92%)
..........................................................
Time: 6.9 minutes, Memory: 41.25Mb
There were 14 failures:
1) RequestsTest_Auth_Basic::testPOSTUsingInstantiation with data set #0 ('Requests_Transport_fsockopen')
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'test'
+''
/home/gelo/Workspace/Rmccue/Requests/tests/Auth/Basic.php:77
2) RequestsTest_Auth_Basic::testPOSTUsingInstantiation with data set #1 ('Requests_Transport_cURL')
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'test'
+''
/home/gelo/Workspace/Rmccue/Requests/tests/Auth/Basic.php:77
3) RequestsTest_Transport_cURL::testGETWithNestedData
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'http://httpbin.org/get?test=true&test2%5Btest3%5D=test&test2%5Btest4%5D=test-too'
+'http://httpbin.org/get?test=true&test2[test3]=test&test2[test4]=test-too'
/home/gelo/Workspace/Rmccue/Requests/tests/Transport/Base.php:71
4) RequestsTest_Transport_cURL::testRawPOST
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'test'
+''
/home/gelo/Workspace/Rmccue/Requests/tests/Transport/Base.php:119
5) RequestsTest_Transport_cURL::testRawPUT
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'test'
+''
/home/gelo/Workspace/Rmccue/Requests/tests/Transport/Base.php:164
6) RequestsTest_Transport_cURL::testRawPATCH
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'test'
+''
/home/gelo/Workspace/Rmccue/Requests/tests/Transport/Base.php:194
7) RequestsTest_Transport_cURL::testMultipleWithDifferingMethods
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'test'
+''
/home/gelo/Workspace/Rmccue/Requests/tests/Transport/Base.php:571
8) RequestsTest_Transport_cURL::testMultipleToFile
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'test'
+''
/home/gelo/Workspace/Rmccue/Requests/tests/Transport/Base.php:671
9) RequestsTest_Transport_fsockopen::testGETWithNestedData
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'http://httpbin.org/get?test=true&test2%5Btest3%5D=test&test2%5Btest4%5D=test-too'
+'http://httpbin.org/get?test=true&test2[test3]=test&test2[test4]=test-too'
/home/gelo/Workspace/Rmccue/Requests/tests/Transport/Base.php:71
10) RequestsTest_Transport_fsockopen::testRawPOST
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'test'
+''
/home/gelo/Workspace/Rmccue/Requests/tests/Transport/Base.php:119
11) RequestsTest_Transport_fsockopen::testRawPUT
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'test'
+''
/home/gelo/Workspace/Rmccue/Requests/tests/Transport/Base.php:164
12) RequestsTest_Transport_fsockopen::testRawPATCH
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'test'
+''
/home/gelo/Workspace/Rmccue/Requests/tests/Transport/Base.php:194
13) RequestsTest_Transport_fsockopen::testMultipleWithDifferingMethods
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'test'
+''
/home/gelo/Workspace/Rmccue/Requests/tests/Transport/Base.php:571
14) RequestsTest_Transport_fsockopen::testMultipleToFile
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'test'
+''
/home/gelo/Workspace/Rmccue/Requests/tests/Transport/Base.php:671
FAILURES!
Tests: 814, Assertions: 1219, Failures: 14. Majority of the failling tests are related to the data |
Yep, noticed the same on my computer, no idea why and honestly I didn't bother. When I submit a PR with new tests, I just make sure my new tests are OK 😄 |
Thanks for your feedback, I will then rely on travis to be sure my tests are OK :) |
Actually, I have started looking at it. The problem is that, IMHO, the tests here are doing it wrong: we're testing httpbin and the values it returns, not Requests. I suspect that this line explains the discrepancies |
Additionally, I'm not even sure what httpbin is supposed to return for instance with test |
Seems related to postmanlabs/httpbin#178 |
Tests added! Undortunatelly, httpbin does not allow me to test as much feature as I want. For example, http spec specifies that an OPTIONS request can have a body but httpbin does not deal with such case. Even worse, it does not deal with TRACE request at all. Feedbacks welcome! |
Thanks for the PR, and apologies for the delay in responding!
I think this may break backwards compatibility with people using hooks that occur between What would cause the handle to be closed? I'm assuming the main issue is reusing the transport?
I like the concept, but let's make the option a bit more generic. I'm thinking (The original reason we didn't support this was because RFC2616 didn't specify that DELETE et al could take a request body, and the general consensus was to treat them similar to GET requests. RFC7231 clarifies that it's allowed, so happy to add this.)
Good catch. Further comments inline as well. |
if ($options['data_as_query']) { | ||
$url = self::format_get($url, $data); | ||
$data = ''; | ||
} elseif (!is_string($data)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The elseif
should be on the next line after the closing brace
I have changed my approach to make it reusable without BC break :) Basically, the issue was the fp is initialized in the constructor and then closed with the first request. Instead of closing it for each request, I have closed it when the transport is destructed.
Done!
Done! Btw, also adding protocol version extraction for the response. ping @rmccue |
If all is fine, I will squash my commits before merging. |
ping @rmccue |
@egeloen Apologies for the delay. If anything, I'd actually prefer the commits split out and in separate pull requests, as it makes it easier to manage and merge parts as they're ready. I'm going to do a full review of this, but it'll also need updating from the latest master in any case. |
Hey!
This PR rationalizes/fixes some issues I encounter with the curl/fsockopen transports + add some new features.
Context
I'm currently integrating this library in an http adapter (See egeloen/ivory-http-adapter#80). This library has a pretty robust test suite which have spotted some issues. This PR tries to fix all of them :)
Issues
setup_handle
method which fixes the issue.DELETE
request but some service like AWS needs some extra info inDELETE
request which needs to be passed by message body. According to DELETE does not allow POST-style data #91, I have added thedata_as_query
option and updated the transport accordingly.New features
OPTIONS
andTRACE
http verbs.1.0
and1.1
protocol versions in request/response.Btw, this PR fixes #133, #137, #142 and #91.
Waiting your feedbacks!