diff --git a/README-EN.md b/README-EN.md index 0159ec3..d93c4b5 100644 --- a/README-EN.md +++ b/README-EN.md @@ -1,6 +1,6 @@ # Saber -[![Latest Version](https://img.shields.io/github/release/swlib/saber.svg?style=flat-square)](https://github.com/swlib/saber/releases) +[![Latest Version](https://img.shields.io/github/release/swlib/saber.svg)](https://github.com/swlib/saber/releases) [![PHPUnit for Saber](https://github.com/swlib/saber/workflows/PHPUnit%20for%20Saber/badge.svg)](https://github.com/swlib/saber/actions) [![Php Version](https://img.shields.io/badge/php-%3E=7.1-brightgreen.svg?maxAge=2592000)](https://secure.php.net/) [![Swoole Version](https://img.shields.io/badge/swoole-%3E=2.1.2-brightgreen.svg?maxAge=2592000)](https://github.com/swoole/swoole-src) diff --git a/README.md b/README.md index 4ef936c..efc31db 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Saber -[![Latest Version](https://img.shields.io/github/release/swlib/saber.svg?style=flat-square)](https://github.com/swlib/saber/releases) +[![Latest Version](https://img.shields.io/github/release/swlib/saber.svg)](https://github.com/swlib/saber/releases) [![PHPUnit for Saber](https://github.com/swlib/saber/workflows/PHPUnit%20for%20Saber/badge.svg)](https://github.com/swlib/saber/actions) [![Php Version](https://img.shields.io/badge/php-%3E=7.1-brightgreen.svg?maxAge=2592000)](https://secure.php.net/) [![Swoole Version](https://img.shields.io/badge/swoole-%3E=2.1.2-brightgreen.svg?maxAge=2592000)](https://github.com/swoole/swoole-src) diff --git a/src/Response.php b/src/Response.php index e1d7ecb..917663c 100755 --- a/src/Response.php +++ b/src/Response.php @@ -106,7 +106,7 @@ function __construct(Request $request) $this->success = true; break; case 3: - if (!$this->hasHeader('Location')) { + if (!$this->hasHeader('Location') || $request->getRedirect() === 0) { /* not a redirect response */ $this->success = true; break; diff --git a/tests/SaberTest.php b/tests/SaberTest.php index 74ce68b..76d7116 100644 --- a/tests/SaberTest.php +++ b/tests/SaberTest.php @@ -127,7 +127,7 @@ public function testExceptions() $this->expectException(ServerException::class); $saber->get('http://www.httpbin.org/status/500'); $this->expectException(TooManyRedirectsException::class); - $saber->get('http://www.httpbin.org//redirect/1', ['redirect' => 0]); + $saber->get('http://httpbingo.org/redirect/3', ['redirect' => 1]); } /** @@ -316,7 +316,7 @@ public function testDownload() public function testBeforeRedirect() { $response = SaberGM::get( - 'http://www.httpbingo.org/redirect-to?url=https://www.qq.com/', + 'http://httpbingo.org/redirect-to?url=https://www.qq.com/', [ 'before_redirect' => function (Saber\Request $request) { $this->assertEquals('https://www.qq.com/', (string)$request->getUri()); @@ -420,4 +420,11 @@ public function testPostDataAndUploadFile() $this->assertEquals($array['form']['foo'], 'bar'); } + + public function testNonRedirect() + { + $saber = Saber::create(['exception_report' => true]); + $res = $saber->get('http://baidu.com', ['redirect' => 0]); + $this->assertTrue((string)$res->body !== ''); + } }