From a332765a9be9cf429f2b72eb4f2f69b20f6e7313 Mon Sep 17 00:00:00 2001 From: scottmotte Date: Tue, 7 Jan 2014 14:32:51 -0800 Subject: [PATCH 1/2] Minor spelling fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4043a6c..2a974f1 100644 --- a/README.md +++ b/README.md @@ -152,7 +152,7 @@ Unirest::clearDefaultHeaders(); You can explicitly enable or disable SSL certificate validation when consuming an SSL protected endpoint: ```php -Unirest::verifiyPeer(false); // Disables SSL cert validation +Unirest::verifyPeer(false); // Disables SSL cert validation ``` By default is `true`. From 0fe3d04e215f07d3b3698f16605ee0b6a1aeb576 Mon Sep 17 00:00:00 2001 From: scottmotte Date: Thu, 27 Mar 2014 10:47:09 -0700 Subject: [PATCH 2/2] Fixes failing spec around CurlFile in 5.5 php and also adds additional spec --- lib/Unirest/Unirest.php | 6 +++--- test/Unirest/UnirestTest.php | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/lib/Unirest/Unirest.php b/lib/Unirest/Unirest.php index f190b25..2229779 100644 --- a/lib/Unirest/Unirest.php +++ b/lib/Unirest/Unirest.php @@ -133,7 +133,7 @@ class Unirest * This function is useful for serializing multidimensional arrays, and avoid getting * the "Array to string conversion" notice */ - private static function http_build_query_for_curl($arrays, &$new = array(), $prefix = null) + public static function http_build_query_for_curl($arrays, &$new = array(), $prefix = null) { if (is_object($arrays)) { $arrays = get_object_vars($arrays); @@ -141,7 +141,7 @@ class Unirest foreach ($arrays AS $key => $value) { $k = isset($prefix) ? $prefix . '[' . $key . ']' : $key; - if (is_array($value) OR is_object($value)) { + if (!$value instanceof CURLFile AND (is_array($value) OR is_object($value))) { Unirest::http_build_query_for_curl($value, $new, $k); } else { $new[$k] = $value; @@ -316,4 +316,4 @@ function is_hex($hex) return ctype_xdigit($hex); } -?> \ No newline at end of file +?> diff --git a/test/Unirest/UnirestTest.php b/test/Unirest/UnirestTest.php index 6157f20..188fa85 100644 --- a/test/Unirest/UnirestTest.php +++ b/test/Unirest/UnirestTest.php @@ -203,7 +203,24 @@ class UnirestTest extends UnitTestCase $form = $response->body->form; $this->assertEqual("Mark", $form->name); } - + + public function testUploadIfFilePartOfData() + { + $response = Unirest::post("http://httpbin.org/post", array( + "Accept" => "application/json" + ), array( + "name" => "Mark", + "files[owl.gif]" => Unirest::file(dirname(__FILE__) . "/test_upload.txt") + )); + $this->assertEqual(200, $response->code); + + //$files = $response->body->files; + //$this->assertEqual("This is a test", $files->file); + + $form = $response->body->form; + $this->assertEqual("Mark", $form->name); + } + public function testPostMultidimensionalArray() { $response = Unirest::post("http://httpbin.org/post", array( @@ -342,5 +359,16 @@ class UnirestTest extends UnitTestCase $headers = $response->body->headers; $this->assertEqual("ciao", $headers->{'User-Agent'}); } - -} \ No newline at end of file + + public function testHttpBuildQueryWhenCurlFile() + { + $file = Unirest::file(dirname(__FILE__) . "/test_upload.txt"); + $body = array( + "to" => "mail@mailinator.com", + "from" => "mail@mailinator.com", + "file" => $file + ); + Unirest::http_build_query_for_curl($body, $postBody); + $this->assertEqual($postBody['file'], $file); + } +}