--- a/mnet/xmlrpc/client.php +++ b/mnet/xmlrpc/client.php @@ -359,7 +359,6 @@ class mnet_xmlrpc_client { * @return cURL handle - the almost-ready-to-send http request */ function prepare_http_request ($mnet_peer) { + global $CFG; $this->uri = $mnet_peer->wwwroot . $mnet_peer->application->xmlrpc_server_url; // Initialize request the target URL @@ -368,39 +367,9 @@ class mnet_xmlrpc_client { curl_setopt($httprequest, CURLOPT_RETURNTRANSFER, true); curl_setopt($httprequest, CURLOPT_POST, true); curl_setopt($httprequest, CURLOPT_USERAGENT, 'Moodle'); + curl_setopt($httprequest, CURLOPT_HTTPHEADER, array("Content-Type: text/xml charset=UTF-8", "Expect:")); - curl_setopt($httprequest, CURLOPT_HTTPHEADER, array("Content-Type: text/xml charset=UTF-8")); curl_setopt($httprequest, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($httprequest, CURLOPT_SSL_VERIFYHOST, 0); + + // check for proxy + if (!empty($CFG->proxyhost) and !is_proxybypass($uri)) { + // SOCKS supported in PHP5 only + if (!empty($CFG->proxytype) and ($CFG->proxytype == 'SOCKS5')) { + if (defined('CURLPROXY_SOCKS5')) { + curl_setopt($httprequest, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5); + } else { + curl_close($httprequest); + print_error( 'socksnotsupported','mnet' ); + } + } + + curl_setopt($httprequest, CURLOPT_HTTPPROXYTUNNEL, false); + + if (empty($CFG->proxyport)) { + curl_setopt($httprequest, CURLOPT_PROXY, $CFG->proxyhost); + } else { + curl_setopt($httprequest, CURLOPT_PROXY, $CFG->proxyhost.':'.$CFG->proxyport); + } + + if (!empty($CFG->proxyuser) and !empty($CFG->proxypassword)) { + curl_setopt($httprequest, CURLOPT_PROXYUSERPWD, $CFG->proxyuser.':'.$CFG->proxypassword); + if (defined('CURLOPT_PROXYAUTH')) { + // any proxy authentication if PHP 5.1 + curl_setopt($httprequest, CURLOPT_PROXYAUTH, CURLAUTH_BASIC | CURLAUTH_NTLM); + } + } + } + return $httprequest; } }