Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
0e38e4f
Solves issue #170: HTTP Header parsing is inconsistent
May 4, 2015
e4a79c6
Update Response.php
josch1710 May 5, 2015
6d480e2
Update the tests
josch1710 May 22, 2015
fe7e64b
Always lowercase header names.
josch1710 May 22, 2015
5ba05b5
Corrected namespace
josch1710 May 22, 2015
f736c8f
added support for http_proxy environment variable
fzipi Jun 12, 2015
f576147
Fix for frameworks that use object proxies
tvt Oct 9, 2015
032ba14
ConnectionErrorException cURLError
bodeme Nov 18, 2015
b8141f7
Update HttpfulTest.php
josch1710 Jan 25, 2016
359d124
Don't lowercase header names
josch1710 Jan 25, 2016
5b01707
Removed remaining strtolower
Jan 29, 2016
4e21b6f
Typo correction
Mar 14, 2016
e813e08
Fix download link
edueo May 20, 2016
56d2a60
#227 unset curl handle after it has been closed
masi Jun 10, 2016
1ecc328
Merge remote-tracking branch 'upstream/master'
Jul 21, 2016
fc8e427
Merge pull request #182 from josch1710/master
Jul 22, 2016
d6de7d9
Merge pull request #225 from edueo/fix-download-link
Dec 15, 2016
034924a
Merge pull request #219 from migueldemoura/patch-1
Dec 15, 2016
0780ffb
Merge pull request #229 from plan2net/issue227
Oct 21, 2017
cb863b8
Merge pull request #208 from bodeme/master
Oct 21, 2017
09ae53b
Merge pull request #183 from fzipi/master
Oct 21, 2017
f71452d
Merge pull request #205 from tvt/patch-1
Oct 21, 2017
10394c7
Add PHPDocs for __call methods.
Ekman May 29, 2018
a29ca5c
Merge pull request #271 from Ekman/phpdoc_call
Jul 27, 2018
bb343d0
PHPUnit Fixes and officially drop < 7.2
nategood Dec 29, 2019
4105a9c
Merge pull request #284 from nategood/php7-testing
Dec 29, 2019
8ba7fa7
master
nategood Dec 29, 2019
4e0c1eb
fix: broken test with header casing issues
atymic Jan 7, 2020
29ce985
fix: allow case insensitive header access
atymic Jan 7, 2020
fd05a5c
docs: update changelog
atymic Jan 7, 2020
97a0389
Merge pull request #286 from atymic/header-casing
nategood Jan 25, 2020
ef36ec8
version bump
nategood Jan 25, 2020
f3607cb
Merge remote-tracking branch 'origin/dev'
nategood Jan 25, 2020
0cded3e
version bump - json exception improvement
nategood Jan 25, 2020
7636620
Updates applied per suggestion of Rector to be 7.2 to 8.2 compatible.
sosherof May 11, 2023
2d2d925
Fixing some type-o's.
sosherof May 12, 2023
c3fdcd1
Fixing some type-o's.
sosherof May 12, 2023
e20b236
Finaly type-o fixes.
sosherof May 16, 2023
5fda2ca
Changed unset($this->_ch) to $this->_ch=null;
sosherof Mar 12, 2024
164467c
Compiled w/out unset statement in Requests
sosherof Mar 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ composer.lock
vendor
downloads
.idea/*
tests/.phpunit.result.cache
/rector.php
/.vs
15 changes: 5 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
language: php

php:
- 5.3
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm

- 7.2
- 7.3
- 7.4

matrix:
fast_finish: true
allow_failures:
- php: 7.0


script:
- phpunit -c ./tests/phpunit.xml
30 changes: 14 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Build Status](https://secure.travis-ci.org/nategood/httpful.png?branch=master)](http://travis-ci.org/nategood/httpful) [![Total Downloads](https://poser.pugx.org/nategood/httpful/downloads.png)](https://packagist.org/packages/nategood/httpful)

[Httpful](http://phphttpclient.com) is a simple Http Client library for PHP 5.3+. There is an emphasis of readability, simplicity, and flexibility – basically provide the features and flexibility to get the job done and make those features really easy to use.
Httpful is a simple Http Client library for PHP 7.2+. There is an emphasis of readability, simplicity, and flexibility – basically provide the features and flexibility to get the job done and make those features really easy to use.

Features

Expand Down Expand Up @@ -34,16 +34,6 @@ echo "{$response->body->name} joined GitHub on " .

# Installation

## Phar

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

```php
include('httpful.phar');
$r = \Httpful\Request::get($uri)->sendIt();
...
```

## Composer

Httpful is PSR-0 compliant and can be installed using [composer](http://getcomposer.org/). Simply add `nategood/httpful` to your composer.json file. _Composer is the sane alternative to PEAR. It is excellent for managing dependencies in larger projects_.
Expand All @@ -62,11 +52,7 @@ Because Httpful is PSR-0 compliant, you can also just clone the Httpful reposito

If you want the build your own [Phar Archive](http://php.net/manual/en/book.phar.php) you can use the `build` script included.
Make sure that your `php.ini` has the *Off* or 0 value for the `phar.readonly` setting.
Also you need to create ad empty `downloads` directory in the project root.

# Show Me More!

You can checkout the [Httpful Landing Page](http://phphttpclient.com) for more info including many examples and [documentation](http://phphttpclient.com/docs).
Also you need to create an empty `downloads` directory in the project root.

# Contributing

Expand All @@ -81,6 +67,18 @@ Httpful highly encourages sending in pull requests. When submitting a pull requ

# Changelog

## 0.3.2

- REFACTOR [PR #276](https://github.com/nategood/httpful/pull/276) Add properly subclassed, more descriptive Exceptions for JSON parse errors

## 0.3.1

- FIX [PR #286](https://github.com/nategood/httpful/pull/286) Fixed header case sensitivity

## 0.3.0

- REFACTOR Dropped support for dead versions of PHP. Updated the PHPUnit tests.

## 0.2.20

- MINOR Move Response building logic into separate function [PR #193](https://github.com/nategood/httpful/pull/193)
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"homepage": "http://github.com/nategood/httpful",
"license": "MIT",
"keywords": ["http", "curl", "rest", "restful", "api", "requests"],
"version": "0.2.20",
"version": "0.3.2",
"authors": [
{
"name": "Nate Good",
Expand All @@ -13,7 +13,7 @@
}
],
"require": {
"php": ">=5.3",
"php": ">=7.2",
"ext-curl": "*"
},
"autoload": {
Expand Down
Binary file added downloads/httpful.phar
Binary file not shown.
14 changes: 7 additions & 7 deletions src/Httpful/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
class Bootstrap
{

const DIR_GLUE = DIRECTORY_SEPARATOR;
const NS_GLUE = '\\';
public const DIR_GLUE = DIRECTORY_SEPARATOR;
public const NS_GLUE = '\\';

public static $registered = false;

Expand All @@ -21,7 +21,7 @@ class Bootstrap
*/
public static function init()
{
spl_autoload_register(array('\Httpful\Bootstrap', 'autoload'));
spl_autoload_register(['\\' . \Httpful\Bootstrap::class, 'autoload']);
self::registerHandlers();
}

