Skip to content

Commit

Permalink
Issue 46 (#55)
Browse files Browse the repository at this point in the history
* CurlFile fix

This is not tested, but we are facing the same problem with CurlFile Uploads (#46) - This *should* do the trick.

* Update README.md

* cs fix
  • Loading branch information
nadar authored and amouhzi committed Nov 17, 2018
1 parent d2f085d commit 63ef7e7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 21 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# PHP Curl Class

[![Build Status](https://travis-ci.org/php-mod/curl.svg?branch=master)](https://travis-ci.org/php-mod/curl)

This library provides an object-oriented wrapper of the PHP cURL extension.

If you have questions or problems with installation or usage [create an Issue](https://github.com/php-mod/curl/issues).
Expand Down Expand Up @@ -115,7 +117,7 @@ fclose($file_handle);
```


## Testing
## Testing

In order to test the library:

Expand Down
52 changes: 32 additions & 20 deletions src/Curl/Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ public function addResponseHeaderLine($curl, $header_line)

if ($trimmed_header === "") {
$this->response_header_continue = false;
} else if (strtolower($trimmed_header) === 'http/1.1 100 continue') {
} elseif (strtolower($trimmed_header) === 'http/1.1 100 continue') {
$this->response_header_continue = true;
} else if (!$this->response_header_continue) {
} elseif (!$this->response_header_continue) {
$this->response_headers[] = $trimmed_header;
}

Expand Down Expand Up @@ -232,7 +232,19 @@ protected function preparePayload($data)
$this->setOpt(CURLOPT_POST, true);

if (is_array($data) || is_object($data)) {
$data = http_build_query($data);
$skip = false;
foreach ($data as $key => $value) {
// If a value is an instance of CurlFile skip the http_build_query
// see issue https://github.com/php-mod/curl/issues/46
// suggestion from: https://stackoverflow.com/a/36603038/4611030
if ($value instanceof \CurlFile) {
$skip = true;
}
}

if (!$skip) {
$data = http_build_query($data);
}
}

$this->setOpt(CURLOPT_POSTFIELDS, $data);
Expand Down Expand Up @@ -499,28 +511,28 @@ public function setOpt($option, $value)
return curl_setopt($this->curl, $option, $value);
}

/**
* Get customized curl options.
*
* To see a full list of options: http://php.net/curl_getinfo
*
* @see http://php.net/curl_getinfo
*
* @param int $option The curl option constante e.g. `CURLOPT_AUTOREFERER`, `CURLOPT_COOKIESESSION`
* @param mixed $value The value to check for the given $option
*/
/**
* Get customized curl options.
*
* To see a full list of options: http://php.net/curl_getinfo
*
* @see http://php.net/curl_getinfo
*
* @param int $option The curl option constante e.g. `CURLOPT_AUTOREFERER`, `CURLOPT_COOKIESESSION`
* @param mixed $value The value to check for the given $option
*/
public function getOpt($option)
{
return curl_getinfo($this->curl, $option);
}

/**
* Return the endpoint set for curl
*
* @see http://php.net/curl_getinfo
*
* @return string of endpoint
*/
/**
* Return the endpoint set for curl
*
* @see http://php.net/curl_getinfo
*
* @return string of endpoint
*/
public function getEndpoint()
{
return $this->getOpt(CURLINFO_EFFECTIVE_URL);
Expand Down

0 comments on commit 63ef7e7

Please sign in to comment.