@@ -109,39 +109,52 @@ if(typeof XDomainRequest === 'undefined') {
109
109
} ) ;
110
110
} ) ;
111
111
112
- // Test GET CORS:
113
- QUnit . asyncTest ( "GET CORS should set content-type header (#187)" , function ( ) {
114
-
115
- var hasCorrectHeader , restore ;
112
+ // Test simple GET CORS:
113
+ QUnit . asyncTest ( "GET CORS should be a simple request - without a preflight (#187)" , function ( ) {
114
+
115
+ // CORS simple requests: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Simple_requests
116
+ var isSimpleRequest = true , restore ;
117
+ var simpleMethods = [ 'GET' , 'POST' , 'HEAD' ] ;
118
+ var simpleHeaders = [
119
+ 'Accept' , 'Accept-Language' , 'Content-Language' , 'Content-Type' ,
120
+ 'DPR' , 'Downlink' , 'Save-Data' , 'Viewport-Width' , 'Width'
121
+ ] ;
122
+ var simpleContentType = 'application/x-www-form-urlencoded' ;
123
+
116
124
restore = makeFixture ( function ( ) {
117
125
this . open = function ( type , url ) {
126
+ if ( simpleMethods . indexOf ( type ) === - 1 ) {
127
+ isSimpleRequest = false ;
128
+ }
118
129
} ;
119
130
131
+ var response = { } ;
120
132
this . send = function ( ) {
133
+ this . responseText = JSON . stringify ( response ) ;
121
134
this . readyState = 4 ;
122
135
this . status = 200 ;
123
136
this . onreadystatechange ( ) ;
124
137
} ;
125
-
138
+
126
139
this . setRequestHeader = function ( header , value ) {
127
- if ( header === "Content-Type" && value === "application/x-www-form-urlencoded" ) {
128
- hasCorrectHeader = true ;
140
+ if ( header === "Content-Type" && value !== simpleContentType ) {
141
+ isSimpleRequest = false ;
142
+ }
143
+ if ( simpleHeaders . indexOf ( header ) === - 1 ) {
144
+ isSimpleRequest = false ;
129
145
}
130
- var o = { } ;
131
- o [ header ] = value ;
132
- this . responseText = JSON . stringify ( o ) ;
146
+ response [ header ] = value ;
133
147
} ;
134
148
} ) ;
135
149
136
150
ajax ( {
137
151
url : "http://query.yahooapis.com/v1/public/yql" ,
138
152
data : {
139
- fmt : "JSON" ,
140
153
q : 'select * from geo.places where text="sunnyvale, ca"' ,
141
154
format : "json"
142
155
}
143
156
} ) . then ( function ( response ) {
144
- QUnit . ok ( hasCorrectHeader , "Content-Type for GET CORS should be set to `application/x-www-form-urlencoded` " ) ;
157
+ QUnit . ok ( isSimpleRequest , "CORS GET is simple " ) ;
145
158
restore ( ) ;
146
159
start ( ) ;
147
160
} , function ( err ) {
0 commit comments