Skip to content

Commit

Permalink
feat(middleware): accept header (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaiyuxin103 committed Apr 6, 2024
1 parent d12ce73 commit 78c5ea9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
22 changes: 22 additions & 0 deletions app/Http/Middleware/AcceptHeader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class AcceptHeader
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
$request->headers->set('Accept', 'application/json');

return $next($request);
}
}
4 changes: 3 additions & 1 deletion bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
//
$middleware->api(prepend: [
\App\Http\Middleware\AcceptHeader::class,
]);
})
->withExceptions(function (Exceptions $exceptions) {
//
Expand Down

0 comments on commit 78c5ea9

Please sign in to comment.