Lines Matching refs:this

30     public $header_regexp; // if set this RE must match against the headers, else abort
69 $this->agent = 'Mozilla/4.0 (compatible; DokuWiki HTTP Client; '.PHP_OS.')';
70 $this->timeout = 15;
71 $this->cookies = array();
72 $this->referer = '';
73 $this->max_redirect = 3;
74 $this->redirect_count = 0;
75 $this->status = 0;
76 $this->headers = array();
77 $this->http = '1.0';
78 $this->debug = false;
79 $this->max_bodysize = 0;
80 $this->header_regexp= '';
81 if(extension_loaded('zlib')) $this->headers['Accept-encoding'] = 'gzip';
82 $this->headers['Accept'] = 'text/xml,application/xml,application/xhtml+xml,'.
84 $this->headers['Accept-Language'] = 'en-us';
100 if(!$this->sendRequest($url)) return false;
101 if($this->status == 304 && $sloppy304) return $this->resp_body;
102 if($this->status < 200 || $this->status > 206) return false;
103 return $this->resp_body;
127 $url .= $this->postEncode($data);
128 return $this->get($url,$sloppy304);
142 if(!$this->sendRequest($url,$data,'POST')) return false;
143 if($this->status < 200 || $this->status > 206) return false;
144 return $this->resp_body;
165 $this->start = $this->time();
166 $this->error = '';
167 $this->status = 0;
168 $this->resp_body = '';
169 $this->resp_headers = array();
175 if($this->max_bodysize &&
176 !$this->max_bodysize_abort &&
177 isset($this->headers['Accept-encoding']) &&
178 $this->headers['Accept-encoding'] == 'gzip'){
179 unset($this->headers['Accept-encoding']);
188 if(isset($uri['user'])) $this->user = $uri['user'];
189 if(isset($uri['pass'])) $this->pass = $uri['pass'];
192 if($this->useProxyForUrl($url)){
194 $server = $this->proxy_host;
195 $port = $this->proxy_port;
197 $use_tls = $this->proxy_ssl;
207 $this->status = -200;
208 $this->error = 'This PHP version does not support SSL - cannot connect to server';
214 $headers = $this->headers;
217 $headers['User-Agent'] = $this->agent;
218 $headers['Referer'] = $this->referer;
227 $headers['Content-Type'] = 'multipart/form-data; boundary=' . $this->boundary;
228 $data = $this->postMultipartEncode($data);
232 $data = $this->postEncode($data);
244 if($this->user) {
245 $headers['Authorization'] = 'Basic '.base64_encode($this->user.':'.$this->pass);
247 if($this->proxy_user) {
248 $headers['Proxy-Authorization'] = 'Basic '.base64_encode($this->proxy_user.':'.$this->proxy_pass);
252 $connectionId = $this->uniqueConnectionId($server,$port);
253 $this->debug('connection pool', self::$connections);
256 $this->debug('reusing connection', $connectionId);
260 $this->debug('opening connection', $connectionId);
262 $socket = @fsockopen($server,$port,$errno, $errstr, $this->timeout);
264 $this->status = -100;
265 $this->error = "Could not connect to $server:$port\n$errstr ($errno)";
271 if($this->ssltunnel($socket, $request_url)){
273 $this->keep_alive = false;
278 $this->status = $e->getCode();
279 $this->error = $e->getMessage();
285 if ($this->keep_alive) {
292 if ($this->keep_alive && !$this->useProxyForUrl($request_url)) {
306 $request = "$method $request_url HTTP/".$this->http.HTTP_NL;
307 $request .= $this->buildHeaders($headers);
308 $request .= $this->getCookies();
312 $this->debug('request',$request);
313 $this->sendData($socket, $request, 'request');
318 $r_line = $this->readLine($socket, 'headers');
322 $this->debug('response headers',$r_headers);
325 if($this->max_bodysize && preg_match('/\r?\nContent-Length:\s*(\d+)\r?\n/i',$r_headers,$match)){
326 if($match[1] > $this->max_bodysize){
327 if ($this->max_bodysize_abort)
330 $this->error = 'Reported content length exceeds allowed response size';
338 $this->status = $m[2];
341 $this->resp_headers = $this->parseHeaders($r_headers);
342 if(isset($this->resp_headers['set-cookie'])){
343 foreach ((array) $this->resp_headers['set-cookie'] as $cookie){
348 if(isset($this->cookies[$key])){
349 unset($this->cookies[$key]);
352 $this->cookies[$key] = $val;
357 $this->debug('Object headers',$this->resp_headers);
360 if(in_array($this->status, [301, 302, 303, 307, 308])){
361 if (empty($this->resp_headers['location'])){
363 }elseif($this->redirect_count == $this->max_redirect){
371 $this->redirect_count++;
372 $this->referer = $url;
374 if (!preg_match('/^http/i', $this->resp_headers['location'])){
375 if($this->resp_headers['location'][0] != '/'){
376 $this->resp_headers['location'] = $uri['scheme'].'://'.$uri['host'].':'.$uriPort.
377 dirname($path).'/'.$this->resp_headers['location'];
379 $this->resp_headers['location'] = $uri['scheme'].'://'.$uri['host'].':'.$uriPort.
380 $this->resp_headers['location'];
383 if($this->status == 307 || $this->status == 308) {
385 return $this->sendRequest($this->resp_headers['location'],$unencodedData,$method);
388 return $this->sendRequest($this->resp_headers['location'],array(),'GET');
394 if($this->header_regexp && !preg_match($this->header_regexp,$r_headers))
401 isset($this->resp_headers['transfer-encoding']) &&
402 $this->resp_headers['transfer-encoding'] == 'chunked'
404 isset($this->resp_headers['transfer-coding']) &&
405 $this->resp_headers['transfer-coding'] == 'chunked'
411 while (preg_match('/^[a-zA-Z0-9]?$/',$byte=$this->readData($socket,1,'chunk'))){
417 $this->readLine($socket, 'chunk'); // readtrailing \n
420 if($this->max_bodysize && $chunk_size+strlen($r_body) > $this->max_bodysize){
421 if ($this->max_bodysize_abort)
423 $this->error = 'Allowed response size exceeded';
424 $chunk_size = $this->max_bodysize - strlen($r_body);
429 $r_body .= $this->readData($socket, $chunk_size, 'chunk');
430 $this->readData($socket, 2, 'chunk'); // read trailing \r\n
433 }elseif(isset($this->resp_headers['content-length']) && !isset($this->resp_headers['transfer-encoding'])){
442 !$this->keep_alive &&
443 $this->max_bodysize &&
444 $this->max_bodysize < $this->resp_headers['content-length']
446 $length = $this->max_bodysize + 1;
448 $length = $this->resp_headers['content-length'];
451 $r_body = $this->readData($socket, $length, 'response (content-length limited)', true);
452 }elseif( !isset($this->resp_headers['transfer-encoding']) && $this->max_bodysize && !$this->keep_alive){
453 $r_body = $this->readData($socket, $this->max_bodysize+1, 'response (content-length limited)', true);
454 } elseif ((int)$this->status === 204) {
459 $r_body .= $this->readData($socket, 4096, 'response (unlimited)', true);
464 if($this->max_bodysize){
465 if(strlen($r_body) > $this->max_bodysize){
466 if ($this->max_bodysize_abort) {
469 $this->error = 'Allowed response size exceeded';
475 $this->error = $err->getMessage();
477 $this->status = $err->getCode();
483 if (!$this->keep_alive ||
484 (isset($this->resp_headers['connection']) && $this->resp_headers['connection'] == 'Close')) {
491 if(isset($this->resp_headers['content-encoding']) &&
492 $this->resp_headers['content-encoding'] == 'gzip' &&
494 $this->resp_body = @gzinflate(substr($r_body, 10));
495 if($this->resp_body === false){
496 $this->error = 'Failed to decompress gzip encoded content';
497 $this->resp_body = $r_body;
500 $this->resp_body = $r_body;
503 $this->debug('response body',$this->resp_body);
504 $this->redirect_count = 0;
519 if(!$this->useProxyForUrl($requesturl)) return false;
527 if($this->proxy_user) {
528 $request .= 'Proxy-Authorization: Basic '.base64_encode($this->proxy_user.':'.$this->proxy_pass).HTTP_NL;
532 $this->debug('SSL Tunnel CONNECT',$request);
533 $this->sendData($socket, $request, 'SSL Tunnel CONNECT');
538 $r_line = $this->readLine($socket, 'headers');
542 $this->debug('SSL Tunnel Response',$r_headers);
586 $time_used = $this->time() - $this->start;
587 if($time_used > $this->timeout)
619 * @param bool $ignore_eof End-of-file is not an error if this is set
631 $time_used = $this->time() - $this->start;
632 if ($time_used > $this->timeout)
678 $time_used = $this->time() - $this->start;
679 if ($time_used > $this->timeout)
712 if(!$this->debug) return;
714 $this->debugText($info, $var);
716 $this->debugHtml($info, $var);
727 print '<b>'.$info.'</b> '.($this->time() - $this->start).'s<br />';
744 print '*'.$info.'* '.($this->time() - $this->start)."s\n";
818 foreach ($this->cookies as $key => $val){
848 $boundary = '--'.$this->boundary;
891 return $this->proxy_host && (!$this->proxy_except || !preg_match('/' . $this->proxy_except . '/i', $url));