@@ -40,10 +40,43 @@ preflightTest(true, false, "*", "x-test", "SUPER", ["X-Test", "1"])
40
40
preflightTest ( true , false , "*" , "*" , "OK" , [ "X-Test" , "1" ] )
41
41
preflightTest ( false , true , "*" , "*" , "OK" , [ "X-Test" , "1" ] )
42
42
preflightTest ( false , true , "*" , "" , "PUT" , [ ] )
43
- preflightTest ( true , true , "PUT" , "*" , "PUT" , [ ] )
44
43
preflightTest ( false , true , "get" , "*" , "GET" , [ "X-Test" , "1" ] )
45
44
preflightTest ( false , true , "*" , "*" , "GET" , [ "X-Test" , "1" ] )
46
45
// Exact character match works even for "*" with credentials.
47
46
preflightTest ( true , true , "*" , "*" , "*" , [ "*" , "1" ] )
48
- // "PUT" does not pass the case-sensitive method check, and not in the safe list.
49
- preflightTest ( false , true , "put" , "*" , "PUT" , [ ] )
47
+
48
+ // The following methods are upper-cased for init["method"] by
49
+ // https://fetch.spec.whatwg.org/#concept-method-normalize
50
+ // but not in Access-Control-Allow-Methods response.
51
+ // But they are https://fetch.spec.whatwg.org/#cors-safelisted-method,
52
+ // CORS anyway passes regardless of the cases.
53
+ for ( const METHOD of [ 'GET' , 'HEAD' , 'POST' ] ) {
54
+ const method = METHOD . toLowerCase ( ) ;
55
+ preflightTest ( true , true , METHOD , "*" , METHOD , [ ] )
56
+ preflightTest ( true , true , METHOD , "*" , method , [ ] )
57
+ preflightTest ( true , true , method , "*" , METHOD , [ ] )
58
+ preflightTest ( true , true , method , "*" , method , [ ] )
59
+ }
60
+
61
+ // The following methods are upper-cased for init["method"] by
62
+ // https://fetch.spec.whatwg.org/#concept-method-normalize
63
+ // but not in Access-Control-Allow-Methods response.
64
+ // As they are not https://fetch.spec.whatwg.org/#cors-safelisted-method,
65
+ // Access-Control-Allow-Methods should contain upper-cased methods,
66
+ // while init["method"] can be either in upper or lower case.
67
+ for ( const METHOD of [ 'DELETE' , 'PUT' ] ) {
68
+ const method = METHOD . toLowerCase ( ) ;
69
+ preflightTest ( true , true , METHOD , "*" , METHOD , [ ] )
70
+ preflightTest ( true , true , METHOD , "*" , method , [ ] )
71
+ preflightTest ( false , true , method , "*" , METHOD , [ ] )
72
+ preflightTest ( false , true , method , "*" , method , [ ] )
73
+ }
74
+
75
+ // "PATCH" is NOT upper-cased in both places because it is not listed in
76
+ // https://fetch.spec.whatwg.org/#concept-method-normalize.
77
+ // So Access-Control-Allow-Methods value and init["method"] should match
78
+ // case-sensitively.
79
+ preflightTest ( true , true , "PATCH" , "*" , "PATCH" , [ ] )
80
+ preflightTest ( false , true , "PATCH" , "*" , "patch" , [ ] )
81
+ preflightTest ( false , true , "patch" , "*" , "PATCH" , [ ] )
82
+ preflightTest ( true , true , "patch" , "*" , "patch" , [ ] )
0 commit comments