diff options
-rwxr-xr-x | library/SSRS/Soap/NTLM.php | 41 | ||||
-rwxr-xr-x | tests/library/SSRSTest/Soap/NTLMTest.php | 36 |
2 files changed, 64 insertions, 13 deletions
diff --git a/library/SSRS/Soap/NTLM.php b/library/SSRS/Soap/NTLM.php index cc5b0fd..7f75db7 100755 --- a/library/SSRS/Soap/NTLM.php +++ b/library/SSRS/Soap/NTLM.php @@ -131,24 +131,13 @@ class NTLM extends \SoapClient { curl_setopt($handle, CURLOPT_FOLLOWLOCATION, true); curl_setopt($handle, CURLOPT_HTTPAUTH, CURLAUTH_NTLM); - $headers = array( - 'Method: ' . (($data === null) ? 'GET' : 'POST'), - 'Connection: Keep-Alive', - 'User-Agent: PHP-SOAP-CURL', - ); + $headers = $this->generateHeaders($url, $data, $action); + curl_setopt($handle, CURLOPT_HTTPHEADER, $headers); if ($data !== null) { - $headers[] = 'Content-Type: text/xml; charset=utf-8'; - $headers[] = 'Content-Length: ' . strlen($data); curl_setopt($handle, CURLOPT_POSTFIELDS, $data); } - if ($action !== null) { - $headers[] = 'SOAPAction: "' . $action . '"'; - } - - curl_setopt($handle, CURLOPT_HTTPHEADER, $headers); - $response = curl_exec($handle); if ($response === false) { throw new SSRS_Soap_Exception('CURL error: ' . curl_error($handle), curl_errno($handle)); @@ -174,4 +163,30 @@ class NTLM extends \SoapClient { return $this->_lastResponse; } + /** + * + * @param string $url + * @param mixed $data + * @param string $action + * @return array + */ + public function generateHeaders($url, $data = null, $action = null) { + $headers = array( + 'Method: ' . (($data === null) ? 'GET' : 'POST'), + 'Connection: Keep-Alive', + 'User-Agent: PHP-SOAP-CURL', + ); + + if ($data !== null) { + $headers[] = 'Content-Type: text/xml; charset=utf-8'; + $headers[] = 'Content-Length: ' . strlen($data); + } + + if ($action !== null) { + $headers[] = 'SOAPAction: "' . $action . '"'; + } + + return $headers; + } + } diff --git a/tests/library/SSRSTest/Soap/NTLMTest.php b/tests/library/SSRSTest/Soap/NTLMTest.php index db0970b..d7c6fd3 100755 --- a/tests/library/SSRSTest/Soap/NTLMTest.php +++ b/tests/library/SSRSTest/Soap/NTLMTest.php @@ -106,4 +106,40 @@ class NTLMTest extends \PHPUnit_Framework_TestCase { ->cacheWSDL('$fileContents'); } + public function testGenerateHeadersNoData() { + $ntlm = new \SSRS\Soap\NTLM('http://'); + $headers = $ntlm->generateHeaders('http://localhost/reports/'); + + $this->assertEquals(array( + 'Method: GET', + 'Connection: Keep-Alive', + 'User-Agent: PHP-SOAP-CURL', + ), $headers); + } + + public function testGenerateHeadersWithData() { + $ntlm = new \SSRS\Soap\NTLM('http://'); + $headers = $ntlm->generateHeaders('http://localhost/reports/', 'data'); + + $this->assertEquals(array( + 'Method: POST', + 'Connection: Keep-Alive', + 'User-Agent: PHP-SOAP-CURL', + 'Content-Type: text/xml; charset=utf-8', + 'Content-Length: 4' + ), $headers); + } + + public function testGenerateHeadersWithAction() { + $ntlm = new \SSRS\Soap\NTLM('http://'); + $headers = $ntlm->generateHeaders('http://localhost/reports/', null, 'TEST'); + + $this->assertEquals(array( + 'Method: GET', + 'Connection: Keep-Alive', + 'User-Agent: PHP-SOAP-CURL', + 'SOAPAction: "TEST"' + ), $headers); + } + } |