Skip to content

Commit 78a287f

Browse files
committed
feat: enhance URL handling in request module to support absolute URLs and improve query parameter serialization
1 parent 5691607 commit 78a287f

File tree

2 files changed

+197
-32
lines changed

2 files changed

+197
-32
lines changed

src/lib/request.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,31 @@ import { APIError } from './api-error';
88
*/
99
function serializeParams(params: any): string {
1010
if (!params) return '';
11+
1112
return serialize(params);
1213
}
1314

1415
/**
1516
* Builds the full URL with query parameters
1617
*/
1718
function buildFullUrl(baseURL: string | undefined, url: string, queryString: string): string {
19+
if (url.startsWith('http://') || url.startsWith('https://')) {
20+
return `${url}?${queryString}`;
21+
}
1822
const base = baseURL || '';
23+
1924
return `${base}${url}?${queryString}`;
2025
}
2126

2227
/**
2328
* Makes the HTTP request with proper URL handling
2429
*/
25-
async function makeRequest(instance: AxiosInstance, url: string, requestConfig: any, actualFullUrl: string): Promise<any> {
30+
async function makeRequest(
31+
instance: AxiosInstance,
32+
url: string,
33+
requestConfig: any,
34+
actualFullUrl: string
35+
): Promise<any> {
2636
// If URL is too long, use direct axios request with full URL
2737
if (actualFullUrl.length > 2000) {
2838
return await instance.request({
@@ -69,11 +79,11 @@ export async function getData(instance: AxiosInstance, url: string, data?: any)
6979
}
7080
}
7181
}
72-
82+
7383
const requestConfig = {
7484
...data,
7585
maxContentLength: Infinity,
76-
maxBodyLength: Infinity
86+
maxBodyLength: Infinity,
7787
};
7888
const queryString = serializeParams(requestConfig.params);
7989
const actualFullUrl = buildFullUrl(instance.defaults.baseURL, url, queryString);

0 commit comments

Comments
 (0)