Skip to content

Commit

Permalink
fix: Early interrupt request will result in a wrong response content …
Browse files Browse the repository at this point in the history
…type
  • Loading branch information
inhere committed Jul 29, 2019
1 parent 8106d32 commit f031398
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 39 deletions.
14 changes: 3 additions & 11 deletions src/http-server/src/HttpDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,15 @@ public function dispatch(...$params): void

// Handle request error
$response = $errDispatcher->run($e, $response);

// Format response
$response = $this->acceptFormatter->format($response);
}

// Format response content type
$response = $this->acceptFormatter->format($response);

// Trigger after request
Swoft::trigger(HttpServerEvent::AFTER_REQUEST, null, $response);
}

/**
* @return array
*/
public function preMiddleware(): array
{
return [];
}

/**
* @return array
*/
Expand Down
32 changes: 4 additions & 28 deletions src/http-server/src/Middleware/DefaultMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@

namespace Swoft\Http\Server\Middleware;

use function context;
use function explode;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use ReflectionException;
use ReflectionNamedType;
use function sprintf;
use Swoft;
use Swoft\Bean\Annotation\Mapping\Bean;
use Swoft\Bean\Annotation\Mapping\Inject;
Expand All @@ -25,6 +22,9 @@
use Swoft\Http\Server\Router\Router;
use Swoft\Stdlib\Helper\ObjectHelper;
use Swoft\Stdlib\Helper\PhpHelper;
use function context;
use function explode;
use function sprintf;

/**
* Class DefaultMiddleware
Expand All @@ -35,15 +35,7 @@
class DefaultMiddleware implements MiddlewareInterface
{
/**
* Accept formatter
*
* @var AcceptResponseFormatter
* @Inject()
*/
private $acceptFormatter;

/**
* @param ServerRequestInterface $request
* @param ServerRequestInterface|Request $request
* @param RequestHandlerInterface $handler
*
* @return ResponseInterface
Expand All @@ -53,22 +45,6 @@ class DefaultMiddleware implements MiddlewareInterface
* @throws ContainerException
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$response = $this->handle($request);
$response = $this->acceptFormatter->format($response);
return $response;
}

/**
* @param ServerRequestInterface|Request $request
*
* @return Response
* @throws MethodNotAllowedException
* @throws NotFoundRouteException
* @throws ReflectionException
* @throws ContainerException
*/
private function handle(ServerRequestInterface $request): Response
{
$method = $request->getMethod();
$uriPath = $request->getUriPath();
Expand Down

0 comments on commit f031398

Please sign in to comment.