Lines Matching +full:check +full:- +full:pass -(+path:inc +path:lang) -(+path:lib +path:plugins +path:lang) -(+path:lib +path:tpl +path:dokuwiki +path:lang)

18  * @author Tobias Sarnowski <sarnowski@new-thoughts.org>
48 public $pass;
61 // what we use as boundary on multipart/form-data posts
62 protected $boundary = '---DokuWikiHTTPClient--4523452351';
71 $this->agent = 'Mozilla/4.0 (compatible; DokuWiki HTTP Client; ' . PHP_OS . ')';
72 if (extension_loaded('zlib')) $this->headers['Accept-encoding'] = 'gzip';
73 $this->headers['Accept'] = 'text/xml,application/xml,application/xhtml+xml,' .
75 $this->headers['Accept-Language'] = 'en-us';
92 if (!$this->sendRequest($url)) return false;
93 if ($this->status == 304 && $sloppy304) return $this->resp_body;
94 if ($this->status < 200 || $this->status > 206) return false;
95 return $this->resp_body;
120 $url .= $this->postEncode($data);
121 return $this->get($url, $sloppy304);
136 if (!$this->sendRequest($url, $data, 'POST')) return false;
137 if ($this->status < 200 || $this->status > 206) return false;
138 return $this->resp_body;
148 * sent as is. You will need to setup your own Content-Type header then.
150 * @param string $url - the complete URL
151 * @param mixed $data - the post data either as array or raw data
152 * @param string $method - HTTP Method usually GET or POST.
153 * @return bool - true on success
160 $this->start = microtime(true);
161 $this->error = '';
162 $this->status = 0;
163 $this->resp_body = '';
164 $this->resp_headers = [];
171 $this->max_bodysize &&
172 !$this->max_bodysize_abort &&
173 isset($this->headers['Accept-encoding']) &&
174 $this->headers['Accept-encoding'] == 'gzip'
176 unset($this->headers['Accept-encoding']);
185 if (isset($uri['user'])) $this->user = $uri['user'];
186 if (isset($uri['pass'])) $this->pass = $uri['pass'];
189 if ($this->useProxyForUrl($url)) {
191 $server = $this->proxy_host;
192 $port = $this->proxy_port;
194 $use_tls = $this->proxy_ssl;
201 // add SSL stream prefix if needed - needs SSL support in PHP
204 $this->status = -200;
205 $this->error = 'This PHP version does not support SSL - cannot connect to server';
211 $headers = $this->headers;
214 $headers['User-Agent'] = $this->agent;
215 $headers['Referer'] = $this->referer;
219 if (empty($headers['Content-Type'])) {
220 $headers['Content-Type'] = null;
222 if ($headers['Content-Type'] == 'multipart/form-data') {
223 $headers['Content-Type'] = 'multipart/form-data; boundary=' . $this->boundary;
224 $data = $this->postMultipartEncode($data);
226 $headers['Content-Type'] = 'application/x-www-form-urlencoded';
227 $data = $this->postEncode($data);
236 $headers['Content-Length'] = $contentlength;
239 if ($this->user) {
240 $headers['Authorization'] = 'Basic ' . base64_encode($this->user . ':' . $this->pass);
242 if ($this->proxy_user) {
243 $headers['Proxy-Authorization'] = 'Basic ' . base64_encode($this->proxy_user . ':' . $this->proxy_pass);
247 $connectionId = $this->uniqueConnectionId($server, $port);
248 $this->debug('connection pool', self::$connections);
251 $this->debug('reusing connection', $connectionId);
255 $this->debug('opening connection', $connectionId);
257 $socket = @fsockopen($server, $port, $errno, $errstr, $this->timeout);
259 $this->status = -100;
260 $this->error = "Could not connect to $server:$port\n$errstr ($errno)";
266 if ($this->ssltunnel($socket, $request_url)) {
268 $this->keep_alive = false;
270 if (isset($headers['Proxy-Authentication'])) unset($headers['Proxy-Authentication']);
273 $this->status = $e->getCode();
274 $this->error = $e->getMessage();
280 if ($this->keep_alive) {
287 if ($this->keep_alive && !$this->useProxyForUrl($request_url)) {
288 // RFC 2068, section 19.7.1: A client MUST NOT send the Keep-Alive
291 $headers['Connection'] = 'Keep-Alive';
297 //set non-blocking
301 $request = "$method $request_url HTTP/" . $this->http . HTTP_NL;
302 $request .= $this->buildHeaders($headers);
303 $request .= $this->getCookies();
307 $this->debug('request', $request);
308 $this->sendData($socket, $request, 'request');
313 $r_line = $this->readLine($socket, 'headers');
317 $this->debug('response headers', $r_headers);
319 // check if expected body size exceeds allowance
320 if ($this->max_bodysize && preg_match('/\r?\nContent-Length:\s*(\d+)\r?\n/i', $r_headers, $match)) {
321 if ($match[1] > $this->max_bodysize) {
322 if ($this->max_bodysize_abort)
324 else $this->error = 'Reported content length exceeds allowed response size';
332 $this->status = $m[2];
335 $this->resp_headers = $this->parseHeaders($r_headers);
336 if (isset($this->resp_headers['set-cookie'])) {
337 foreach ((array)$this->resp_headers['set-cookie'] as $cookie) {
342 if (isset($this->cookies[$key])) {
343 unset($this->cookies[$key]);
346 $this->cookies[$key] = $val;
351 $this->debug('Object headers', $this->resp_headers);
353 // check server status code to follow redirect
354 if (in_array($this->status, [301, 302, 303, 307, 308])) {
355 if (empty($this->resp_headers['location'])) {
357 } elseif ($this->redirect_count == $this->max_redirect) {
365 $this->redirect_count++;
366 $this->referer = $url;
367 // handle non-RFC-compliant relative redirects
368 if (!preg_match('/^http/i', $this->resp_headers['location'])) {
369 if ($this->resp_headers['location'][0] != '/') {
370 $this->resp_headers['location'] = $uri['scheme'] . '://' . $uri['host'] . ':' . $uriPort .
371 dirname($path) . '/' . $this->resp_headers['location'];
373 $this->resp_headers['location'] = $uri['scheme'] . '://' . $uri['host'] . ':' . $uriPort .
374 $this->resp_headers['location'];
377 if ($this->status == 307 || $this->status == 308) {
379 return $this->sendRequest($this->resp_headers['location'], $unencodedData, $method);
382 return $this->sendRequest($this->resp_headers['location'], [], 'GET');
387 // check if headers are as expected
388 if ($this->header_regexp && !preg_match($this->header_regexp, $r_headers))
395 isset($this->resp_headers['transfer-encoding']) &&
396 $this->resp_headers['transfer-encoding'] == 'chunked'
398 isset($this->resp_headers['transfer-coding']) &&
399 $this->resp_headers['transfer-coding'] == 'chunked'
405 while (preg_match('/^[a-zA-Z0-9]?$/', $byte = $this->readData($socket, 1, 'chunk'))) {
411 $this->readLine($socket, 'chunk'); // readtrailing \n
414 if ($this->max_bodysize && $chunk_size + strlen($r_body) > $this->max_bodysize) {
415 if ($this->max_bodysize_abort)
417 $this->error = 'Allowed response size exceeded';
418 $chunk_size = $this->max_bodysize - strlen($r_body);
423 $r_body .= $this->readData($socket, $chunk_size, 'chunk');
424 $this->readData($socket, 2, 'chunk'); // read trailing \r\n
428 isset($this->resp_headers['content-length']) &&
429 !isset($this->resp_headers['transfer-encoding'])
432 * If a message is received with both a Transfer-Encoding header field and a Content-Length
436 // read up to the content-length or max_bodysize
439 !$this->keep_alive &&
440 $this->max_bodysize &&
441 $this->max_bodysize < $this->resp_headers['content-length']
443 $length = $this->max_bodysize + 1;
445 $length = $this->resp_headers['content-length'];
448 $r_body = $this->readData($socket, $length, 'response (content-length limited)', true);
449 } elseif (!isset($this->resp_headers['transfer-encoding']) && $this->max_bodysize && !$this->keep_alive) {
450 $r_body = $this->readData($socket, $this->max_bodysize + 1, 'response (content-length limited)', true);
451 } elseif ((int)$this->status === 204) {
456 $r_body .= $this->readData($socket, 4096, 'response (unlimited)', true);
461 if ($this->max_bodysize) {
462 if (strlen($r_body) > $this->max_bodysize) {
463 if ($this->max_bodysize_abort) {
466 $this->error = 'Allowed response size exceeded';
471 $this->error = $err->getMessage();
472 if ($err->getCode())
473 $this->status = $err->getCode();
480 !$this->keep_alive ||
481 (isset($this->resp_headers['connection']) && $this->resp_headers['connection'] == 'Close')
490 isset($this->resp_headers['content-encoding']) &&
491 $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;
520 if (!$this->useProxyForUrl($requesturl)) return false;
528 if ($this->proxy_user) {
529 $request .= 'Proxy-Authorization: Basic ' .
530 base64_encode($this->proxy_user . ':' . $this->proxy_pass) . HTTP_NL;
534 $this->debug('SSL Tunnel CONNECT', $request);
535 $this->sendData($socket, $request, 'SSL Tunnel CONNECT');
540 $r_line = $this->readLine($socket, 'headers');
544 $this->debug('SSL Tunnel Response', $r_headers);
566 -151
570 throw new HTTPClientException('Failed to establish secure proxy connection', -150);
589 // check timeout
590 $time_used = microtime(true) - $this->start;
591 if ($time_used > $this->timeout)
592 throw new HTTPClientException(sprintf('Timeout while sending %s (%.3fs)', $message, $time_used), -100);
609 throw new HTTPClientException("Failed writing to socket while sending $message", -100);
620 * @param resource $socket An open socket handle in non-blocking mode
623 * @param bool $ignore_eof End-of-file is not an error if this is set
636 $time_used = microtime(true) - $this->start;
637 if ($time_used > $this->timeout)
645 -100
666 throw new HTTPClientException("Failed reading from socket while reading $message", -100);
668 $to_read -= strlen($bytes);
675 * Safely read a \n-terminated line from a socket
679 * @param resource $socket An open socket handle in non-blocking mode
690 $time_used = microtime(true) - $this->start;
691 if ($time_used > $this->timeout)
694 -100
726 if (!$this->debug) return;
728 $this->debugText($info, $var);
730 $this->debugHtml($info, $var);
742 echo '<b>' . $info . '</b> ' . (microtime(true) - $this->start) . 's<br />';
760 echo '*' . $info . '* ' . (microtime(true) - $this->start) . "s\n";
762 echo "\n-----------------------------------------------\n";
827 foreach ($this->cookies as $key => $val) {
830 $headers = substr($headers, 0, -2);
859 $boundary = '--' . $this->boundary;
864 $out .= 'Content-Disposition: form-data; name="' . urlencode($key) . '"' . HTTP_NL;
869 $out .= 'Content-Disposition: form-data; name="' . urlencode($key) . '"';
872 if ($val['mimetype']) $out .= 'Content-Type: ' . $val['mimetype'] . HTTP_NL;
878 $out .= "$boundary--" . HTTP_NL;
904 return $this->proxy_host && (!$this->proxy_except || !preg_match('/' . $this->proxy_except . '/i', $url));