@@ -114,16 +114,16 @@ if(typeof XDomainRequest === 'undefined') {
114
114
115
115
// CORS simple requests: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Simple_requests
116
116
var isSimpleRequest = true , restore ;
117
- var simpleMethods = [ 'GET' , 'POST' , 'HEAD' ] ;
118
- var simpleHeaders = [
119
- 'Accept' , 'Accept-Language' , 'Content-Language' , 'Content-Type' ,
117
+ var isSimpleMethod = makePredicateContains ( [ 'GET' , 'POST' , 'HEAD' ] ) ;
118
+ var isSimpleHeader = makePredicateContains ( [
119
+ 'Accept' , 'Accept-Language' , 'Content-Language' , 'Content-Type' ,
120
120
'DPR' , 'Downlink' , 'Save-Data' , 'Viewport-Width' , 'Width'
121
- ] ;
122
- var simpleContentType = 'application/x-www-form-urlencoded' ;
121
+ ] ) ;
122
+ var isSimpleContentType = makePredicateContains ( [ 'application/x-www-form-urlencoded' , 'multipart/form-data' , 'text/plain' ] ) ;
123
123
124
124
restore = makeFixture ( function ( ) {
125
125
this . open = function ( type , url ) {
126
- if ( simpleMethods . indexOf ( type ) === - 1 ) {
126
+ if ( ! isSimpleMethod ( type ) ) {
127
127
isSimpleRequest = false ;
128
128
}
129
129
} ;
@@ -137,10 +137,10 @@ if(typeof XDomainRequest === 'undefined') {
137
137
} ;
138
138
139
139
this . setRequestHeader = function ( header , value ) {
140
- if ( header === "Content-Type" && value !== simpleContentType ) {
140
+ if ( header === "Content-Type" && ! isSimpleHeader ( value ) ) {
141
141
isSimpleRequest = false ;
142
142
}
143
- if ( simpleHeaders . indexOf ( header ) === - 1 ) {
143
+ if ( isSimpleContentType ( header ) ) {
144
144
isSimpleRequest = false ;
145
145
}
146
146
response [ header ] = value ;
@@ -241,3 +241,11 @@ if (__dirname !== '/') {
241
241
} ) ;
242
242
} ) ;
243
243
}
244
+
245
+
246
+ // A helper to make a predicate for a given array that checks whether it contains a given value:
247
+ function makePredicateContains ( arr ) {
248
+ return function ( val ) {
249
+ return arr . indexOf ( val ) !== - 1 ;
250
+ }
251
+ }
0 commit comments