Commit 23fa188f authored by Benni Mack's avatar Benni Mack Committed by Susanne Moog
Browse files

[!!!][FEATURE] Introduce Guzzle for making HTTP Requests

The Guzzle library is added as a composer dependency
instead of HttpRequest to request urls from TYPO3.

Guzzle is encapsulated inside a RequestFactory to do
requests and return PSR-7 compliant Response objects
to deal with content. In the future, Guzzle can also be used
to do HTTP requests asynchronously but there is no API
for that yet as there is no current need for that in the
TYPO3 Core.

GeneralUtility::getUrl() now uses Guzzle under the hood,
thus adding headers like the TYPO3 User Agent by default.

A lot of existing TYPO3_CONF_VARS options are now
removed or merged into Guzzle compliant options which
are independant of the implementation (cURL, stream
wrappers, fopen etc).

Resolves: #70056
Releases: master
Change-Id: Ibd14bba944b1590bae1b12c10f26365f20576475
Reviewed-on: https://review.typo3.org/43508

Reviewed-by: default avatarMorton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: default avatarMorton Jonuschat <m.jonuschat@mojocode.de>
Reviewed-by: Markus Klein's avatarMarkus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein's avatarMarkus Klein <markus.klein@typo3.org>
Reviewed-by: default avatarSusanne Moog <typo3@susannemoog.de>
Tested-by: default avatarSusanne Moog <typo3@susannemoog.de>
parent 88eb5b68
......@@ -38,7 +38,6 @@
"ext-session": "*",
"ext-xml": "*",
"psr/log": "1.0.0",
"pear/http_request2": "~2.2.1",
"swiftmailer/swiftmailer": "~5.4.1",
"symfony/console": ">=2.7|<3.1",
"symfony/finder": ">=2.7|<3.1",
......@@ -48,7 +47,8 @@
"psr/http-message": "~1.0",
"cogpowered/finediff": "~0.3.1",
"mso/idna-convert": "^0.9.1",
"typo3fluid/fluid": "^1.0.6"
"typo3fluid/fluid": "^1.0.6",
"guzzlehttp/guzzle": "^6.2.0"
},
"require-dev": {
"phpunit/phpunit": "~5.2.0",
......@@ -218,9 +218,5 @@
"TYPO3\\CMS\\Recycler\\Tests\\": "typo3/sysext/recycler/Tests/"
},
"classmap": ["typo3/sysext/extbase/Tests/Unit/Object/Container/Fixtures/"]
},
"include-path": [
"vendor/pear/http_request2/",
"vendor/pear/net_url2/"
]
}
}
......@@ -4,8 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "82c74b3e141085ced0e704ebb8ea114b",
"content-hash": "c30d9ff58c2c7c805bd2e1fce8c0b08b",
"hash": "e346427bb60ae5bf1fb7c5b6128dd888",
"content-hash": "d9d04a98027086cd867bb7dbff748e7a",
"packages": [
{
"name": "cogpowered/finediff",
......@@ -113,222 +113,225 @@
"time": "2015-06-14 21:17:01"
},
{
"name": "mso/idna-convert",
"version": "v0.9.1",
"name": "guzzlehttp/guzzle",
"version": "6.2.0",
"source": {
"type": "git",
"url": "https://github.com/phlylabs/idna-convert.git",
"reference": "0a0a09e460e63739d82c3f0c3f0e5555567a6be3"
"url": "https://github.com/guzzle/guzzle.git",
"reference": "d094e337976dff9d8e2424e8485872194e768662"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phlylabs/idna-convert/zipball/0a0a09e460e63739d82c3f0c3f0e5555567a6be3",
"reference": "0a0a09e460e63739d82c3f0c3f0e5555567a6be3",
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/d094e337976dff9d8e2424e8485872194e768662",
"reference": "d094e337976dff9d8e2424e8485872194e768662",
"shasum": ""
},
"require": {
"ext-pcre": "*",
"php": ">=5.0.0"
"guzzlehttp/promises": "~1.0",
"guzzlehttp/psr7": "~1.1",
"php": ">=5.5.0"
},
"require-dev": {
"ext-curl": "*",
"phpunit/phpunit": "~4.0",
"psr/log": "~1.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "0.9.x-dev"
"dev-master": "6.2-dev"
}
},
"autoload": {
"classmap": [
"idna_convert.class.php",
"uctc.php"
]
"files": [
"src/functions_include.php"
],
"psr-4": {
"GuzzleHttp\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"LGPL-2.1+"
"MIT"
],
"authors": [
{
"name": "Matthias Sommerfeld",
"email": "mso@phlylabs.de",
"role": "Developer"
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "A library for encoding and decoding internationalized domain names",
"homepage": "http://idnaconv.net/",
"description": "Guzzle is a PHP HTTP client library",
"homepage": "http://guzzlephp.org/",
"keywords": [
"idn",
"idna",
"php"
"client",
"curl",
"framework",
"http",
"http client",
"rest",
"web service"
],
"time": "2016-01-06 21:05:46"
"time": "2016-03-21 20:02:09"
},
{
"name": "pear/http_request2",
"version": "v2.2.1",
"name": "guzzlehttp/promises",
"version": "1.1.0",
"source": {
"type": "git",
"url": "https://github.com/pear/HTTP_Request2.git",
"reference": "d6c81670c504045248c1afdf896bb9a3288158de"
"url": "https://github.com/guzzle/promises.git",
"reference": "bb9024c526b22f3fe6ae55a561fd70653d470aa8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/pear/HTTP_Request2/zipball/d6c81670c504045248c1afdf896bb9a3288158de",
"reference": "d6c81670c504045248c1afdf896bb9a3288158de",
"url": "https://api.github.com/repos/guzzle/promises/zipball/bb9024c526b22f3fe6ae55a561fd70653d470aa8",
"reference": "bb9024c526b22f3fe6ae55a561fd70653d470aa8",
"shasum": ""
},
"require": {
"pear/net_url2": ">=2.0.0",
"pear/pear_exception": "*",
"php": ">=5.2.0"
"php": ">=5.5.0"
},
"suggest": {
"ext-fileinfo": "Adds support for looking up mime-types using finfo.",
"ext-zlib": "Allows handling gzip compressed responses.",
"lib-curl": "Allows using cURL as a request backend.",
"lib-openssl": "Allows handling SSL requests when not using cURL."
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"type": "library",
"autoload": {
"psr-0": {
"HTTP_Request2": ""
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"autoload": {
"psr-4": {
"GuzzleHttp\\Promise\\": "src/"
},
"files": [
"src/functions_include.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
"MIT"
],
"authors": [
{
"name": "Alexey Borzov",
"email": "avb@php.net",
"role": "Developer HTML_Common2"
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "Provides an easy way to perform HTTP requests.",
"homepage": "http://pear.php.net/package/HTTP_Request2",
"description": "Guzzle promises library",
"keywords": [
"PEAR",
"curl",
"http",
"request"
"promise"
],
"time": "2014-01-16 17:27:21"
"time": "2016-03-08 01:15:46"
},
{
"name": "pear/net_url2",
"version": "v2.2.0",
"name": "guzzlehttp/psr7",
"version": "1.2.3",
"source": {
"type": "git",
"url": "https://github.com/pear/Net_URL2.git",
"reference": "fa9b1ecb3c3e640d4a54d58d681a4cb7524f209e"
"url": "https://github.com/guzzle/psr7.git",
"reference": "2e89629ff057ebb49492ba08e6995d3a6a80021b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/pear/Net_URL2/zipball/fa9b1ecb3c3e640d4a54d58d681a4cb7524f209e",
"reference": "fa9b1ecb3c3e640d4a54d58d681a4cb7524f209e",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/2e89629ff057ebb49492ba08e6995d3a6a80021b",
"reference": "2e89629ff057ebb49492ba08e6995d3a6a80021b",
"shasum": ""
},
"require": {
"php": ">=5.1.4"
"php": ">=5.4.0",
"psr/http-message": "~1.0"
},
"provide": {
"psr/http-message-implementation": "1.0"
},
"require-dev": {
"phpunit/phpunit": ">=3.3.0"
"phpunit/phpunit": "~4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.2.x-dev"
"dev-master": "1.0-dev"
}
},
"autoload": {
"classmap": [
"Net/URL2.php"
"psr-4": {
"GuzzleHttp\\Psr7\\": "src/"
},
"files": [
"src/functions_include.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
"MIT"
],
"authors": [
{
"name": "David Coallier",
"email": "davidc@php.net"
},
{
"name": "Tom Klingenberg",
"email": "tkli@php.net"
},
{
"name": "Christian Schmidt",
"email": "chmidt@php.net"
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "Class for parsing and handling URL. Provides parsing of URLs into their constituent parts (scheme, host, path etc.), URL generation, and resolving of relative URLs.",
"homepage": "https://github.com/pear/Net_URL2",
"description": "PSR-7 message implementation",
"keywords": [
"PEAR",
"net",
"networking",
"rfc3986",
"uri",
"url"
],
"time": "2015-04-18 17:36:57"
"http",
"message",
"stream",
"uri"
],
"time": "2016-02-18 21:54:00"
},
{
"name": "pear/pear_exception",
"version": "v1.0.0",
"name": "mso/idna-convert",
"version": "v0.9.1",
"source": {
"type": "git",
"url": "https://github.com/pear/PEAR_Exception.git",
"reference": "8c18719fdae000b690e3912be401c76e406dd13b"
"url": "https://github.com/phlylabs/idna-convert.git",
"reference": "0a0a09e460e63739d82c3f0c3f0e5555567a6be3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/pear/PEAR_Exception/zipball/8c18719fdae000b690e3912be401c76e406dd13b",
"reference": "8c18719fdae000b690e3912be401c76e406dd13b",
"url": "https://api.github.com/repos/phlylabs/idna-convert/zipball/0a0a09e460e63739d82c3f0c3f0e5555567a6be3",
"reference": "0a0a09e460e63739d82c3f0c3f0e5555567a6be3",
"shasum": ""
},
"require": {
"php": ">=4.4.0"
},
"require-dev": {
"phpunit/phpunit": "*"
"ext-pcre": "*",
"php": ">=5.0.0"
},
"type": "class",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
"dev-master": "0.9.x-dev"
}
},
"autoload": {
"psr-0": {
"PEAR": ""
}
"classmap": [
"idna_convert.class.php",
"uctc.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"include-path": [
"."
],
"license": [
"BSD-2-Clause"
"LGPL-2.1+"
],
"authors": [
{
"name": "Helgi Thormar",
"email": "dufuz@php.net"
},
{
"name": "Greg Beaver",
"email": "cellog@php.net"
"name": "Matthias Sommerfeld",
"email": "mso@phlylabs.de",
"role": "Developer"
}
],
"description": "The PEAR Exception base class.",
"homepage": "https://github.com/pear/PEAR_Exception",
"description": "A library for encoding and decoding internationalized domain names",
"homepage": "http://idnaconv.net/",
"keywords": [
"exception"
"idn",
"idna",
"php"
],
"time": "2015-02-10 20:07:52"
"time": "2016-01-06 21:05:46"
},
{
"name": "psr/http-message",
......@@ -924,177 +927,6 @@
],
"time": "2015-12-31 15:58:49"
},
{
"name": "guzzlehttp/guzzle",
"version": "6.2.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/guzzle.git",
"reference": "d094e337976dff9d8e2424e8485872194e768662"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/d094e337976dff9d8e2424e8485872194e768662",
"reference": "d094e337976dff9d8e2424e8485872194e768662",
"shasum": ""
},
"require": {
"guzzlehttp/promises": "~1.0",
"guzzlehttp/psr7": "~1.1",
"php": ">=5.5.0"
},
"require-dev": {
"ext-curl": "*",
"phpunit/phpunit": "~4.0",
"psr/log": "~1.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "6.2-dev"
}
},
"autoload": {
"files": [
"src/functions_include.php"
],
"psr-4": {
"GuzzleHttp\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "Guzzle is a PHP HTTP client library",
"homepage": "http://guzzlephp.org/",
"keywords": [
"client",
"curl",
"framework",
"http",
"http client",
"rest",
"web service"
],
"time": "2016-03-21 20:02:09"
},
{
"name": "guzzlehttp/promises",
"version": "1.1.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/promises.git",
"reference": "bb9024c526b22f3fe6ae55a561fd70653d470aa8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/promises/zipball/bb9024c526b22f3fe6ae55a561fd70653d470aa8",
"reference": "bb9024c526b22f3fe6ae55a561fd70653d470aa8",
"shasum": ""
},
"require": {
"php": ">=5.5.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"autoload": {
"psr-4": {
"GuzzleHttp\\Promise\\": "src/"
},
"files": [
"src/functions_include.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "Guzzle promises library",
"keywords": [
"promise"
],
"time": "2016-03-08 01:15:46"
},
{
"name": "guzzlehttp/psr7",
"version": "1.2.3",
"source": {
"type": "git",
"url": "https://github.com/guzzle/psr7.git",
"reference": "2e89629ff057ebb49492ba08e6995d3a6a80021b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/2e89629ff057ebb49492ba08e6995d3a6a80021b",
"reference": "2e89629ff057ebb49492ba08e6995d3a6a80021b",
"shasum": ""
},
"require": {
"php": ">=5.4.0",
"psr/http-message": "~1.0"
},
"provide": {
"psr/http-message-implementation": "1.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"autoload": {
"psr-4": {
"GuzzleHttp\\Psr7\\": "src/"
},
"files": [
"src/functions_include.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "PSR-7 message implementation",
"keywords": [
"http",
"message",
"stream",
"uri"
],
"time": "2016-02-18 21:54:00"
},
{
"name": "mikey179/vfsStream",
"version": "v1.6.2",
......
......@@ -718,7 +718,6 @@ class Clipboard
return $message;
}
/**
* Returns confirm JavaScript message
*
......
......@@ -535,7 +535,7 @@ class Bootstrap
*/
protected function defineUserAgentConstant()
{
define('TYPO3_user_agent', 'User-Agent: ' . $GLOBALS['TYPO3_CONF_VARS']['HTTP']['userAgent']);
define('TYPO3_user_agent', 'User-Agent: ' . $GLOBALS['TYPO3_CONF_VARS']['HTTP']['headers']['User-Agent']);
return $this;
}
......
<?php
namespace TYPO3\CMS\Core\Http;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
/**
* HTTP Request Utility class
*
* Extends \HTTP_Request2 and sets TYPO3 environment defaults
*/
class HttpRequest extends \HTTP_Request2
{
/**
* Default constructor - sets TYPO3 defaults
*
* @param string|\Net_Url2 $url Request URL
* @param string $method Request Method (GET, HEAD or POST). Redirects reset this to GET unless "strict_redirects" is set.
* @param array $config Configuration for this request instance
* @link http://pear.php.net/manual/en/package.http.http-request2.config.php
*/
public function __construct($url = null, $method = self::METHOD_GET, array $config = array())
{
parent::__construct($url, $method);
$this->setConfiguration($config);
}
/**
* Sets the configuration for this object instance.
* Merges default values with provided $config and overrides all
* not provided values with those from $TYPO3_CONF_VARS
*
* @param array $config Configuration options which override the default configuration
* @return void
* @see http://pear.php.net/manual/en/package.http.http-request2.config.php
*/
public function setConfiguration(array $config = array())
{
// set a branded user-agent
$this->setHeader('user-agent', $GLOBALS['TYPO3_CONF_VARS']['HTTP']['userAgent']);
$default = array(
'adapter' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['adapter'],
'connect_timeout' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['connect_timeout'],
'timeout' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['timeout'],
'protocol_version' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['protocol_version'],
'follow_redirects' => (bool)$GLOBALS['TYPO3_CONF_VARS']['HTTP']['follow_redirects'],
'max_redirects' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['max_redirects'],
'strict_redirects' => (bool)$GLOBALS['TYPO3_CONF_VARS']['HTTP']['strict_redirects'],
'proxy_host' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_host'],
'proxy_port' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_port'],
'proxy_user' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_user'],
'proxy_password' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_password'],
'proxy_auth_scheme' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_auth_scheme'],