Expand All @@ -32,15 +32,15 @@ public static function init()
*/
public static function autoload($classname)
{
self::_autoload(dirname(dirname(__FILE__)), $classname);
self::_autoload(dirname(__FILE__,2), $classname);
}

/**
* Register the autoloader and any other setup needed
*/
public static function pharInit()
{
spl_autoload_register(array('\Httpful\Bootstrap', 'pharAutoload'));
spl_autoload_register(['\\' . \Httpful\Bootstrap::class, 'pharAutoload']);
self::registerHandlers();
}

Expand Down Expand Up @@ -78,12 +78,12 @@ public static function registerHandlers()

// @todo check a conf file to load from that instead of
// hardcoding into the library?
$handlers = array(
$handlers = [
\Httpful\Mime::JSON => new \Httpful\Handlers\JsonHandler(),
\Httpful\Mime::XML => new \Httpful\Handlers\XmlHandler(),
\Httpful\Mime::FORM => new \Httpful\Handlers\FormHandler(),
\Httpful\Mime::CSV => new \Httpful\Handlers\CsvHandler(),
);
];

foreach ($handlers as $mime => $handler) {
// Don't overwrite if the handler has already been registered
Expand Down
53 changes: 50 additions & 3 deletions src/Httpful/Exception/ConnectionErrorException.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,54 @@
<?php
<?php

namespace Httpful\Exception;

class ConnectionErrorException extends \Exception
{

class ConnectionErrorException extends \Exception {


/**
* @var string
*/
private $curlErrorNumber;

/**
* @var string
*/
private $curlErrorString;

/**
* @return string
*/
public function getCurlErrorNumber() {
return $this->curlErrorNumber;
}

/**
* @param string $curlErrorNumber
* @return $this
*/
public function setCurlErrorNumber($curlErrorNumber) {
$this->curlErrorNumber = $curlErrorNumber;

return $this;
}

/**
* @return string
*/
public function getCurlErrorString() {
return $this->curlErrorString;
}

/**
* @param string $curlErrorString
* @return $this
*/
public function setCurlErrorString($curlErrorString) {
$this->curlErrorString = $curlErrorString;

return $this;
}


}
6 changes: 3 additions & 3 deletions src/Httpful/Handlers/CsvHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ public function parse($body)
if (empty($body))
return null;

$parsed = array();
$parsed = [];
$fp = fopen('data://text/plain;base64,' . base64_encode($body), 'r');
while (($r = fgetcsv($fp)) !== FALSE) {
$parsed[] = $r;
}

if (empty($parsed))
if ($parsed === [])
throw new \Exception("Unable to parse response as CSV");
return $parsed;
}
Expand All @@ -33,7 +33,7 @@ public function parse($body)
* @param mixed $payload
* @return string
*/
public function serialize($payload)
public function serialize($payload): string
{
$fp = fopen('php://temp/maxmemory:'. (6*1024*1024), 'r+');
$i = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/Httpful/Handlers/FormHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class FormHandler extends MimeHandlerAdapter
*/
public function parse($body)
{
$parsed = array();
$parsed = [];
parse_str($body, $parsed);
return $parsed;
}
Expand All @@ -23,7 +23,7 @@ public function parse($body)
* @param mixed $payload
* @return string
*/
public function serialize($payload)
public function serialize($payload): string
{
return http_build_query($payload, null, '&');
}
Expand Down
4 changes: 2 additions & 2 deletions src/Httpful/Handlers/JsonHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class JsonHandler extends MimeHandlerAdapter

public function init(array $args)
{
$this->decode_as_array = !!(array_key_exists('decode_as_array', $args) ? $args['decode_as_array'] : false);
$this->decode_as_array = (bool) ($args['decode_as_array'] ?? false);
}

/**
Expand All @@ -37,7 +37,7 @@ public function parse($body)
* @param mixed $payload
* @return string
*/
public function serialize($payload)
public function serialize($payload): string
{
return json_encode($payload);
}
Expand Down
10 changes: 5 additions & 5 deletions src/Httpful/Handlers/MimeHandlerAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class MimeHandlerAdapter
{
public function __construct(array $args = array())
public function __construct(array $args = [])
{
$this->init($args);
}
Expand All @@ -36,18 +36,18 @@ public function parse($body)
* @param mixed $payload
* @return string
*/
function serialize($payload)
function serialize($payload): string
{
return (string) $payload;
}

protected function stripBom($body)
protected function stripBom($body): string
{
if ( substr($body,0,3) === "\xef\xbb\xbf" ) // UTF-8
$body = substr($body,3);
else if ( substr($body,0,4) === "\xff\xfe\x00\x00" || substr($body,0,4) === "\x00\x00\xfe\xff" ) // UTF-32
elseif ( substr($body,0,4) === "\xff\xfe\x00\x00" || substr($body,0,4) === "\x00\x00\xfe\xff" ) // UTF-32
$body = substr($body,4);
else if ( substr($body,0,2) === "\xff\xfe" || substr($body,0,2) === "\xfe\xff" ) // UTF-16
elseif ( substr($body,0,2) === "\xff\xfe" || substr($body,0,2) === "\xfe\xff" ) // UTF-16
$body = substr($body,2);
return $body;
}
Expand Down
Loading