Skip to content

[BUG] http 304 响应会导致错误的重定向处理 #3

@NHZEX

Description

@NHZEX
[Argument 1 passed to Yurun\Util\YurunHttp\Http\Psr7\Request::withUri() must implement interface Psr\Http\Message\UriInterface, null given, called in /home/vagrant/code/project/vendor/yurunsoft/yurun-http/src/YurunHttp/Handler/Swoole.php on line 307
#class: TypeError
#0 /home/vagrant/code/project/vendor/yurunsoft/yurun-http/src/YurunHttp/Handler/Swoole.php(307): Yurun\Util\YurunHttp\Http\Psr7\Request->withUri(NULL)
#1 /home/vagrant/code/project/vendor/yurunsoft/yurun-http/src/YurunHttp/Handler/Swoole.php(189): Yurun\Util\YurunHttp\Handler\Swoole->recvDefer(Object(Yurun\Util\YurunHttp\Http\Request))
#2 /home/vagrant/code/project/vendor/yurunsoft/yurun-http/src/YurunHttp.php(97): Yurun\Util\YurunHttp\Handler\Swoole->send(Object(Yurun\Util\YurunHttp\Http\Request))
#3 /home/vagrant/code/project/vendor/yurunsoft/yurun-http/src/HttpRequest.php(756): Yurun\Util\YurunHttp::send(Object(Yurun\Util\YurunHttp\Http\Request), Object(Yurun\Util\YurunHttp\Handler\Swoole))
#4 /home/vagrant/code/project/vendor/yurunsoft/yurun-http/src/HttpRequest.php(795): Yurun\Util\HttpRequest->send('http://devimage...', Array, 'GET')
#5 /home/vagrant/code/project/App/HttpController/Auth.php(231): Yurun\Util\HttpRequest->get('http://devimage...')
#6 /home/vagrant/code/project/App/HttpController/Auth.php(182): App\HttpController\Auth->handleM3u8('iphone/samples/...', Array)
#7 /home/vagrant/code/project/vendor/easyswoole/http/src/AbstractInterface/Controller.php(115): App\HttpController\Auth->index()
#8 /home/vagrant/code/project/vendor/easyswoole/http/src/Dispatcher.php(182): EasySwoole\Http\AbstractInterface\Controller->__hook('index', Object(EasySwoole\Http\Request), Object(EasySwoole\Http\Response))
#9 /home/vagrant/code/project/vendor/easyswoole/http/src/Dispatcher.php(137): EasySwoole\Http\Dispatcher->controllerHandler(Object(EasySwoole\Http\Request), Object(EasySwoole\Http\Response), '/Auth')
#10 /home/vagrant/code/project/vendor/easyswoole/easyswoole/src/Core.php(255): EasySwoole\Http\Dispatcher->dispatch(Object(EasySwoole\Http\Request), Object(EasySwoole\Http\Response))

if(!$isWebSocket && $statusCode >= 300 && $statusCode < 400 && $request->getAttribute(Attributes::FOLLOW_LOCATION, true))
{
if(++$redirectCount <= ($maxRedirects = $request->getAttribute(Attributes::MAX_REDIRECTS, 10)))
{
// 自己实现重定向
$uri = $this->parseRedirectLocation($this->result->getHeaderLine('location'), $request->getUri());
if(in_array($statusCode, [301, 302, 303]))
{
$method = 'GET';
}
else
{
$method = $request->getMethod();
}
return $this->send($request->withMethod($method)->withUri($uri)->withAttribute(Attributes::PRIVATE_REDIRECT_COUNT, $redirectCount));
}
else
{
$this->result = $this->result->withErrno(-1)
->withError(sprintf('Maximum (%s) redirects followed', $maxRedirects));
return false;
}
}

http code 的定义:
https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Status

location 只有 301、302、303、307、308 才会存在
https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Location

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions