File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the jiannei/laravel-response.
5
+ *
6
+
7
+ *
8
+ * This source file is subject to the MIT license that is bundled
9
+ * with this source code in the file LICENSE.
10
+ */
11
+
12
+ namespace Jiannei \Response \Laravel \Http \Middleware ;
13
+
14
+ use Closure ;
15
+ use Illuminate \Http \Request ;
16
+ use Illuminate \Support \Str ;
17
+
18
+ class SetAcceptHeader
19
+ {
20
+ /**
21
+ * Handle an incoming request.
22
+ *
23
+ * @param \Illuminate\Http\Request $request
24
+ * @param \Closure $next
25
+ * @param string $type
26
+ *
27
+ * @return \Illuminate\Http\Response
28
+ */
29
+ public function handle (Request $ request , Closure $ next , string $ type = 'json ' )
30
+ {
31
+ Str::contains ($ request ->header ('Accept ' ), $ contentType = "application/ $ type " ) or
32
+ $ request ->headers ->set ('Accept ' , $ contentType );
33
+
34
+ return $ next ($ request );
35
+ }
36
+ }
You can’t perform that action at this time.
0 commit comments