refactor: 优化代码
This commit is contained in:
parent
18eb1827ef
commit
c8e6b5106f
|
@ -275,29 +275,23 @@ export class DubboSample extends DefaultTestElement {
|
|||
}
|
||||
|
||||
export class HTTPSamplerProxy extends DefaultTestElement {
|
||||
constructor(testName, request) {
|
||||
constructor(testName, options = {}) {
|
||||
super('HTTPSamplerProxy', 'HttpTestSampleGui', 'HTTPSamplerProxy', testName);
|
||||
this.request = request || {};
|
||||
|
||||
if (request.useEnvironment) {
|
||||
this.stringProp("HTTPSampler.domain", request.domain);
|
||||
this.stringProp("HTTPSampler.protocol", request.protocol);
|
||||
this.stringProp("HTTPSampler.path", this.request.path);
|
||||
} else {
|
||||
this.stringProp("HTTPSampler.domain", this.request.hostname);
|
||||
this.stringProp("HTTPSampler.protocol", this.request.protocol.split(":")[0]);
|
||||
this.stringProp("HTTPSampler.path", this.request.pathname);
|
||||
}
|
||||
this.stringProp("HTTPSampler.method", this.request.method);
|
||||
this.stringProp("HTTPSampler.contentEncoding", this.request.encoding, "UTF-8");
|
||||
if (!this.request.port) {
|
||||
this.stringProp("HTTPSampler.domain", options.domain);
|
||||
this.stringProp("HTTPSampler.protocol", options.protocol);
|
||||
this.stringProp("HTTPSampler.path", options.path);
|
||||
|
||||
this.stringProp("HTTPSampler.method", options.method);
|
||||
this.stringProp("HTTPSampler.contentEncoding", options.encoding, "UTF-8");
|
||||
if (!options.port) {
|
||||
this.stringProp("HTTPSampler.port", "");
|
||||
} else {
|
||||
this.stringProp("HTTPSampler.port", this.request.port);
|
||||
this.stringProp("HTTPSampler.port", options.port);
|
||||
}
|
||||
|
||||
this.boolProp("HTTPSampler.follow_redirects", this.request.follow, true);
|
||||
this.boolProp("HTTPSampler.use_keepalive", this.request.keepalive, true);
|
||||
this.boolProp("HTTPSampler.follow_redirects", options.follow, true);
|
||||
this.boolProp("HTTPSampler.use_keepalive", options.keepalive, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -691,14 +691,14 @@ class JMXHttpRequest {
|
|||
request.url = 'http://' + request.url;
|
||||
}
|
||||
let url = new URL(request.url);
|
||||
this.hostname = decodeURIComponent(url.hostname);
|
||||
this.domain = decodeURIComponent(url.hostname);
|
||||
this.port = url.port;
|
||||
this.protocol = url.protocol.split(":")[0];
|
||||
this.pathname = this.getPostQueryParameters(request, decodeURIComponent(url.pathname));
|
||||
this.path = this.getPostQueryParameters(request, decodeURIComponent(url.pathname));
|
||||
} else {
|
||||
this.domain = environment.domain;
|
||||
this.port = environment.port;
|
||||
this.protocol = environment.protocol;
|
||||
this.domain = environment.domain;
|
||||
let url = new URL(environment.protocol + "://" + environment.socket);
|
||||
this.path = this.getPostQueryParameters(request, decodeURIComponent(url.pathname + (request.path ? request.path : '')));
|
||||
}
|
||||
|
@ -717,7 +717,7 @@ class JMXHttpRequest {
|
|||
for (let i = 0; i < parameters.length; i++) {
|
||||
let parameter = parameters[i];
|
||||
path += (parameter.name + '=' + parameter.value);
|
||||
if (i != parameters.length - 1) {
|
||||
if (i !== parameters.length - 1) {
|
||||
path += '&';
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue