Skip to content

Commit

Permalink
feat: remove http options withCredentials
Browse files Browse the repository at this point in the history
  • Loading branch information
sigoden committed Jun 18, 2021
1 parent 68865ab commit 87f087c
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 11 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -970,8 +970,6 @@ The `echo` client does not send any request, and directly returns the data in th
// `timeout` specifies the number of milliseconds before the request times out.
// If the request takes longer than `timeout`, the request will be aborted.
timeout: 0,
// `withCredentials` Whether to provide credentials
withCredentials: true,
// `maxRedirects` defines the maximum number of redirects to follow in node.js.
// If set to 0, no redirects will be followed.
maxRedirects: 0,
Expand Down
2 changes: 0 additions & 2 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -960,8 +960,6 @@ Apitest 提供两种客户端。
baseURL: '',
// `timeout` 指定请求超时前的毫秒数。 如果请求时间超过`timeout`,请求将被中止。
timeout: 0,
// `withCredentials` 是否提供凭据信息
withCredentials: true,
// `maxRedirects` 最大重定向数。如果设置为 0,则不会遵循重定向。
maxRedirects: 0,
// `headers` 默认请求头
Expand Down
8 changes: 2 additions & 6 deletions src/Clients/HttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ axiosCookieJarSupport(axios);
export interface HttpClientOptions {
baseUrl?: string;
timeout?: number;
withCredentials?: boolean;
maxRedirects?: number;
headers?: Record<string, string>;
proxy?: string;
Expand All @@ -29,9 +28,6 @@ export const HTTP_OPTIONS_SCHEMA = {
timeout: {
type: "integer",
},
withCredentials: {
type: "boolean",
},
maxRedirects: {
type: "integer",
},
Expand All @@ -49,7 +45,6 @@ export const HTTP_OPTIONS_SCHEMA = {

export const DEFAULT_OPTIONS: HttpClientOptions = {
timeout: 0,
withCredentials: true,
maxRedirects: 0,
};

Expand All @@ -60,7 +55,7 @@ export default class HttpClient implements Client {
if (options) {
try {
schemaValidate(options, [], HTTP_OPTIONS_SCHEMA, true);
this.options = _.pick(options, ["baseURL", "timeout", "withCredentials", "maxRedirects", "headers", "proxy"]);
this.options = _.pick(options, ["baseURL", "timeout", "maxRedirects", "headers", "proxy"]);
this.options = _.merge({}, DEFAULT_OPTIONS, this.options);
} catch (err) {
throw new Error(`[main@client(${name})[${err.paths.join(".")}] ${err.message}`);
Expand All @@ -87,6 +82,7 @@ export default class HttpClient implements Client {
method: req.method,
validateStatus: () => true,
jar: true,
withCredentials: true,
ignoreCookieErrors: true,
};
if (req.query) {
Expand Down
3 changes: 2 additions & 1 deletion tests/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ test("validate", () => {
{
baseURL: "abc",
timeout: 5000,
withCredentials: false,
maxRedirects: 0,
proxy: "http://localhost:8080",
headers: {
"x-key": "abc",
},
Expand Down

0 comments on commit 87f087c

Please sign in to comment.