File tree 3 files changed +39
-3
lines changed
3 files changed +39
-3
lines changed Original file line number Diff line number Diff line change 10
10
},
11
11
"require" : {
12
12
"php" : " >=7.2" ,
13
- "illuminate/http" : " ^7 .0 || ^8 .0 || ^9 .0" ,
14
- "illuminate/contracts" : " ^7 .0 || ^8 .0 || ^9 .0"
13
+ "illuminate/http" : " ^8 .0 || ^9 .0 || ^10 .0" ,
14
+ "illuminate/contracts" : " ^8 .0 || ^9 .0 || ^10 .0"
15
15
},
16
16
"require-dev" : {
17
17
"friendsofphp/php-cs-fixer" : " ^2.16" ,
Original file line number Diff line number Diff line change @@ -9,7 +9,9 @@ class RequestAcceptJson
9
9
{
10
10
public function handle (Request $ request , Closure $ next )
11
11
{
12
- if (!$ request ->headers ->has ('Accept ' )) {
12
+ $ accept = $ request ->headers ->get ('Accept ' );
13
+
14
+ if ($ accept === null || $ accept === '*/* ' || $ accept === 'application/* ' ) {
13
15
$ request ->headers ->set ('Accept ' , 'application/json ' );
14
16
}
15
17
Original file line number Diff line number Diff line change @@ -25,6 +25,40 @@ function ($request) {
25
25
$ this ->assertSame ('application/json ' , $ result ->header ('Accept ' ));
26
26
}
27
27
28
+ /**
29
+ * @test
30
+ */
31
+ public function whenItReceivesWildcardAcceptHeaderItShouldSetToApplicationJson ()
32
+ {
33
+ $ mockRequest = $ this ->getRequest (['Accept ' => '*/* ' ]);
34
+ $ middleware = new RequestAcceptJson ();
35
+
36
+ $ result = $ middleware ->handle (
37
+ $ mockRequest ,
38
+ function ($ request ) {
39
+ return $ request ;
40
+ }
41
+ );
42
+ $ this ->assertSame ('application/json ' , $ result ->header ('Accept ' ));
43
+ }
44
+
45
+ /**
46
+ * @test
47
+ */
48
+ public function whenItReceivesApplicationWildcardAcceptHeaderItShouldSetToApplicationJson ()
49
+ {
50
+ $ mockRequest = $ this ->getRequest (['Accept ' => 'application/* ' ]);
51
+ $ middleware = new RequestAcceptJson ();
52
+
53
+ $ result = $ middleware ->handle (
54
+ $ mockRequest ,
55
+ function ($ request ) {
56
+ return $ request ;
57
+ }
58
+ );
59
+ $ this ->assertSame ('application/json ' , $ result ->header ('Accept ' ));
60
+ }
61
+
28
62
/**
29
63
* @test
30
64
*/
You can’t perform that action at this time.
0 commit comments