Skip to content

Commit

Permalink
Fix the retry, change the http-bin server.
Browse files Browse the repository at this point in the history
  • Loading branch information
twose committed Apr 30, 2018
1 parent 8b8e3ca commit 08346c5
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion examples/basic-auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
'password' => md5(openssl_random_pseudo_bytes(6))
];
echo Saber::get(
"http://httpbin.org/basic-auth/{$auth['username']}/{$auth['password']}",
"http://eu.httpbin.org/basic-auth/{$auth['username']}/{$auth['password']}",
['auth' => $auth]
);
});
2 changes: 1 addition & 1 deletion examples/before_redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

go(function () {
echo Saber::get(
'http://httpbin.org/redirect-to?url=http://www.twosee.cn', [
'http://eu.httpbin.org/redirect-to?url=http://www.twosee.cn', [
'before_redirect' => function (Saber\Request $request) {
echo 'redirect to: ' . $request->getUri() . "\n\n";
return false; //use false ret val to shutdown redirect
Expand Down
2 changes: 1 addition & 1 deletion examples/create-multi.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
require __DIR__ . '/../vendor/autoload.php';

go(function () {
$saber = Saber::create(['base_uri' => 'http://httpbin.org']);
$saber = Saber::create(['base_uri' => 'http://eu.httpbin.org']);
echo $saber->requests([
['get', '/get'],
['delete', '/delete'],
Expand Down
2 changes: 1 addition & 1 deletion examples/create.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

go(function () {
$saber = Saber::create([
'base_uri' => 'http://httpbin.org',
'base_uri' => 'http://eu.httpbin.org',
'headers' => [
'Accept-Language' => 'en,zh-CN;q=0.9,zh;q=0.8',
'Content-Type' => ContentType::JSON,
Expand Down
4 changes: 2 additions & 2 deletions examples/data-parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
go(function () {
[$json, $xml, $html] = Saber::list([
'uri' => [
'http://httpbin.org/get',
'http://eu.httpbin.org/get',
'http://www.w3school.com.cn/example/xmle/note.xml',
'http://httpbin.org/html'
'http://eu.httpbin.org/html'
]
]);
var_dump($json->getParsedJsonArray());
Expand Down
2 changes: 1 addition & 1 deletion examples/exception_handle.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
echo get_class($e) . " is caught!";
return true;
});
Saber::get('http://httpbin.org/redirect/10');
Saber::get('http://eu.httpbin.org/redirect/10');
});
4 changes: 2 additions & 2 deletions examples/exception_report.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
go(function () {
//redirect exception
try {
Saber::get('http://httpbin.org/redirect/10');
Saber::get('http://eu.httpbin.org/redirect/10');
} catch (\Exception$e) {
echo get_class($e) . " occurs!\n";
}
Expand All @@ -23,6 +23,6 @@
HttpExceptionMask::E_ALL ^ HttpExceptionMask::E_REDIRECT
);

Saber::get('http://httpbin.org/redirect/10');
Saber::get('http://eu.httpbin.org/redirect/10');
echo "No exception";
});
2 changes: 1 addition & 1 deletion examples/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
'http://www.qq.com/',
'https://www.baidu.com/',
'https://www.swoole.com/',
'http://httpbin.org/'
'http://eu.httpbin.org/'
]
]);
echo "success: $res->success_num, error: $res->error_num";
Expand Down
2 changes: 1 addition & 1 deletion examples/psr.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
go(function () {
$response = Saber::psr()
->withMethod('POST')
->withUri(new Uri('http://httpbin.org/post?foo=bar'))
->withUri(new Uri('http://eu.httpbin.org/post?foo=bar'))
->withQueryParams(['foo' => 'option is higher-level than uri'])
->withHeader('content-type', ContentType::JSON)
->withBody(new BufferStream(json_encode(['foo' => 'bar'])))
Expand Down
4 changes: 2 additions & 2 deletions examples/session.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

go(function () {
$session = Saber::session([
'base_uri' => 'http://httpbin.org',
'redirect' => 0,
'base_uri' => 'http://eu.httpbin.org',
// 'redirect' => 0,
'exception_report' => HttpExceptionMask::E_ALL ^ HttpExceptionMask::E_REDIRECT
]);
$session->get('/cookies/set?foo=bar&k=v&apple=banana');
Expand Down
10 changes: 5 additions & 5 deletions examples/static.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
require __DIR__ . '/../vendor/autoload.php';

go(function () {
echo "[GET]\n" . Saber::get('http://httpbin.org/get')->statusCode . "\n";
echo "[POST]\n" . Saber::post('http://httpbin.org/post')->statusCode . "\n";
echo "[PUT]\n" . Saber::put('http://httpbin.org/put')->statusCode . "\n";
echo "[PATCH]\n" . Saber::patch('http://httpbin.org/patch')->statusCode . "\n";
echo "[DELETE]\n" . Saber::delete('http://httpbin.org/delete')->statusCode . "\n";
echo "[GET]\n" . Saber::get('http://eu.httpbin.org/get')->statusCode . "\n";
echo "[POST]\n" . Saber::post('http://eu.httpbin.org/post')->statusCode . "\n";
echo "[PUT]\n" . Saber::put('http://eu.httpbin.org/put')->statusCode . "\n";
echo "[PATCH]\n" . Saber::patch('http://eu.httpbin.org/patch')->statusCode . "\n";
echo "[DELETE]\n" . Saber::delete('http://eu.httpbin.org/delete')->statusCode . "\n";
});
2 changes: 1 addition & 1 deletion examples/upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
ContentType::get('png')
);

echo Saber::post('http://httpbin.org/post', null, [
echo Saber::post('http://eu.httpbin.org/post', null, [
'files' => [
'image1' => $file1,
'image2' => $file2,
Expand Down
2 changes: 1 addition & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ public static function transOptionsToRequest(array $options, Request $request)
$request->withRetryTime($options['retry_time']);
}
/** register interceptor before every retry */
if (isset($options['retry'])) {
if (!empty($options['retry'])) {
if ($request->getRetryTime() < 1) {
$request->withRetryTime(1);
}
Expand Down
30 changes: 15 additions & 15 deletions tests/SaberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ public function testShortUri()
public function testStaticAndRequests()
{
$responses = Saber::requests([
['get', 'http://httpbin.org/get'],
['delete', 'http://httpbin.org/delete'],
['post', 'http://httpbin.org/post', ['foo' => 'bar']],
['patch', 'http://httpbin.org/patch', ['foo' => 'bar']],
['put', 'http://httpbin.org/put', ['foo' => 'bar']],
['get', 'http://eu.httpbin.org/get'],
['delete', 'http://eu.httpbin.org/delete'],
['post', 'http://eu.httpbin.org/post', ['foo' => 'bar']],
['patch', 'http://eu.httpbin.org/patch', ['foo' => 'bar']],
['put', 'http://eu.httpbin.org/put', ['foo' => 'bar']],
]);
$this->assertEquals(0, $responses->error_num);
}

public function testInstanceAndRequests()
{
$saber = Saber::create(['base_uri' => 'http://httpbin.org']);
$saber = Saber::create(['base_uri' => 'http://eu.httpbin.org']);
$responses = $saber->requests([
['get', '/get'],
['delete', '/delete'],
Expand All @@ -59,9 +59,9 @@ public function testDataParser()
{
[$json, $xml, $html] = Saber::list([
'uri' => [
'http://httpbin.org/get',
'http://eu.httpbin.org/get',
'https://www.javatpoint.com/xmlpages/books.xml',
'http://httpbin.org/html'
'http://eu.httpbin.org/html'
]
]);
$this->assertEquals((string)$json->uri, $json->getParsedJsonArray()['url']);
Expand All @@ -76,7 +76,7 @@ public function testDataParser()
public function testSessionAndUriQuery()
{
$session = Saber::session([
'base_uri' => 'http://httpbin.org',
'base_uri' => 'http://eu.httpbin.org',
'redirect' => 0,
'exception_report' => HttpExceptionMask::E_ALL ^ HttpExceptionMask::E_REDIRECT
]);
Expand All @@ -97,11 +97,11 @@ public function testExceptions()
$this->expectException(ConnectException::class);
$saber->get('http://foo.bar');
$this->expectException(ClientException::class);
$saber->get('http://httpbin.org/status/401');
$saber->get('http://eu.httpbin.org/status/401');
$this->expectException(ServerException::class);
$saber->get('http://httpbin.org/status/500');
$saber->get('http://eu.httpbin.org/status/500');
$this->expectException(TooManyRedirectsException::class);
$saber->get('http://httpbin.org//redirect/1', ['redirect' => 0]);
$saber->get('http://eu.httpbin.org//redirect/1', ['redirect' => 0]);
}

/**
Expand All @@ -114,7 +114,7 @@ public function testExceptionHandle()
$exception = get_class($e);
return true;
});
$saber->get('http://httpbin.org/status/500');
$saber->get('http://eu.httpbin.org/status/500');
$this->assertEquals(ServerException::class, $exception);
}

Expand All @@ -135,7 +135,7 @@ public function testUploadFiles()
ContentType::get('png')
);

$res = Saber::post('http://httpbin.org/post', null, [
$res = Saber::post('http://eu.httpbin.org/post', null, [
'files' => [
'image1' => $file1,
'image2' => $file2,
Expand Down Expand Up @@ -177,7 +177,7 @@ public function testList()
$uri_list = [
'http://www.qq.com/',
'https://www.baidu.com/',
'http://httpbin.org/'
'http://eu.httpbin.org/'
];
$res = Saber::list(['uri' => $uri_list]);
$this->assertEquals(count($uri_list), $res->success_num);
Expand Down

0 comments on commit 08346c5

Please sign in to comment.