TYPO3 CMS  TYPO3_6-2
HttpRequest.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Core\Http;
3 
17 require_once('HTTP/Request2.php');
18 
26 class HttpRequest extends \HTTP_Request2 {
27 
36  public function __construct($url = NULL, $method = self::METHOD_GET, array $config = array()) {
37  parent::__construct($url, $method);
38  $this->setConfiguration($config);
39  }
40 
50  public function setConfiguration(array $config = array()) {
51  // set a branded user-agent
52  $this->setHeader('user-agent', $GLOBALS['TYPO3_CONF_VARS']['HTTP']['userAgent']);
53  $default = array(
54  'adapter' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['adapter'],
55  'connect_timeout' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['connect_timeout'],
56  'timeout' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['timeout'],
57  'protocol_version' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['protocol_version'],
58  'follow_redirects' => (bool) $GLOBALS['TYPO3_CONF_VARS']['HTTP']['follow_redirects'],
59  'max_redirects' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['max_redirects'],
60  'strict_redirects' => (bool) $GLOBALS['TYPO3_CONF_VARS']['HTTP']['strict_redirects'],
61  'proxy_host' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_host'],
62  'proxy_port' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_port'],
63  'proxy_user' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_user'],
64  'proxy_password' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_password'],
65  'proxy_auth_scheme' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_auth_scheme'],
66  'ssl_verify_peer' => (bool) $GLOBALS['TYPO3_CONF_VARS']['HTTP']['ssl_verify_peer'],
67  'ssl_verify_host' => (bool) $GLOBALS['TYPO3_CONF_VARS']['HTTP']['ssl_verify_host'],
68  // we have to deal with Install Tool limitations and set this to NULL if it is empty
69  'ssl_cafile' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['ssl_cafile'] ?: NULL,
70  'ssl_capath' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['ssl_capath'] ?: NULL,
71  'ssl_local_cert' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['ssl_local_cert'] ?: NULL,
72  'ssl_passphrase' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['ssl_passphrase'] ?: NULL
73  );
74  $configuration = array_merge($default, $config);
75  $this->setConfig($configuration);
76  }
77 
87  public function download($directory, $filename = '') {
88  $isAttached = FALSE;
89  // Do not store the body in memory
90  $this->setConfig('store_body', FALSE);
91  // Check if we already attached an instance of download. If so, just reuse it.
92  foreach ($this->observers as $observer) {
93  if ($observer instanceof \TYPO3\CMS\Core\Http\Observer\Download) {
95  $observer->setDirectory($directory);
96  $observer->setFilename($filename);
97  $isAttached = TRUE;
98  }
99  }
100  if (!$isAttached) {
102  $observer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Http\\Observer\\Download', $directory, $filename);
103  $this->attach($observer);
104  }
105  return $this->send();
106  }
107 
108 }
__construct($url=NULL, $method=self::METHOD_GET, array $config=array())
Definition: HttpRequest.php:36
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
setConfiguration(array $config=array())
Definition: HttpRequest.php:50