1
0
Fork 0
fetch-compare/fixtures/fetch.js

104 lines
2.8 KiB
JavaScript
Raw Normal View History

2021-09-10 01:55:07 +08:00
const tests = {
fetch: {
2021-09-30 11:00:44 +08:00
async acceptCookie() {
try {
const ctrl = new AbortController();
setTimeout(() => ctrl.abort(), 5000);
2021-09-30 11:18:33 +08:00
const response = await fetch('http://httpbin.org/get', {
headers: {Cookie: 'overwrote-cookie'},
2021-09-30 11:00:44 +08:00
signal: ctrl.signal,
});
const o = await response.json();
2021-09-30 11:56:57 +08:00
return `Cookie: ${o.headers.Cookie}`;
2021-09-30 11:00:44 +08:00
} catch (error) {
return error.toString();
}
},
async acceptReferer() {
try {
const ctrl = new AbortController();
setTimeout(() => ctrl.abort(), 5000);
2021-09-30 11:18:33 +08:00
const response = await fetch('http://httpbin.org/get', {
headers: {Referer: 'overwrote-referer'},
2021-09-30 11:00:44 +08:00
signal: ctrl.signal,
});
const o = await response.json();
2021-09-30 11:56:57 +08:00
return `Referer: ${o.headers.Referer}`;
2021-09-30 11:00:44 +08:00
} catch (error) {
return error.toString();
}
},
async acceptKeepAlive() {
try {
const ctrl = new AbortController();
setTimeout(() => ctrl.abort(), 5000);
2021-09-30 11:18:33 +08:00
const response = await fetch('http://httpbin.org/get', {
2021-09-30 11:00:44 +08:00
headers: {'Keep-Alive': 'timeout=5, max=1000'},
signal: ctrl.signal,
});
const o = await response.json();
return `Keep-Alive: ${o.headers['Keep-Alive']}`;
} catch (error) {
return error.toString();
}
},
async acceptDate() {
try {
const ctrl = new AbortController();
setTimeout(() => ctrl.abort(), 5000);
2021-09-30 11:18:33 +08:00
const response = await fetch('http://httpbin.org/get', {
headers: {Date: 'overwrote-date'},
2021-09-30 11:00:44 +08:00
signal: ctrl.signal,
});
const o = await response.json();
2021-09-30 11:56:57 +08:00
return `Date: ${o.headers.Date}`;
2021-09-30 11:00:44 +08:00
} catch (error) {
return error.toString();
}
},
async acceptHost() {
try {
const ctrl = new AbortController();
setTimeout(() => ctrl.abort(), 5000);
2021-09-30 11:18:33 +08:00
const response = await fetch('http://httpbin.org/get', {
headers: {Host: 'overwrote-host.example.com'},
2021-09-30 11:00:44 +08:00
signal: ctrl.signal,
});
const o = await response.json();
2021-09-30 11:56:57 +08:00
return `Host: ${o.headers.Host}`;
2021-09-30 11:00:44 +08:00
} catch (error) {
return error.toString();
}
},
2021-09-30 11:18:33 +08:00
async acceptContentLength0() {
2021-09-10 01:55:07 +08:00
try {
const ctrl = new AbortController();
setTimeout(() => ctrl.abort(), 5000);
2021-09-30 11:18:33 +08:00
const response = await fetch('http://httpbin.org/get', {
headers: {'Content-Length': '0'},
signal: ctrl.signal,
});
const o = await response.json();
return `Content-Length: ${o.headers['Content-Length']}`;
} catch (error) {
return error.toString();
}
},
async acceptContentLength2() {
try {
const ctrl = new AbortController();
setTimeout(() => ctrl.abort(), 5000);
const response = await fetch('http://httpbin.org/get', {
2021-09-30 11:00:44 +08:00
headers: {'Content-Length': '2'},
2021-09-10 01:55:07 +08:00
signal: ctrl.signal,
});
const o = await response.json();
2021-09-30 11:00:44 +08:00
return `Content-Length: ${o.headers['Content-Length']}`;
2021-09-10 01:55:07 +08:00
} catch (error) {
return error.toString();
}
},
},
};
export default tests;