feat: framework optimization

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
2022-10-14 10:07:36 +08:00
parent 2fe9bce2ea
commit 1c579c9789
6 changed files with 47 additions and 17 deletions

View File

@ -19,12 +19,20 @@ interface RequestConfig {
method?: Method
headers?: { [key: string]: string }
params?: { [key: string]: string }
data?: any
data?: any,
connectTimeout?: number,
readTimeout?: number,
}
function request(config: RequestConfig) {
// @ts-ignore XMLHttpRequest class only exist nashorn polyfill
let xhr = new XMLHttpRequest()
if (config.connectTimeout) {
xhr.connectTimeout = config.connectTimeout
}
if (config.readTimeout) {
xhr.readTimeout = config.readTimeout
}
xhr.open(config.method, config.url, false)
for (const header in config.headers) {
xhr.setRequestHeader(header, config.headers[header])