TYPO3 CMS  TYPO3_7-6
HttpRequest.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Core\Http;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
22 class HttpRequest extends \HTTP_Request2
23 {
32  public function __construct($url = null, $method = self::METHOD_GET, array $config = [])
33  {
34  parent::__construct($url, $method);
35  $this->setConfiguration($config);
36  }
37 
47  public function setConfiguration(array $config = [])
48  {
49  // set a branded user-agent
50  $this->setHeader('user-agent', $GLOBALS['TYPO3_CONF_VARS']['HTTP']['userAgent']);
51  $default = [
52  'adapter' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['adapter'],
53  'connect_timeout' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['connect_timeout'],
54  'timeout' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['timeout'],
55  'protocol_version' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['protocol_version'],
56  'follow_redirects' => (bool)$GLOBALS['TYPO3_CONF_VARS']['HTTP']['follow_redirects'],
57  'max_redirects' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['max_redirects'],
58  'strict_redirects' => (bool)$GLOBALS['TYPO3_CONF_VARS']['HTTP']['strict_redirects'],
59  'proxy_host' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_host'],
60  'proxy_port' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_port'],
61  'proxy_user' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_user'],
62  'proxy_password' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_password'],
63  'proxy_auth_scheme' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_auth_scheme'],
64  'ssl_verify_peer' => (bool)$GLOBALS['TYPO3_CONF_VARS']['HTTP']['ssl_verify_peer'],
65  'ssl_verify_host' => (bool)$GLOBALS['TYPO3_CONF_VARS']['HTTP']['ssl_verify_host'],
66  // we have to deal with Install Tool limitations and set this to NULL if it is empty
67  'ssl_cafile' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['ssl_cafile'] ?: null,
68  'ssl_capath' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['ssl_capath'] ?: null,
69  'ssl_local_cert' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['ssl_local_cert'] ?: null,
70  'ssl_passphrase' => $GLOBALS['TYPO3_CONF_VARS']['HTTP']['ssl_passphrase'] ?: null
71  ];
72  $configuration = array_merge($default, $config);
73  $this->setConfig($configuration);
74  }
75 
85  public function download($directory, $filename = '')
86  {
87  $isAttached = false;
88  // Do not store the body in memory
89  $this->setConfig('store_body', false);
90  // Check if we already attached an instance of download. If so, just reuse it.
91  foreach ($this->observers as $observer) {
92  if ($observer instanceof Observer\Download) {
94  $observer->setDirectory($directory);
95  $observer->setFilename($filename);
96  $isAttached = true;
97  }
98  }
99  if (!$isAttached) {
101  $observer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Http\Observer\Download::class, $directory, $filename);
102  $this->attach($observer);
103  }
104  return $this->send();
105  }
106 }
__construct($url=null, $method=self::METHOD_GET, array $config=[])
Definition: HttpRequest.php:32
setConfiguration(array $config=[])
Definition: HttpRequest.php:47
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']