[r6272]: releases / VuFind-1.3 / web / sys / Proxy_Request.php  Maximize  Restore  History

Download this file

114 lines (105 with data), 3.4 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
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
/**
* Proxy Server Support for VuFind
*
* PHP version 5
*
* Copyright (C) Villanova University 2009.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @category VuFind
* @package Support_Classes
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://vufind.org/wiki/system_classes Wiki
*/
// Suppress error output when importing the PEAR HTTP_Request module; some versions
// output deprecation warnings which interfere with AJAX requests in debug mode.
@require_once 'HTTP/Request.php';
/**
* Proxy_Request Class
*
* This is a wrapper class around the PEAR HTTP_Request which adds proxy server
* support.
*
* @category VuFind
* @package Support_Classes
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://vufind.org/wiki/system_classes Wiki
*/
class Proxy_Request extends HTTP_Request
{
private $_useProxy = null;
/**
* Disable the proxy manually
*
* @return void
* @access public
*/
public function disableProxy()
{
$this->_useProxy = false;
}
/**
* Enable the proxy manually
*
* @return void
* @access public
*/
public function useProxy()
{
$this->_useProxy = true;
}
/**
* Time to send the request
*
* @param bool $saveBody Whether to save response body in response object
* property
*
* @return void
* @access public
*/
public function sendRequest($saveBody = true)
{
// Unless the user has expressly set the proxy setting
$defaultProxy = null;
if ($this->_useProxy == null) {
// Is this localhost traffic?
if (strstr($this->getUrl(), "localhost") !== false) {
// Yes, don't proxy
$defaultProxy = false;
}
}
// Setup the proxy if needed
// _useProxy + defaultProxy both need to be null or true
if ($this->_useProxy !== false && $defaultProxy !== false) {
global $configArray;
// Proxy server settings
if (isset($configArray['Proxy']['host'])) {
if (isset($configArray['Proxy']['port'])) {
$this->setProxy(
$configArray['Proxy']['host'], $configArray['Proxy']['port']
);
} else {
$this->setProxy($configArray['Proxy']['host']);
}
}
}
// Send the request via the parent class
parent::sendRequest($saveBody);
}
}
?>

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks