1 | <?php |
||
16 | class MailxpertCurlHttpClient implements MailxpertHttpClientInterface |
||
17 | { |
||
18 | /** |
||
19 | * @var string The client error message |
||
20 | */ |
||
21 | protected $curlErrorMessage = ''; |
||
22 | |||
23 | /** |
||
24 | * @var int The curl client error code |
||
25 | */ |
||
26 | protected $curlErrorCode = 0; |
||
27 | |||
28 | /** |
||
29 | * @var string|boolean The raw response from the server |
||
30 | */ |
||
31 | protected $rawResponse; |
||
32 | |||
33 | /** |
||
34 | * @var MailxpertCurl Procedural curl as object |
||
35 | */ |
||
36 | protected $mailxpertCurl; |
||
37 | |||
38 | /** |
||
39 | * @const Curl Version which is unaffected by the proxy header length error. |
||
40 | */ |
||
41 | const CURL_PROXY_QUIRK_VER = 0x071E00; |
||
42 | |||
43 | /** |
||
44 | * @const "Connection Established" header text |
||
45 | */ |
||
46 | const CONNECTION_ESTABLISHED = "HTTP/1.0 200 Connection established\r\n\r\n"; |
||
47 | |||
48 | /** |
||
49 | * @param MailxpertCurl|null $mailxpertCurl Procedural curl as object |
||
50 | */ |
||
51 | public function __construct(MailxpertCurl $mailxpertCurl = null) |
||
55 | |||
56 | /** |
||
57 | * {@inheritdoc} |
||
58 | */ |
||
59 | public function send($url, $method, $body, array $headers, $timeOut) |
||
75 | |||
76 | /** |
||
77 | * Opens a new curl connection. |
||
78 | * |
||
79 | * @param string $url The endpoint to send the request to. |
||
80 | * @param string $method The request method. |
||
81 | * @param string $body The body of the request. |
||
82 | * @param array $headers The request headers. |
||
83 | * @param int $timeOut The timeout in seconds for the request. |
||
84 | */ |
||
85 | public function openConnection($url, $method, $body, array $headers, $timeOut) |
||
104 | |||
105 | /** |
||
106 | * Closes an existing curl connection |
||
107 | */ |
||
108 | public function closeConnection() |
||
112 | |||
113 | /** |
||
114 | * Send the request and get the raw response from curl |
||
115 | */ |
||
116 | public function sendRequest() |
||
120 | |||
121 | /** |
||
122 | * Compiles the request headers into a curl-friendly format. |
||
123 | * |
||
124 | * @param array $headers The request headers. |
||
125 | * |
||
126 | * @return array |
||
127 | */ |
||
128 | public function compileRequestHeaders(array $headers) |
||
138 | |||
139 | /** |
||
140 | * Extracts the headers and the body into a two-part array |
||
141 | * |
||
142 | * @return array |
||
143 | */ |
||
144 | public function extractResponseHeadersAndBody() |
||
153 | |||
154 | /** |
||
155 | * Return proper header size |
||
156 | * |
||
157 | * @return integer |
||
158 | */ |
||
159 | private function getHeaderSize() |
||
175 | |||
176 | /** |
||
177 | * Detect versions of Curl which report incorrect header lengths when |
||
178 | * using Proxies. |
||
179 | * |
||
180 | * @return boolean |
||
181 | */ |
||
182 | private function needsCurlProxyFix() |
||
189 | } |
||
190 |