@jayfong/x-request 2.28.1 → 2.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_cjs/index.js +9 -7
- package/lib/index.d.ts +23 -2
- package/lib/index.js +9 -7
- package/package.json +1 -1
package/lib/_cjs/index.js
CHANGED
|
@@ -77,12 +77,14 @@ exports.XRequestFormFile = XRequestFormFile;
|
|
|
77
77
|
class XRequest {
|
|
78
78
|
static getGotOptions(options, responseType) {
|
|
79
79
|
var _gotOptions$headers, _userAgent, _gotOptions$headers$_, _options$userAgent;
|
|
80
|
-
if (options.query) {
|
|
81
|
-
const url = new URL(options.url);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
80
|
+
if (options.baseUrl || options.query) {
|
|
81
|
+
const url = new URL(options.url, options.baseUrl);
|
|
82
|
+
if (options.query) {
|
|
83
|
+
const query = options.query instanceof URLSearchParams ? options.query : new URLSearchParams(options.query);
|
|
84
|
+
query.forEach((v, k) => {
|
|
85
|
+
url.searchParams.set(k, v);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
86
88
|
options.url = url.toString();
|
|
87
89
|
}
|
|
88
90
|
const gotOptions = {
|
|
@@ -147,7 +149,7 @@ class XRequest {
|
|
|
147
149
|
method: options.method || 'POST',
|
|
148
150
|
...(options.data == null ? {
|
|
149
151
|
body: ''
|
|
150
|
-
} : options.data instanceof _formData.default ? {
|
|
152
|
+
} : options.data instanceof _formData.default || Buffer.isBuffer(options.data) ? {
|
|
151
153
|
body: options.data
|
|
152
154
|
} : options.data instanceof URLSearchParams ? {
|
|
153
155
|
form: options.data
|
package/lib/index.d.ts
CHANGED
|
@@ -7,6 +7,27 @@ import { Readable } from 'stream';
|
|
|
7
7
|
import { CookieJar } from 'tough-cookie';
|
|
8
8
|
import { OmitStrict } from 'vtils/types';
|
|
9
9
|
export interface XRequestOptions {
|
|
10
|
+
/**
|
|
11
|
+
* 基础请求地址
|
|
12
|
+
*
|
|
13
|
+
* ```
|
|
14
|
+
* new URL('1111', 'https://baidu.com')
|
|
15
|
+
* // => https://baidu.com/1111
|
|
16
|
+
*
|
|
17
|
+
* new URL('1111', 'https://baidu.com/ddd')
|
|
18
|
+
* // => https://baidu.com/1111
|
|
19
|
+
*
|
|
20
|
+
* new URL('./1111', 'https://baidu.com/ddd/')
|
|
21
|
+
* // => https://baidu.com/ddd/1111
|
|
22
|
+
*
|
|
23
|
+
* new URL('/1111', 'https://baidu.com/ddd/')
|
|
24
|
+
* // => https://baidu.com/1111
|
|
25
|
+
*
|
|
26
|
+
* new URL('https://dddd.ddd', 'https://baidu.com/ddd/')
|
|
27
|
+
* // => https://dddd.ddd/
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
baseUrl?: string;
|
|
10
31
|
/**
|
|
11
32
|
* 请求地址
|
|
12
33
|
*/
|
|
@@ -60,11 +81,11 @@ export interface XRequestGetOptions extends XRequestOptions {
|
|
|
60
81
|
}
|
|
61
82
|
export interface XRequestPostOptions extends XRequestOptions {
|
|
62
83
|
method?: string;
|
|
63
|
-
data?: Record<string, any> | FormData | URLSearchParams;
|
|
84
|
+
data?: Record<string, any> | FormData | URLSearchParams | Buffer;
|
|
64
85
|
}
|
|
65
86
|
export interface XRequestPostStreamOptions extends XRequestOptions {
|
|
66
87
|
method?: string;
|
|
67
|
-
data?: Record<string, any> | FormData | URLSearchParams | FormStream;
|
|
88
|
+
data?: Record<string, any> | FormData | URLSearchParams | Buffer | FormStream;
|
|
68
89
|
}
|
|
69
90
|
export declare class XRequestFormUrlencoded extends URLSearchParams {
|
|
70
91
|
}
|
package/lib/index.js
CHANGED
|
@@ -68,12 +68,14 @@ export class XRequestFormFile {
|
|
|
68
68
|
export class XRequest {
|
|
69
69
|
static getGotOptions(options, responseType) {
|
|
70
70
|
var _gotOptions$headers, _userAgent, _gotOptions$headers$_, _options$userAgent;
|
|
71
|
-
if (options.query) {
|
|
72
|
-
const url = new URL(options.url);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
if (options.baseUrl || options.query) {
|
|
72
|
+
const url = new URL(options.url, options.baseUrl);
|
|
73
|
+
if (options.query) {
|
|
74
|
+
const query = options.query instanceof URLSearchParams ? options.query : new URLSearchParams(options.query);
|
|
75
|
+
query.forEach((v, k) => {
|
|
76
|
+
url.searchParams.set(k, v);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
77
79
|
options.url = url.toString();
|
|
78
80
|
}
|
|
79
81
|
const gotOptions = {
|
|
@@ -138,7 +140,7 @@ export class XRequest {
|
|
|
138
140
|
method: options.method || 'POST',
|
|
139
141
|
...(options.data == null ? {
|
|
140
142
|
body: ''
|
|
141
|
-
} : options.data instanceof FormData ? {
|
|
143
|
+
} : options.data instanceof FormData || Buffer.isBuffer(options.data) ? {
|
|
142
144
|
body: options.data
|
|
143
145
|
} : options.data instanceof URLSearchParams ? {
|
|
144
146
|
form: options.data
|