|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the bee4/transport package. |
|
4
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
5
|
|
|
* file that was distributed with this source code. |
|
6
|
|
|
* |
|
7
|
|
|
* @copyright Bee4 2015 |
|
8
|
|
|
* @author Stephane HULARD <[email protected]> |
|
9
|
|
|
* @package Bee4\Transport\Configuration |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Bee4\Transport\Configuration; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* HTTP Configuration implementation |
|
16
|
|
|
* @package Bee4\Transport\Configuration |
|
17
|
|
|
* @property string $accept_encoding Value used for the Accept-Encoding header |
|
18
|
|
|
* @property string $user_agent User agent used in the current request |
|
19
|
|
|
*/ |
|
20
|
|
|
class HttpConfiguration extends Configuration |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* Default configuration values |
|
24
|
|
|
*/ |
|
25
|
|
|
const DEFAULTS = [ |
|
26
|
|
|
'allow_redirects' => [ |
|
27
|
|
|
'max' => null, |
|
28
|
|
|
'referer' => true, |
|
29
|
|
|
], |
|
30
|
|
|
'accept_encoding' => null, |
|
31
|
|
|
'user_agent' => null |
|
32
|
|
|
]; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Build a configuration instance |
|
36
|
|
|
* @param array $data |
|
37
|
|
|
*/ |
|
38
|
|
|
public function __construct(array $data = []) |
|
39
|
|
|
{ |
|
40
|
|
|
parent::__construct(array_merge( |
|
41
|
|
|
self::DEFAULTS, |
|
42
|
|
|
$data |
|
43
|
|
|
)); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Check if redirects are allowed |
|
48
|
|
|
* @return boolean |
|
49
|
|
|
*/ |
|
50
|
|
|
public function redirectsAllowed() |
|
51
|
|
|
{ |
|
52
|
|
|
return $this['allow_redirects']!==false; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Define how much redirects must be followed, default null = infinite |
|
57
|
|
|
* @return Configuration|integer|null |
|
58
|
|
|
*/ |
|
59
|
|
|
public function allowRedirectsMax($max = null) |
|
60
|
|
|
{ |
|
61
|
|
|
return $this->arrayValue('allow_redirects', 'max', $max); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Define if referer must be set during redirection |
|
66
|
|
|
* @return Configuration|boolean |
|
67
|
|
|
*/ |
|
68
|
|
|
public function allowRedirectsReferer($referer = null) |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->arrayValue('allow_redirects', 'referer', $referer); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|