!118 fix(request): 优化请求参数使用体验并解决 url 拼接问题

Merge pull request !118 from 涂旭辉/master
This commit is contained in:
openInula-robot 2024-01-24 07:24:53 +00:00 committed by Gitee
commit f295f25176
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 29 additions and 5 deletions

View File

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

View File

@ -17,7 +17,7 @@ import express from "express";
import * as fs from "fs";
import bodyParser from "body-parser";
import cors from "cors";
import path from "path";
import * as path from "path";
const app = express();
const port = 3001;
@ -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

@ -430,7 +430,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;