-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.js
More file actions
38 lines (29 loc) · 1.01 KB
/
index.js
File metadata and controls
38 lines (29 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { sendNodeAPIRequest } from './client-node'
import { sendXmlHttpRequest } from './client-browser'
import { Request } from './request'
import { getFormData, setFormData } from './utils'
Object.defineProperty(Request, 'FormData', {
get() {
return getFormData()
},
set(value) {
setFormData(value)
}
})
Request.XMLHttpRequest = typeof XMLHttpRequest !== 'undefined' ? XMLHttpRequest : undefined
Request.send = (path, method, headers, body, encoding, timeout, withCredentials, abortSignal) => {
const sender = typeof Request.XMLHttpRequest !== 'undefined'
? sendXmlHttpRequest
: sendNodeAPIRequest
return sender(path, method, headers, body, encoding, timeout, withCredentials, abortSignal)
}
Request.verbose = false
Request.withCredentials = false
Request.methods = ['get', 'post', 'put', 'patch', 'delete']
Request.methods.forEach(method => {
Request[method] = function(path, body) {
return new Request(path, method, body)
}
})
exports = module.exports = Request
export default Request