Skip to content

Commit

Permalink
[bug] fix hiker req res not standard
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiram committed Dec 6, 2024
1 parent 64b5dc1 commit 3c7df48
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/main/utils/hiker/syncFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ const toString = (val: any): string => {
}
};

const serialize2dict = (headers) => {
const serialize2dict = (headers: { [key: string]: any } = {}) => {
const headersDict = {};
for (const [key, value] of headers.entries()) {
headersDict[key] = value;
headersDict[key] = value.split(';');
}
return headersDict;
};
Expand Down
12 changes: 11 additions & 1 deletion src/main/utils/hiker/syncRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const getTimeout = (timeout: number | undefined | null) => {
return baseTimeout;
};

const toTitleCase = (str) => {
const toTitleCase = (str: string) => {
return str
.split('-')
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
Expand Down Expand Up @@ -58,6 +58,14 @@ const toString = (val: any): string => {
}
};

const serialize2dict = (headers: { [key: string]: any } = {}) => {
const headersDict = {};
for (const [key, value] of Object.entries(headers)) {
headersDict[key] = value.split(';');
}
return headersDict;
};

type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'HEAD';

interface RequestOptions {
Expand Down Expand Up @@ -143,6 +151,8 @@ const fetch = (url: string, options: RequestOptions = {}) => {
res.getBody = function (encoding: BufferEncoding | undefined) {
return encoding ? this.body.toString(encoding) : this.body;
};
// @ts-ignore 重写请求头
res.headers = serialize2dict(res.headers);

if (options?.onlyHeaders) {
return toString(res.headers);
Expand Down

0 comments on commit 3c7df48

Please sign in to comment.