Skip to content

Commit

Permalink
Merge pull request #1498 from natanfelles/curl_helpers
Browse files Browse the repository at this point in the history
Add CURLRequest helper methods
  • Loading branch information
jim-parry authored Nov 29, 2018
2 parents 633e291 + 42605e9 commit e7edcce
Show file tree
Hide file tree
Showing 2 changed files with 178 additions and 42 deletions.
64 changes: 62 additions & 2 deletions system/HTTP/CURLRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@
* A lightweight HTTP client for sending synchronous HTTP requests
* via cURL.
*
* @todo Add a few helpers for dealing with JSON, forms, files, etc.
*
* @package CodeIgniter\HTTP
*/
class CURLRequest extends Request
Expand Down Expand Up @@ -267,6 +265,68 @@ public function put(string $url, array $options = []): ResponseInterface

//--------------------------------------------------------------------

/**
* Set the HTTP Authentication.
*
* @param string $username
* @param string $password
* @param string $type basic or digest
*
* @return $this
*/
public function setAuth(string $username, string $password, string $type = 'basic')
{
$this->config['auth'] = [
$username,
$password,
$type,
];

return $this;
}

//--------------------------------------------------------------------

/**
* Set form data to be sent.
*
* @param array $params
* @param boolean $multipart Set TRUE if you are sending CURLFiles
*
* @return $this
*/
public function setForm(array $params, bool $multipart = false)
{
if ($multipart)
{
$this->config['multipart'] = $params;
}
else
{
$this->config['form_params'] = $params;
}

return $this;
}

//--------------------------------------------------------------------

/**
* Set JSON data to be sent.
*
* @param mixed $data
*
* @return $this
*/
public function setJSON($data)
{
$this->config['json'] = $data;

return $this;
}

//--------------------------------------------------------------------

/**
* Sets the correct settings based on the options array
* passed in.
Expand Down
Loading

0 comments on commit e7edcce

Please sign in to comment.