Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Yurunsoft committed Dec 3, 2019
2 parents 59db52f + 910575e commit e76547f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 12 additions & 6 deletions src/YurunHttp/Handler/Swoole.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public function buildRequest($request, $connection, &$http2Request)
{
$http2Request->headers = $headers;
$http2Request->pipeline = $request->getAttribute(Attributes::HTTP2_PIPELINE, false);
$http2Request->path = $uri->getPath();
}
else
{
Expand Down Expand Up @@ -213,7 +214,6 @@ public function send($request)
{
if($isHttp2)
{
$http2Request->path = $path;
$result = $connection->send($http2Request);
}
else
Expand Down Expand Up @@ -323,13 +323,14 @@ private function parseCookies(&$request, $connection, $http2Request)
/**
* 构建 Http2 Response
*
* @param \Swoole\Coroutine\Http2\Client $connection
* @param \Swoole\Http2\Response|bool $response
* @return \Yurun\Util\YurunHttp\Http\Response
*/
public function buildHttp2Response($response)
public function buildHttp2Response($connection, $response)
{
$success = false !== $response;
$result = new Response($success ? $response->data: '', $success ? $response->statusCode : 0);
$result = new Response($response->data ?? '', $success ? $response->statusCode : 0);
if($success)
{
// streamId
Expand All @@ -353,6 +354,11 @@ public function buildHttp2Response($response)
}
$result = $result->withCookieOriginParams($cookies);
}
if($connection)
{
$result = $result->withError(socket_strerror($connection->errCode))
->withErrno($connection->errCode);
}
return $result;
}

Expand All @@ -366,7 +372,7 @@ private function getResponse($connection, $isWebSocket, $isHttp2)
if($isHttp2)
{
$response = $connection->recv();
$this->result = $this->buildHttp2Response($response);
$this->result = $this->buildHttp2Response($connection, $response);
}
else
{
Expand All @@ -392,9 +398,9 @@ private function getResponse($connection, $isWebSocket, $isHttp2)
}
$this->result = $this->result->withCookieOriginParams($cookies);
}
$this->result = $this->result->withError(socket_strerror($connection->errCode))
->withErrno($connection->errCode);
}
$this->result = $this->result->withError(socket_strerror($connection->errCode))
->withErrno($connection->errCode);
return $this->result;
}

Expand Down
2 changes: 1 addition & 1 deletion src/YurunHttp/Http2/SwooleClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public function recv($streamId = -1, $timeout = null)
unset($this->recvChannels[$streamId]);
$channel->close();
}
$response = $this->handler->buildHttp2Response($swooleResponse);
$response = $this->handler->buildHttp2Response($this->http2Client, $swooleResponse);
return $response;
}

Expand Down

0 comments on commit e76547f

Please sign in to comment.