mirror of
https://github.com/tenrok/axios.git
synced 2026-06-20 20:00:40 +03:00
fix(params): re-added the ability to set the function as paramsSerializer config; (#5633)
This commit is contained in:
+1
-1
@@ -370,7 +370,7 @@ declare namespace axios {
|
|||||||
transformResponse?: AxiosResponseTransformer | AxiosResponseTransformer[];
|
transformResponse?: AxiosResponseTransformer | AxiosResponseTransformer[];
|
||||||
headers?: (RawAxiosRequestHeaders & MethodsHeaders) | AxiosHeaders;
|
headers?: (RawAxiosRequestHeaders & MethodsHeaders) | AxiosHeaders;
|
||||||
params?: any;
|
params?: any;
|
||||||
paramsSerializer?: ParamsSerializerOptions;
|
paramsSerializer?: ParamsSerializerOptions | CustomParamsSerializer;
|
||||||
data?: D;
|
data?: D;
|
||||||
timeout?: Milliseconds;
|
timeout?: Milliseconds;
|
||||||
timeoutErrorMessage?: string;
|
timeoutErrorMessage?: string;
|
||||||
|
|||||||
Vendored
+1
-1
@@ -311,7 +311,7 @@ export interface AxiosRequestConfig<D = any> {
|
|||||||
transformResponse?: AxiosResponseTransformer | AxiosResponseTransformer[];
|
transformResponse?: AxiosResponseTransformer | AxiosResponseTransformer[];
|
||||||
headers?: (RawAxiosRequestHeaders & MethodsHeaders) | AxiosHeaders;
|
headers?: (RawAxiosRequestHeaders & MethodsHeaders) | AxiosHeaders;
|
||||||
params?: any;
|
params?: any;
|
||||||
paramsSerializer?: ParamsSerializerOptions;
|
paramsSerializer?: ParamsSerializerOptions | CustomParamsSerializer;
|
||||||
data?: D;
|
data?: D;
|
||||||
timeout?: Milliseconds;
|
timeout?: Milliseconds;
|
||||||
timeoutErrorMessage?: string;
|
timeoutErrorMessage?: string;
|
||||||
|
|||||||
+11
-5
@@ -57,11 +57,17 @@ class Axios {
|
|||||||
}, false);
|
}, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (paramsSerializer !== undefined) {
|
if (paramsSerializer != null) {
|
||||||
validator.assertOptions(paramsSerializer, {
|
if (utils.isFunction(paramsSerializer)) {
|
||||||
encode: validators.function,
|
config.paramsSerializer = {
|
||||||
serialize: validators.function
|
serialize: paramsSerializer
|
||||||
}, true);
|
}
|
||||||
|
} else {
|
||||||
|
validator.assertOptions(paramsSerializer, {
|
||||||
|
encode: validators.function,
|
||||||
|
serialize: validators.function
|
||||||
|
}, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set config.method
|
// Set config.method
|
||||||
|
|||||||
@@ -2103,4 +2103,18 @@ describe('supports http with nodejs', function () {
|
|||||||
it('should properly handle synchronous errors inside the adapter', function () {
|
it('should properly handle synchronous errors inside the adapter', function () {
|
||||||
return assert.rejects(() => axios.get('http://192.168.0.285'), /Invalid URL/);
|
return assert.rejects(() => axios.get('http://192.168.0.285'), /Invalid URL/);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should support function as paramsSerializer value', async () => {
|
||||||
|
server = await startHTTPServer((req, res) => res.end(req.url));
|
||||||
|
|
||||||
|
const {data} = await axios.post(LOCAL_SERVER_URL, 'test', {
|
||||||
|
params: {
|
||||||
|
x: 1
|
||||||
|
},
|
||||||
|
paramsSerializer: () => 'foo',
|
||||||
|
maxRedirects: 0
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.strictEqual(data, '/?foo');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user