Skip to content

Commit

Permalink
Fix non-redirect failure (#113)
Browse files Browse the repository at this point in the history
* Fix non-redirect failure

* update

* Fix tests

* Add test
  • Loading branch information
sy-records committed Jan 6, 2021
1 parent 89becdd commit ebdcd68
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README-EN.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 9 additions & 2 deletions tests/SaberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}

/**
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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 !== '');
}
}

0 comments on commit ebdcd68

Please sign in to comment.