Skip to content

Commit

Permalink
added per element update of foudnatio headers
Browse files Browse the repository at this point in the history
  • Loading branch information
jshannon63 committed Dec 1, 2017
1 parent 2cea600 commit 3f383b4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
20 changes: 18 additions & 2 deletions src/Psr15MiddlewareDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@ function ($carry, $item) use ($psr7request, $requestHandler) {
$requestHandler->handle($psr7request)
);

return (new HttpFoundationFactory())->createResponse($psr7response);
return $this->convertResponse($psr7response, $response);
}
}

private function convertResponse($psr7response, $original)
{
$foundation_response = (new HttpFoundationFactory())->createResponse($psr7response);

foreach ($foundation_response->headers as $key => $value) {
$original->headers->set($key, $value);
}
$original->setContent($foundation_response->getContent());
$original->setProtocolVersion($foundation_response->getProtocolVersion());
$original->setStatusCode($foundation_response->getStatusCode());
$original->setCharset($foundation_response->getCharset());

return $original;
}
}

4 changes: 2 additions & 2 deletions src/Psr15MiddlewareServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function boot()
$this->app->singleton('Psr15Middleware', function () use ($config) {
return new \Jshannon63\Psr15Middleware\Psr15Middleware($config, 'middleware');
});
$this->app[\Illuminate\Contracts\Http\Kernel::class]->prependMiddleware('Psr15Middleware');
$this->app[\Illuminate\Contracts\Http\Kernel::class]->pushMiddleware('Psr15Middleware');
}

foreach ($config->get('psr15middleware.groups') as $key => $group) {
Expand All @@ -35,7 +35,7 @@ public function boot()
$this->app->singleton('Psr15MiddlewareGroup'.title_case($key), function () use ($config, $key) {
return new \Jshannon63\Psr15Middleware\Psr15Middleware($config, 'groups.'.$key);
});
$this->app['router']->prependMiddlewareToGroup($key, 'Psr15MiddlewareGroup'.title_case($key));
$this->app['router']->pushMiddlewareToGroup($key, 'Psr15MiddlewareGroup'.title_case($key));
}

foreach ($config->get('psr15middleware.aliases') as $key => $alias) {
Expand Down

0 comments on commit 3f383b4

Please sign in to comment.