-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathHeaderCollector.php
More file actions
79 lines (63 loc) · 1.92 KB
/
Copy pathHeaderCollector.php
File metadata and controls
79 lines (63 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
namespace evaisse\SimpleHttpBundle\Curl\Collector;
use Symfony\Component\HttpFoundation\Cookie;
class HeaderCollector implements CollectorInterface
{
private $headers = array();
private $version;
private $code;
private $message;
public function collect() {
list($handle, $headerString) = func_get_args();
$cleanHeader = trim($headerString);
// The HTTP/1.0 200 OK header is also passed through this function
// and must be parsed differently than the other HTTP headers
if(false !== stripos($cleanHeader,"http/")) {
$this->parseHttp($cleanHeader);
} else {
$this->parseHeader($cleanHeader);
}
return strlen($headerString);
}
/**
* Parse the `HTTP/1.0 200 OK' header into the proper
* Status Code/Message and Protocol Version fields
*
* @param string $header
*/
private function parseHttp($header) {
list($version,$code,$message) = explode(" ", $header);
$versionParts = explode("/",$version);
$this->version = end($versionParts);
$this->code = $code;
$this->message = $message;
}
/**
* Parse the standard `Header-name: value' headers into
* individual header name/value pairs
*
* @param string $header
*/
private function parseHeader($header) {
if(!empty($header)) {
$pos = strpos($header, ": ");
if(false !== $pos) {
$name = substr($header,0,$pos);
$value = substr($header,$pos+2);
$this->headers[$name] = $value;
}
}
}
public function retrieve() {
return $this->headers;
}
public function getVersion() {
return $this->version;
}
public function getMessage() {
return $this->message;
}
public function getCode() {
return $this->code;
}
}