fix(request): 优化请求参数使用体验和解决 URL 拼接问题

This commit is contained in:
13659257719 2024-01-24 15:22:55 +08:00
parent 3bebf5280e
commit 80e22da1ec
5 changed files with 28 additions and 4 deletions

View File

@ -0,0 +1,21 @@
# 0.0.10 版本
## 新特性
- 新增了支持过滤请求参数中传入值为 null 时自动过滤的能力
## API变更
## Bug修复
- 优化了传入 params 参数为空对象时拼接 url 后携带 ? 的问题
-
## CVE漏洞修复
## 已知问题

View File

@ -53,7 +53,7 @@ app.get('/data', (req, res) => {
});
app.get('/download', (req, res) => {
const filePath = path.resolve('./examples/request/downloadTest.html');
const filePath = path.resolve(__dirname, '../request/downloadTest.html');
const fileName = 'downloadTest.html';
const fileSize = fs.statSync(filePath).size;

View File

@ -12,7 +12,8 @@
},
"files": [
"/dist",
"README.md"
"README.md",
"CHANGELOG.md"
],
"types": "./dist/index.d.ts",
"repository": {

View File

@ -62,7 +62,9 @@ export const fetchRequest = (config: IrRequestConfig): Promise<IrResponse> => {
// 处理请求参数
if (params) {
const queryString = utils.objectToQueryString(utils.filterUndefinedValues(params));
url = `${url}${url!.includes('?') ? '&' : '?'}${queryString}`; // 支持用户将部分请求参数写在 url 中
if (queryString) {
url = `${url}${url!.includes('?') ? '&' : '?'}${queryString}`; // 支持用户将部分请求参数写在 url 中
}
}
// GET HEAD 方法不允许设置 body

View File

@ -432,7 +432,7 @@ function getObjectByArray(arr: any[]): Record<string, any> {
function filterUndefinedValues(obj: Record<any, any>) {
return Object.keys(obj).reduce((result, key) => {
if (obj[key] !== undefined) {
if (obj[key] !== undefined && obj[key] !== null) {
result[key] = obj[key];
}
return result;