Skip to content

Commit

Permalink
Added timeout feature and fixed digest auth bug
Browse files Browse the repository at this point in the history
 - FEATURE [I #77](#77) Convenience method for setting a timeout (seconds) `$req->timeoutIn(10);`
 - FIX [I #75](#75) [I #78](#78) Bug with checking if digest auth is being used.
 - Minor README tweaks to update version and reference new download url
  • Loading branch information
Nathan committed May 22, 2013
1 parent 816f511 commit 165f272
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Here's something to whet your appetite. Search the twitter API for tweets conta

## Phar

A [PHP Archive](http://php.net/manual/en/book.phar.php) (or .phar) file is available for [downloading](https://github.com/nategood/httpful/downloads). Simply [download](https://github.com/nategood/httpful/downloads) the .phar, drop it into your project, and include it like you would any other php file. _This method is ideal smaller projects, one off scripts, and quick API hacking_.
A [PHP Archive](http://php.net/manual/en/book.phar.php) (or .phar) file is available for [downloading](http://phphttpclient.com/httpful-0.2.4.phar). Simply [download](http://phphttpclient.com/httpful-0.2.4.phar) the .phar, drop it into your project, and include it like you would any other php file. _This method is ideal smaller projects, one off scripts, and quick API hacking_.

<?php
include('httpful.phar');
Expand Down Expand Up @@ -69,6 +69,11 @@ Httpful highly encourages sending in pull requests. When submitting a pull requ

# Changelog

## 0.2.4

- FEATURE [I #77](https://github.com/nategood/httpful/issues/77) Convenience method for setting a timeout (seconds) `$req->timeoutIn(10);`
- FIX [I #75](https://github.com/nategood/httpful/issues/75) [I #78](https://github.com/nategood/httpful/issues/78) Bug with checking if digest auth is being used.

## 0.2.3

- FIX Overriding default Mime Handlers
Expand Down
2 changes: 1 addition & 1 deletion src/Httpful/Httpful.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Httpful;

class Httpful {
const VERSION = '0.1.7';
const VERSION = '0.2.4';

private static $mimeRegistrar = array();
private static $default = null;
Expand Down
25 changes: 20 additions & 5 deletions src/Httpful/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ public function hasBasicAuth()
*/
public function hasDigestAuth()
{
return isset($this->password) && isset($this->username) && $this->additional_curl_opts['CURLOPT_HTTPAUTH'] = CURLAUTH_DIGEST;
}
return isset($this->password) && isset($this->username) && $this->additional_curl_opts[CURLOPT_HTTPAUTH] == CURLAUTH_DIGEST;
}

/**
* Specify a HTTP timeout
Expand Down Expand Up @@ -264,7 +264,7 @@ public function digestAuth($username, $password)
public function authenticateWithDigest($username, $password)
{
return $this->digestAuth($username, $password);
}
}

/**
* @return is this request setup for client side cert?
Expand All @@ -275,7 +275,7 @@ public function hasClientSideCert() {

/**
* Use Client Side Cert Authentication
* @return Response $this
* @return Request $this
* @param string $key file path to client key
* @param string $cert file path to client cert
* @param string $passphrase for client key
Expand All @@ -296,6 +296,21 @@ public function authenticateWithCert($cert, $key, $passphrase = null, $encoding
return $this->clientSideCert($cert, $key, $passphrase, $encoding);
}

/**
* @return Request $this
* @param int $seconds number of seconds before timeout
*/
public function timeoutIn($seconds)
{
$this->addOnCurlOption(CURLOPT_TIMEOUT, $seconds);
return $this;
}
// alias of timeoutIn
public function timeout($seconds)
{
return $this->timeoutIn($seconds);
}

/**
* Set the body of the request
* @return Request this
Expand Down Expand Up @@ -744,7 +759,7 @@ public function _curlPrep()
if ($this->hasTimeout()) {
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
}

if ($this->follow_redirects) {
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, $this->max_redirects);
Expand Down

0 comments on commit 165f272

Please sign in to comment.