Skip to content

Commit ebdcd68

Browse files
authored
Fix non-redirect failure (#113)
* Fix non-redirect failure * update * Fix tests * Add test
1 parent 89becdd commit ebdcd68

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

README-EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Saber
22

3-
[![Latest Version](https://img.shields.io/github/release/swlib/saber.svg?style=flat-square)](https://github.com/swlib/saber/releases)
3+
[![Latest Version](https://img.shields.io/github/release/swlib/saber.svg)](https://github.com/swlib/saber/releases)
44
[![PHPUnit for Saber](https://github.com/swlib/saber/workflows/PHPUnit%20for%20Saber/badge.svg)](https://github.com/swlib/saber/actions)
55
[![Php Version](https://img.shields.io/badge/php-%3E=7.1-brightgreen.svg?maxAge=2592000)](https://secure.php.net/)
66
[![Swoole Version](https://img.shields.io/badge/swoole-%3E=2.1.2-brightgreen.svg?maxAge=2592000)](https://github.com/swoole/swoole-src)

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Saber
22

3-
[![Latest Version](https://img.shields.io/github/release/swlib/saber.svg?style=flat-square)](https://github.com/swlib/saber/releases)
3+
[![Latest Version](https://img.shields.io/github/release/swlib/saber.svg)](https://github.com/swlib/saber/releases)
44
[![PHPUnit for Saber](https://github.com/swlib/saber/workflows/PHPUnit%20for%20Saber/badge.svg)](https://github.com/swlib/saber/actions)
55
[![Php Version](https://img.shields.io/badge/php-%3E=7.1-brightgreen.svg?maxAge=2592000)](https://secure.php.net/)
66
[![Swoole Version](https://img.shields.io/badge/swoole-%3E=2.1.2-brightgreen.svg?maxAge=2592000)](https://github.com/swoole/swoole-src)

src/Response.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ function __construct(Request $request)
106106
$this->success = true;
107107
break;
108108
case 3:
109-
if (!$this->hasHeader('Location')) {
109+
if (!$this->hasHeader('Location') || $request->getRedirect() === 0) {
110110
/* not a redirect response */
111111
$this->success = true;
112112
break;

tests/SaberTest.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public function testExceptions()
127127
$this->expectException(ServerException::class);
128128
$saber->get('http://www.httpbin.org/status/500');
129129
$this->expectException(TooManyRedirectsException::class);
130-
$saber->get('http://www.httpbin.org//redirect/1', ['redirect' => 0]);
130+
$saber->get('http://httpbingo.org/redirect/3', ['redirect' => 1]);
131131
}
132132

133133
/**
@@ -316,7 +316,7 @@ public function testDownload()
316316
public function testBeforeRedirect()
317317
{
318318
$response = SaberGM::get(
319-
'http://www.httpbingo.org/redirect-to?url=https://www.qq.com/',
319+
'http://httpbingo.org/redirect-to?url=https://www.qq.com/',
320320
[
321321
'before_redirect' => function (Saber\Request $request) {
322322
$this->assertEquals('https://www.qq.com/', (string)$request->getUri());
@@ -420,4 +420,11 @@ public function testPostDataAndUploadFile()
420420

421421
$this->assertEquals($array['form']['foo'], 'bar');
422422
}
423+
424+
public function testNonRedirect()
425+
{
426+
$saber = Saber::create(['exception_report' => true]);
427+
$res = $saber->get('http://baidu.com', ['redirect' => 0]);
428+
$this->assertTrue((string)$res->body !== '');
429+
}
423430
}

0 commit comments

Comments
 (0)