Skip to content
Snippets Groups Projects
Commit 6aad717e authored by Andreas Gohr's avatar Andreas Gohr
Browse files

show more info on failed HTTP requests

hopefully this will help with figuring out why our HTTP tests sometimes
fail on travis.
parent 92ca36ed
No related branches found
No related tags found
No related merge requests found
......@@ -16,7 +16,7 @@ class httpclient_http_test extends DokuWikiTest {
$this->markTestSkipped('connection timed out');
return;
}
$this->assertFalse($data === false, 'HTTP response '.$http->error);
$this->assertFalse($data === false, $http->errorInfo());
$resp = json_decode($data, true);
$this->assertTrue(is_array($resp), 'JSON response');
$this->assertArrayHasKey('args',$resp);
......@@ -33,7 +33,7 @@ class httpclient_http_test extends DokuWikiTest {
$this->markTestSkipped('connection timed out');
return;
}
$this->assertFalse($data === false, 'HTTP response '.$http->error);
$this->assertFalse($data === false, $http->errorInfo());
$resp = json_decode($data, true);
$this->assertTrue(is_array($resp), 'JSON response');
$this->assertArrayHasKey('args',$resp);
......@@ -50,7 +50,7 @@ class httpclient_http_test extends DokuWikiTest {
$this->markTestSkipped('connection timed out');
return;
}
$this->assertFalse($data === false, 'HTTP response '.$http->error);
$this->assertFalse($data === false, $http->errorInfo());
$resp = json_decode($data, true);
$this->assertTrue(is_array($resp), 'JSON response');
$this->assertArrayHasKey('gzipped',$resp);
......@@ -67,7 +67,7 @@ class httpclient_http_test extends DokuWikiTest {
$this->markTestSkipped('connection timed out');
return;
}
$this->assertFalse($data === false, 'HTTP response '.$http->error);
$this->assertFalse($data === false, $http->errorInfo());
$resp = json_decode($data, true);
$this->assertTrue(is_array($resp), 'JSON response');
$this->assertArrayHasKey('form',$resp);
......@@ -84,7 +84,7 @@ class httpclient_http_test extends DokuWikiTest {
$this->markTestSkipped('connection timed out');
return;
}
$this->assertFalse($data === false, 'HTTP response '.$http->error);
$this->assertFalse($data === false, $http->errorInfo());
$resp = json_decode($data, true);
$this->assertTrue(is_array($resp), 'JSON response');
$this->assertArrayHasKey('url',$resp);
......@@ -101,7 +101,7 @@ class httpclient_http_test extends DokuWikiTest {
$this->markTestSkipped('connection timed out');
return;
}
$this->assertFalse($data === false, 'HTTP response '.$http->error);
$this->assertFalse($data === false, $http->errorInfo());
$resp = json_decode($data, true);
$this->assertTrue(is_array($resp), 'JSON response');
$this->assertArrayHasKey('url',$resp);
......@@ -118,7 +118,7 @@ class httpclient_http_test extends DokuWikiTest {
$this->markTestSkipped('connection timed out');
return;
}
$this->assertTrue($data === false, 'HTTP response '.$http->error);
$this->assertTrue($data === false, $http->errorInfo());
$this->assertEquals('Maximum number of redirects exceeded',$http->error);
}
......@@ -138,7 +138,7 @@ class httpclient_http_test extends DokuWikiTest {
$this->markTestSkipped('connection timed out');
return;
}
$this->assertFalse($data === false, 'HTTP response '.$http->error);
$this->assertFalse($data === false, $http->errorInfo());
$resp = json_decode($data, true);
$this->assertTrue(is_array($resp), 'JSON response');
$this->assertArrayHasKey('cookies',$resp);
......@@ -155,7 +155,7 @@ class httpclient_http_test extends DokuWikiTest {
$this->markTestSkipped('connection timed out');
return;
}
$this->assertTrue($data === false, 'HTTP response '.$http->error);
$this->assertTrue($data === false, $http->errorInfo());
$this->assertEquals(418,$http->status);
}
......@@ -172,7 +172,7 @@ class httpclient_http_test extends DokuWikiTest {
$this->markTestSkipped('connection timed out');
return;
}
$this->assertTrue($data === false, 'HTTP response '.$http->error);
$this->assertTrue($data === false, $http->errorInfo());
// this should read just the needed bytes
$http->max_bodysize_abort = false;
......@@ -182,7 +182,7 @@ class httpclient_http_test extends DokuWikiTest {
$this->markTestSkipped('connection timed out');
return;
}
$this->assertFalse($data === false, 'HTTP response '.$http->error);
$this->assertFalse($data === false, $http->errorInfo());
/* should read no more than max_bodysize+1 */
$this->assertLessThanOrEqual(251,strlen($data));
}
......@@ -198,14 +198,14 @@ class httpclient_http_test extends DokuWikiTest {
$this->markTestSkipped('connection timed out');
return;
}
$this->assertTrue($data !== false, 'HTTP response '.$http->error);
$this->assertTrue($data !== false, $http->errorInfo());
$http->max_bodysize_abort = false;
$data = $http->get($this->server.'/stream/5');
if($http->noconnection()) {
$this->markTestSkipped('connection timed out');
return;
}
$this->assertTrue($data !== false, 'HTTP response '.$http->error);
$this->assertTrue($data !== false, $http->errorInfo());
}
/**
......@@ -220,7 +220,7 @@ class httpclient_http_test extends DokuWikiTest {
$this->markTestSkipped('connection timed out');
return;
}
$this->assertFalse($data === false, 'HTTP response '.$http->error);
$this->assertFalse($data === false, $http->errorInfo());
$resp = json_decode($data, true);
$this->assertTrue(is_array($resp), 'JSON response');
$this->assertEquals(array('authenticated'=>true,'user'=>'user'), $resp);
......@@ -238,7 +238,7 @@ class httpclient_http_test extends DokuWikiTest {
$this->markTestSkipped('connection timed out');
return;
}
$this->assertTrue($data === false, 'HTTP response '.$http->error);
$this->assertTrue($data === false, $http->errorInfo());
$this->assertEquals(401,$http->status);
}
......@@ -249,7 +249,7 @@ class httpclient_http_test extends DokuWikiTest {
$http = new HTTPMockClient();
$http->timeout = 5;
$data = $http->get($this->server.'/delay/10');
$this->assertTrue($data === false, 'HTTP response '.$http->error);
$this->assertTrue($data === false, $http->errorInfo());
$this->assertEquals(-100,$http->status);
}
......@@ -263,7 +263,7 @@ class httpclient_http_test extends DokuWikiTest {
$this->markTestSkipped('connection timed out');
return;
}
$this->assertFalse($data === false, 'HTTP response '.$http->error);
$this->assertFalse($data === false, $http->errorInfo());
$resp = json_decode($data, true);
$this->assertTrue(is_array($resp), 'JSON response');
$this->assertArrayHasKey('baz',$http->resp_headers);
......@@ -281,7 +281,7 @@ class httpclient_http_test extends DokuWikiTest {
$this->markTestSkipped('connection timed out');
return;
}
$this->assertFalse($data === false, 'HTTP response '.$http->error);
$this->assertFalse($data === false, $http->errorInfo());
$this->assertEquals(2550,strlen($data));
}
......@@ -298,7 +298,7 @@ class httpclient_http_test extends DokuWikiTest {
$this->markTestSkipped('connection timed out');
return;
}
$this->assertTrue($data !== false, 'HTTP response '.$http->error);
$this->assertTrue($data !== false, $http->errorInfo());
}
function test_postencode(){
......
......@@ -15,7 +15,7 @@ class httpclient_http_proxy_test extends DokuWikiTest {
$http->proxy_port = 8080;
$data = $http->get($this->url);
$this->assertFalse($data === false, 'HTTP response: '.$http->error.' ['.$this->url.']');
$this->assertFalse($data === false, $http->errorInfo($this->url));
$this->assertTrue(strpos($data,'DokuWiki') !== false, 'response content');
}
}
......@@ -11,7 +11,7 @@ class HTTPMockClient extends HTTPClient {
/**
* Sets shorter timeout
*/
function __construct() {
public function __construct() {
parent::__construct();
$this->timeout = 8; // slightly faster timeouts
}
......@@ -21,7 +21,7 @@ class HTTPMockClient extends HTTPClient {
*
* @return bool
*/
function noconnection() {
public function noconnection() {
return ($this->tries === 0);
}
......@@ -33,7 +33,7 @@ class HTTPMockClient extends HTTPClient {
* @param string $method
* @return bool
*/
function sendRequest($url, $data = '', $method = 'GET') {
public function sendRequest($url, $data = '', $method = 'GET') {
$this->tries = 2; // configures the number of retries
$return = false;
while($this->tries) {
......@@ -43,4 +43,21 @@ class HTTPMockClient extends HTTPClient {
}
return $return;
}
}
\ No newline at end of file
/**
* Return detailed error data
*
* @param string $info optional additional info
* @return string
*/
public function errorInfo($info = '') {
return json_encode(
array(
'Error' => $this->error,
'Status' => $this->status,
'Body' => $this->resp_body,
'Info' => $info
), JSON_PRETTY_PRINT
);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment