Skip to content

Commit 0b34e66

Browse files
authored
Merge pull request #402 from qiniu/fix/redirect-header
fix header not correct if redirect
2 parents a6c911e + 8d03b12 commit 0b34e66

File tree

5 files changed

+20
-1
lines changed

5 files changed

+20
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Next Version
44
* 对象存储,修复无法对 key 为空字符串的对象进行操作
5+
* 修复 301 重定向无法正确获取 header 信息
56

67
## 7.8.0 (2022-10-25)
78
* 移除不推荐域名,并增加区域亚太-首尔和华东-浙江2

src/Qiniu/Http/Header.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ public function __construct($obj = array())
3535
*/
3636
public static function parseRawText($raw)
3737
{
38+
$multipleHeaders = explode("\r\n\r\n", trim($raw));
3839
$headers = array();
39-
$headerLines = explode("\r\n", $raw);
40+
$headerLines = explode("\r\n", end($multipleHeaders));
4041
foreach ($headerLines as $line) {
4142
$headerLine = trim($line);
4243
$kv = explode(':', $headerLine);

tests/Qiniu/Tests/HttpTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ public function testGetTimeout()
3232
$this->assertEquals(-1, $response->statusCode);
3333
}
3434

35+
public function testGetRedirect()
36+
{
37+
$response = Client::get('localhost:9000/redirect.php');
38+
$this->assertEquals(200, $response->statusCode);
39+
$this->assertEquals('application/json;charset=UTF-8', $response->normalizedHeaders['Content-Type']);
40+
$respData = $response->json();
41+
$this->assertEquals('ok', $respData['msg']);
42+
}
43+
3544
public function testDelete()
3645
{
3746
$response = Client::delete('uc.qbox.me/bucketTagging', array());

tests/mock-server/ok.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
header("Content-Type: application/json;charset=UTF-8");
3+
echo '{"msg": "ok"}';

tests/mock-server/redirect.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
header("Content-Type: text/plain;charset=UTF-8", true);
3+
header("Location: ./ok.php", true, 301);
4+
echo "redirect to ok.php";
5+
exit();

0 commit comments

Comments
 (0)