From 89b34c8bdaf06b10268cab19796cd94684442124 Mon Sep 17 00:00:00 2001 From: Nathan Gass Date: Mon, 13 May 2019 13:47:21 +0200 Subject: add test and fix for 204 http status code --- it_url.class | 2 +- test/it_url.t | 13 +++++++++++++ test/it_url.testserver.php | 4 ++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/it_url.class b/it_url.class index 59ac212..4135789 100644 --- a/it_url.class +++ b/it_url.class @@ -131,7 +131,7 @@ function get($p=null, $timeout=5) $result = $url->request($p + ['followlocation' => true]); - if (!$result && $p['retries'] > 0 && $url->result < 400) + if (!$result && $p['retries'] > 0 && $url->result < 400 && $url->result != 204) { usleep($p['retrysleep']*1000000); $result = $url->get(array('retries' => $p['retries'] - 1) + $p); diff --git a/test/it_url.t b/test/it_url.t index eb36dd6..624b4bf 100755 --- a/test/it_url.t +++ b/test/it_url.t @@ -266,6 +266,19 @@ if (!ok( )) diag($output); +$output = handle_server( + is( + it_url::get(U('http://localhost:8000/empty')), + '', + 'it_url::get() explicit empty result' + ) +); +if (!ok( + count(preg_grep('/^Got Request:/', $output)) == 1, + 'it_url::get() does not retry on explicity empty page' +)) + diag($output); + handle_server( is( it_url::get(U('http://localhost:8000/get_server_value', array('key' => 'HTTP_HOST'))), diff --git a/test/it_url.testserver.php b/test/it_url.testserver.php index 530a505..64e6674 100644 --- a/test/it_url.testserver.php +++ b/test/it_url.testserver.php @@ -65,6 +65,10 @@ switch ($_SERVER['PHP_SELF']) echo $_REQUEST['string']; break; + case "/empty": + http_response_code(204); + break; + default: http_response_code(404); fwrite($stderr, "Unknown path '$_SERVER[PHP_SELF]' not handled!\n"); -- cgit v1.2.3