File tree Expand file tree Collapse file tree 12 files changed +758
-0
lines changed
Controller/HttpResponse/Cors
dev/tests/api-functional/testsuite/Magento/GraphQl Expand file tree Collapse file tree 12 files changed +758
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Copyright © Magento, Inc. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
6
+ declare (strict_types=1 );
7
+
8
+ namespace Magento \GraphQl \Controller \HttpResponse \Cors ;
9
+
10
+ use Magento \Framework \App \Response \HeaderProvider \HeaderProviderInterface ;
11
+ use Magento \GraphQl \Model \Cors \ConfigurationInterface ;
12
+
13
+ /**
14
+ * Provides value for Access-Control-Allow-Credentials header if CORS is enabled
15
+ */
16
+ class CorsAllowCredentialsHeaderProvider implements HeaderProviderInterface
17
+ {
18
+ /**
19
+ * @var string
20
+ */
21
+ private $ headerName ;
22
+
23
+ /**
24
+ * CORS configuration provider
25
+ *
26
+ * @var \Magento\GraphQl\Model\Cors\ConfigurationInterface
27
+ */
28
+ private $ corsConfiguration ;
29
+
30
+ /**
31
+ * @param ConfigurationInterface $corsConfiguration
32
+ * @param string $headerName
33
+ */
34
+ public function __construct (
35
+ ConfigurationInterface $ corsConfiguration ,
36
+ string $ headerName
37
+ ) {
38
+ $ this ->corsConfiguration = $ corsConfiguration ;
39
+ $ this ->headerName = $ headerName ;
40
+ }
41
+
42
+ /**
43
+ * Get name of header
44
+ *
45
+ * @return string
46
+ */
47
+ public function getName (): string
48
+ {
49
+ return $ this ->headerName ;
50
+ }
51
+
52
+ /**
53
+ * Get value for header
54
+ *
55
+ * @return string
56
+ */
57
+ public function getValue (): string
58
+ {
59
+ return "1 " ;
60
+ }
61
+
62
+ /**
63
+ * Check if header can be applied
64
+ *
65
+ * @return bool
66
+ */
67
+ public function canApply (): bool
68
+ {
69
+ return $ this ->corsConfiguration ->isEnabled () && $ this ->corsConfiguration ->isCredentialsAllowed ();
70
+ }
71
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Copyright © Magento, Inc. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
6
+ declare (strict_types=1 );
7
+
8
+ namespace Magento \GraphQl \Controller \HttpResponse \Cors ;
9
+
10
+ use Magento \Framework \App \Response \HeaderProvider \HeaderProviderInterface ;
11
+ use Magento \GraphQl \Model \Cors \ConfigurationInterface ;
12
+
13
+ /**
14
+ * Provides value for Access-Control-Allow-Headers header if CORS is enabled
15
+ */
16
+ class CorsAllowHeadersHeaderProvider implements HeaderProviderInterface
17
+ {
18
+ /**
19
+ * @var string
20
+ */
21
+ private $ headerName ;
22
+
23
+ /**
24
+ * CORS configuration provider
25
+ *
26
+ * @var \Magento\GraphQl\Model\Cors\ConfigurationInterface
27
+ */
28
+ private $ corsConfiguration ;
29
+
30
+ /**
31
+ * @param ConfigurationInterface $corsConfiguration
32
+ * @param string $headerName
33
+ */
34
+ public function __construct (
35
+ ConfigurationInterface $ corsConfiguration ,
36
+ string $ headerName
37
+ ) {
38
+ $ this ->corsConfiguration = $ corsConfiguration ;
39
+ $ this ->headerName = $ headerName ;
40
+ }
41
+
42
+ /**
43
+ * Get name of header
44
+ *
45
+ * @return string
46
+ */
47
+ public function getName (): string
48
+ {
49
+ return $ this ->headerName ;
50
+ }
51
+
52
+ /**
53
+ * Check if header can be applied
54
+ *
55
+ * @return bool
56
+ */
57
+ public function canApply (): bool
58
+ {
59
+ return $ this ->corsConfiguration ->isEnabled () && $ this ->getValue ();
60
+ }
61
+
62
+ /**
63
+ * Get value for header
64
+ *
65
+ * @return string|null
66
+ */
67
+ public function getValue (): ?string
68
+ {
69
+ return $ this ->corsConfiguration ->getAllowedHeaders ();
70
+ }
71
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Copyright © Magento, Inc. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
6
+ declare (strict_types=1 );
7
+
8
+ namespace Magento \GraphQl \Controller \HttpResponse \Cors ;
9
+
10
+ use Magento \Framework \App \Response \HeaderProvider \HeaderProviderInterface ;
11
+ use Magento \GraphQl \Model \Cors \ConfigurationInterface ;
12
+
13
+ /**
14
+ * Provides value for Access-Control-Allow-Methods header if CORS is enabled
15
+ */
16
+ class CorsAllowMethodsHeaderProvider implements HeaderProviderInterface
17
+ {
18
+ /**
19
+ * @var string
20
+ */
21
+ private $ headerName ;
22
+
23
+ /**
24
+ * CORS configuration provider
25
+ *
26
+ * @var \Magento\GraphQl\Model\Cors\ConfigurationInterface
27
+ */
28
+ private $ corsConfiguration ;
29
+
30
+ /**
31
+ * @param ConfigurationInterface $corsConfiguration
32
+ * @param string $headerName
33
+ */
34
+ public function __construct (
35
+ ConfigurationInterface $ corsConfiguration ,
36
+ string $ headerName
37
+ ) {
38
+ $ this ->corsConfiguration = $ corsConfiguration ;
39
+ $ this ->headerName = $ headerName ;
40
+ }
41
+
42
+ /**
43
+ * Get name of header
44
+ *
45
+ * @return string
46
+ */
47
+ public function getName (): string
48
+ {
49
+ return $ this ->headerName ;
50
+ }
51
+
52
+ /**
53
+ * Check if header can be applied
54
+ *
55
+ * @return bool
56
+ */
57
+ public function canApply (): bool
58
+ {
59
+ return $ this ->corsConfiguration ->isEnabled () && $ this ->getValue ();
60
+ }
61
+
62
+ /**
63
+ * Get value for header
64
+ *
65
+ * @return string|null
66
+ */
67
+ public function getValue (): ?string
68
+ {
69
+ return $ this ->corsConfiguration ->getAllowedMethods ();
70
+ }
71
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Copyright © Magento, Inc. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
6
+ declare (strict_types=1 );
7
+
8
+ namespace Magento \GraphQl \Controller \HttpResponse \Cors ;
9
+
10
+ use Magento \Framework \App \Response \HeaderProvider \HeaderProviderInterface ;
11
+ use Magento \GraphQl \Model \Cors \ConfigurationInterface ;
12
+
13
+ /**
14
+ * Provides value for Access-Control-Allow-Origin header if CORS is enabled
15
+ */
16
+ class CorsAllowOriginHeaderProvider implements HeaderProviderInterface
17
+ {
18
+ /**
19
+ * @var string
20
+ */
21
+ private $ headerName ;
22
+
23
+ /**
24
+ * CORS configuration provider
25
+ *
26
+ * @var \Magento\GraphQl\Model\Cors\ConfigurationInterface
27
+ */
28
+ private $ corsConfiguration ;
29
+
30
+ /**
31
+ * @param ConfigurationInterface $corsConfiguration
32
+ * @param string $headerName
33
+ */
34
+ public function __construct (
35
+ ConfigurationInterface $ corsConfiguration ,
36
+ string $ headerName
37
+ ) {
38
+ $ this ->corsConfiguration = $ corsConfiguration ;
39
+ $ this ->headerName = $ headerName ;
40
+ }
41
+
42
+ /**
43
+ * Get name of header
44
+ *
45
+ * @return string
46
+ */
47
+ public function getName (): string
48
+ {
49
+ return $ this ->headerName ;
50
+ }
51
+
52
+ /**
53
+ * Check if header can be applied
54
+ *
55
+ * @return bool
56
+ */
57
+ public function canApply (): bool
58
+ {
59
+ return $ this ->corsConfiguration ->isEnabled () && $ this ->getValue ();
60
+ }
61
+
62
+ /**
63
+ * Get value for header
64
+ *
65
+ * @return string|null
66
+ */
67
+ public function getValue (): ?string
68
+ {
69
+ return $ this ->corsConfiguration ->getAllowedOrigins ();
70
+ }
71
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Copyright © Magento, Inc. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
6
+ declare (strict_types=1 );
7
+
8
+ namespace Magento \GraphQl \Controller \HttpResponse \Cors ;
9
+
10
+ use Magento \Framework \App \Response \HeaderProvider \HeaderProviderInterface ;
11
+ use Magento \GraphQl \Model \Cors \ConfigurationInterface ;
12
+
13
+ /**
14
+ * Provides value for Access-Control-Max-Age header if CORS is enabled
15
+ */
16
+ class CorsMaxAgeHeaderProvider implements HeaderProviderInterface
17
+ {
18
+ /**
19
+ * @var string
20
+ */
21
+ private $ headerName ;
22
+
23
+ /**
24
+ * CORS configuration provider
25
+ *
26
+ * @var \Magento\GraphQl\Model\Cors\ConfigurationInterface
27
+ */
28
+ private $ corsConfiguration ;
29
+
30
+ /**
31
+ * @param ConfigurationInterface $corsConfiguration
32
+ * @param string $headerName
33
+ */
34
+ public function __construct (
35
+ ConfigurationInterface $ corsConfiguration ,
36
+ string $ headerName
37
+ ) {
38
+ $ this ->corsConfiguration = $ corsConfiguration ;
39
+ $ this ->headerName = $ headerName ;
40
+ }
41
+
42
+ /**
43
+ * Get name of header
44
+ *
45
+ * @return string
46
+ */
47
+ public function getName (): string
48
+ {
49
+ return $ this ->headerName ;
50
+ }
51
+
52
+ /**
53
+ * Check if header can be applied
54
+ *
55
+ * @return bool
56
+ */
57
+ public function canApply (): bool
58
+ {
59
+ return $ this ->corsConfiguration ->isEnabled () && $ this ->getValue ();
60
+ }
61
+
62
+ /**
63
+ * Get value for header
64
+ *
65
+ * @return string|null
66
+ */
67
+ public function getValue (): ?string
68
+ {
69
+ return (string ) $ this ->corsConfiguration ->getMaxAge ();
70
+ }
71
+ }
You can’t perform that action at this time.
0 commit comments