pro-xy-ui 0.5.8 → 0.6.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/.esformatter +28 -28
- package/.eslintrc +15 -15
- package/bin/pro-xy-ui +25 -27
- package/index.html +38 -38
- package/lib/app/_common/app-menu.js +42 -42
- package/lib/app/_common/app-menu.ts +41 -41
- package/lib/app/_common/patchResize.js +33 -33
- package/lib/app/_common/patchResize.ts +32 -32
- package/lib/app/_common/pipes.js +33 -33
- package/lib/app/_common/pipes.ts +21 -21
- package/lib/app/_common/rxjs-extensions.js +20 -20
- package/lib/app/_common/rxjs-extensions.ts +21 -21
- package/lib/app/app.component.css +39 -39
- package/lib/app/app.component.html +35 -35
- package/lib/app/app.module.js +92 -92
- package/lib/app/app.module.ts +89 -89
- package/lib/app/main.js +11 -11
- package/lib/app/main.ts +11 -11
- package/lib/app/model/config.js +69 -69
- package/lib/app/model/config.ts +79 -79
- package/lib/app/model/http.js +116 -116
- package/lib/app/service/config.defaultConfig.js +74 -74
- package/lib/app/service/config.defaultConfig.ts +72 -72
- package/lib/app/service/config.service.js +44 -44
- package/lib/app/service/config.service.ts +39 -39
- package/lib/app/service/socket.service.js +109 -109
- package/lib/app/service/socket.service.ts +131 -131
- package/lib/app/service/traffic.service.js +98 -98
- package/lib/app/views/auto-responder/auto-responder.component.css +37 -37
- package/lib/app/views/auto-responder/auto-responder.component.html +41 -41
- package/lib/app/views/auto-responder/auto-responder.component.js +102 -102
- package/lib/app/views/auto-responder/auto-responder.component.ts +110 -110
- package/lib/app/views/composer/composer.component.css +7 -7
- package/lib/app/views/composer/composer.component.html +9 -9
- package/lib/app/views/composer/composer.component.js +147 -147
- package/lib/app/views/composer/composer.component.ts +148 -148
- package/lib/app/views/config/config.component.css +13 -13
- package/lib/app/views/config/config.component.html +14 -14
- package/lib/app/views/config/config.component.js +163 -163
- package/lib/app/views/config/diff.dialog.html +3 -3
- package/lib/app/views/config/diff.dialog.js +29 -29
- package/lib/app/views/config/diff.dialog.ts +17 -17
- package/lib/app/views/config/plugins.dialog.html +17 -17
- package/lib/app/views/config/plugins.dialog.js +29 -29
- package/lib/app/views/config/plugins.dialog.ts +17 -17
- package/lib/app/views/config-list-base.js +44 -44
- package/lib/app/views/config-list-base.ts +66 -66
- package/lib/app/views/connection/connection.component.html +9 -9
- package/lib/app/views/connection/connection.component.js +87 -89
- package/lib/app/views/connection/connection.component.ts +83 -85
- package/lib/app/views/delay/delay.component.css +23 -23
- package/lib/app/views/delay/delay.component.html +35 -35
- package/lib/app/views/delay/delay.component.js +34 -34
- package/lib/app/views/find/find.component.css +30 -30
- package/lib/app/views/find/find.component.html +10 -10
- package/lib/app/views/find/find.component.js +113 -113
- package/lib/app/views/find/find.component.ts +111 -111
- package/lib/app/views/inspector/inspector.component.css +14 -14
- package/lib/app/views/inspector/inspector.component.html +17 -17
- package/lib/app/views/inspector/inspector.component.js +64 -64
- package/lib/app/views/inspector/inspector.component.ts +54 -54
- package/lib/app/views/logs/logs.component.css +7 -7
- package/lib/app/views/logs/logs.component.html +13 -13
- package/lib/app/views/logs/logs.component.js +56 -56
- package/lib/app/views/logs/logs.component.ts +46 -46
- package/lib/app/views/requests/request-row.component.css +15 -15
- package/lib/app/views/requests/request-row.component.html +7 -7
- package/lib/app/views/requests/request-row.component.js +68 -68
- package/lib/app/views/requests/request.bodyMenu.js +41 -41
- package/lib/app/views/requests/request.bodyMenu.ts +61 -61
- package/lib/app/views/requests/request.headMenu.js +25 -25
- package/lib/app/views/requests/requests.component.css +49 -49
- package/lib/app/views/requests/requests.component.html +33 -33
- package/lib/app/views/requests/requests.component.js +127 -127
- package/lib/app/views/status/status.component.css +18 -18
- package/lib/app/views/status/status.component.html +8 -8
- package/lib/app/views/status/status.component.js +49 -49
- package/lib/app/views/status/status.component.ts +45 -45
- package/lib/app/views/url-replace/url-replace.component.css +32 -32
- package/lib/app/views/url-replace/url-replace.component.html +36 -36
- package/lib/app/views/url-replace/url-replace.component.js +34 -34
- package/lib/index.js +23 -23
- package/lib/lib.d.ts +2 -2
- package/lib/style.css +100 -100
- package/lib/systemjs.config.js +75 -75
- package/package.json +64 -64
- package/readme.md +5 -5
- package/tsconfig.json +23 -23
- package/typings.json +11 -11
- package/npm-shrinkwrap.json +0 -2568
package/lib/app/main.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { platformBrowserDynamic/*, __platform_browser_dynamic_private__*/ } from '@angular/platform-browser-dynamic';
|
|
2
|
-
import { AppModule } from './app.module';
|
|
3
|
-
|
|
4
|
-
// var resourceLoaderImplProto = __platform_browser_dynamic_private__.ResourceLoaderImpl.prototype;
|
|
5
|
-
// var getOrig = resourceLoaderImplProto.get;
|
|
6
|
-
// resourceLoaderImplProto.get = function(url) {
|
|
7
|
-
// return getOrig.call(this, /^\//.test(url) ? "file://" + url : url);
|
|
8
|
-
// };
|
|
9
|
-
|
|
10
|
-
const platform = platformBrowserDynamic();
|
|
11
|
-
platform.bootstrapModule(AppModule);
|
|
1
|
+
import { platformBrowserDynamic/*, __platform_browser_dynamic_private__*/ } from '@angular/platform-browser-dynamic';
|
|
2
|
+
import { AppModule } from './app.module';
|
|
3
|
+
|
|
4
|
+
// var resourceLoaderImplProto = __platform_browser_dynamic_private__.ResourceLoaderImpl.prototype;
|
|
5
|
+
// var getOrig = resourceLoaderImplProto.get;
|
|
6
|
+
// resourceLoaderImplProto.get = function(url) {
|
|
7
|
+
// return getOrig.call(this, /^\//.test(url) ? "file://" + url : url);
|
|
8
|
+
// };
|
|
9
|
+
|
|
10
|
+
const platform = platformBrowserDynamic();
|
|
11
|
+
platform.bootstrapModule(AppModule);
|
package/lib/app/model/config.js
CHANGED
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
class urlReplace {
|
|
4
|
-
}
|
|
5
|
-
class Config {
|
|
6
|
-
constructor(obj) {
|
|
7
|
-
this.isEmpty = false;
|
|
8
|
-
if (obj) {
|
|
9
|
-
Object.assign(this, obj);
|
|
10
|
-
}
|
|
11
|
-
else {
|
|
12
|
-
this.isEmpty = true;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
get urlReplace() {
|
|
16
|
-
var urlReplace = this["pro-xy-url-replace"];
|
|
17
|
-
if (!urlReplace) {
|
|
18
|
-
urlReplace = {
|
|
19
|
-
missing: true
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
if (!urlReplace.replaces) {
|
|
23
|
-
urlReplace.replaces = [];
|
|
24
|
-
}
|
|
25
|
-
return urlReplace;
|
|
26
|
-
}
|
|
27
|
-
get autoResponder() {
|
|
28
|
-
var autoResponder = this["pro-xy-auto-responder"];
|
|
29
|
-
if (!autoResponder) {
|
|
30
|
-
autoResponder = {
|
|
31
|
-
missing: true
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
if (!autoResponder.responses) {
|
|
35
|
-
autoResponder.responses = [];
|
|
36
|
-
}
|
|
37
|
-
autoResponder.responses.forEach(obj => {
|
|
38
|
-
let p = obj.urlPattern;
|
|
39
|
-
obj.shortUrlPattern = p.length > 80 ? `${p.substring(0, 78)}..` : p;
|
|
40
|
-
});
|
|
41
|
-
return autoResponder;
|
|
42
|
-
}
|
|
43
|
-
get delay() {
|
|
44
|
-
var delay = this["pro-xy-delay"];
|
|
45
|
-
if (!delay) {
|
|
46
|
-
delay = {
|
|
47
|
-
missing: true
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
if (!delay.rules) {
|
|
51
|
-
delay.rules = [];
|
|
52
|
-
}
|
|
53
|
-
return delay;
|
|
54
|
-
}
|
|
55
|
-
addAutoResponse(response) {
|
|
56
|
-
var autoResponder = this.autoResponder;
|
|
57
|
-
if (autoResponder.missing) {
|
|
58
|
-
autoResponder = this["pro-xy-auto-responder"] = {
|
|
59
|
-
disabled: false,
|
|
60
|
-
responses: []
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
if (!autoResponder.responses) {
|
|
64
|
-
autoResponder.responses = [];
|
|
65
|
-
}
|
|
66
|
-
autoResponder.responses.push(response);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
exports.Config = Config;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class urlReplace {
|
|
4
|
+
}
|
|
5
|
+
class Config {
|
|
6
|
+
constructor(obj) {
|
|
7
|
+
this.isEmpty = false;
|
|
8
|
+
if (obj) {
|
|
9
|
+
Object.assign(this, obj);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
this.isEmpty = true;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
get urlReplace() {
|
|
16
|
+
var urlReplace = this["pro-xy-url-replace"];
|
|
17
|
+
if (!urlReplace) {
|
|
18
|
+
urlReplace = {
|
|
19
|
+
missing: true
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
if (!urlReplace.replaces) {
|
|
23
|
+
urlReplace.replaces = [];
|
|
24
|
+
}
|
|
25
|
+
return urlReplace;
|
|
26
|
+
}
|
|
27
|
+
get autoResponder() {
|
|
28
|
+
var autoResponder = this["pro-xy-auto-responder"];
|
|
29
|
+
if (!autoResponder) {
|
|
30
|
+
autoResponder = {
|
|
31
|
+
missing: true
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
if (!autoResponder.responses) {
|
|
35
|
+
autoResponder.responses = [];
|
|
36
|
+
}
|
|
37
|
+
autoResponder.responses.forEach(obj => {
|
|
38
|
+
let p = obj.urlPattern;
|
|
39
|
+
obj.shortUrlPattern = p.length > 80 ? `${p.substring(0, 78)}..` : p;
|
|
40
|
+
});
|
|
41
|
+
return autoResponder;
|
|
42
|
+
}
|
|
43
|
+
get delay() {
|
|
44
|
+
var delay = this["pro-xy-delay"];
|
|
45
|
+
if (!delay) {
|
|
46
|
+
delay = {
|
|
47
|
+
missing: true
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
if (!delay.rules) {
|
|
51
|
+
delay.rules = [];
|
|
52
|
+
}
|
|
53
|
+
return delay;
|
|
54
|
+
}
|
|
55
|
+
addAutoResponse(response) {
|
|
56
|
+
var autoResponder = this.autoResponder;
|
|
57
|
+
if (autoResponder.missing) {
|
|
58
|
+
autoResponder = this["pro-xy-auto-responder"] = {
|
|
59
|
+
disabled: false,
|
|
60
|
+
responses: []
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
if (!autoResponder.responses) {
|
|
64
|
+
autoResponder.responses = [];
|
|
65
|
+
}
|
|
66
|
+
autoResponder.responses.push(response);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.Config = Config;
|
package/lib/app/model/config.ts
CHANGED
|
@@ -1,79 +1,79 @@
|
|
|
1
|
-
class urlReplace {
|
|
2
|
-
disabled: boolean;
|
|
3
|
-
replaces: { name: string, pattern: string, replacement: string, disabled: boolean }[];
|
|
4
|
-
replaceBackHeaders: string[]
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export class Config {
|
|
9
|
-
plugins: string[]
|
|
10
|
-
|
|
11
|
-
isEmpty = false
|
|
12
|
-
|
|
13
|
-
constructor(obj?) {
|
|
14
|
-
if (obj) {
|
|
15
|
-
Object.assign(this, obj);
|
|
16
|
-
} else {
|
|
17
|
-
this.isEmpty = true;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
get urlReplace(): urlReplace {
|
|
22
|
-
var urlReplace = this["pro-xy-url-replace"];
|
|
23
|
-
if (!urlReplace) {
|
|
24
|
-
urlReplace = {
|
|
25
|
-
missing: true
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
if (!urlReplace.replaces) {
|
|
29
|
-
urlReplace.replaces = [];
|
|
30
|
-
}
|
|
31
|
-
return urlReplace;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
get autoResponder() {
|
|
35
|
-
var autoResponder = this["pro-xy-auto-responder"];
|
|
36
|
-
if (!autoResponder) {
|
|
37
|
-
autoResponder = {
|
|
38
|
-
missing: true
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
if (!autoResponder.responses) {
|
|
42
|
-
autoResponder.responses = [];
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
autoResponder.responses.forEach(obj => {
|
|
46
|
-
let p = obj.urlPattern;
|
|
47
|
-
obj.shortUrlPattern = p.length > 80 ? `${p.substring(0, 78)}..` : p;
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
return autoResponder;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
get delay() {
|
|
54
|
-
var delay = this["pro-xy-delay"];
|
|
55
|
-
if (!delay) {
|
|
56
|
-
delay = {
|
|
57
|
-
missing: true
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
if (!delay.rules) {
|
|
61
|
-
delay.rules = [];
|
|
62
|
-
}
|
|
63
|
-
return delay;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
addAutoResponse(response) {
|
|
67
|
-
var autoResponder = this.autoResponder;
|
|
68
|
-
if (autoResponder.missing) {
|
|
69
|
-
autoResponder = this["pro-xy-auto-responder"] = {
|
|
70
|
-
disabled: false,
|
|
71
|
-
responses: []
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
if (!autoResponder.responses) {
|
|
75
|
-
autoResponder.responses = [];
|
|
76
|
-
}
|
|
77
|
-
autoResponder.responses.push(response);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
1
|
+
class urlReplace {
|
|
2
|
+
disabled: boolean;
|
|
3
|
+
replaces: { name: string, pattern: string, replacement: string, disabled: boolean }[];
|
|
4
|
+
replaceBackHeaders: string[]
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export class Config {
|
|
9
|
+
plugins: string[]
|
|
10
|
+
|
|
11
|
+
isEmpty = false
|
|
12
|
+
|
|
13
|
+
constructor(obj?) {
|
|
14
|
+
if (obj) {
|
|
15
|
+
Object.assign(this, obj);
|
|
16
|
+
} else {
|
|
17
|
+
this.isEmpty = true;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
get urlReplace(): urlReplace {
|
|
22
|
+
var urlReplace = this["pro-xy-url-replace"];
|
|
23
|
+
if (!urlReplace) {
|
|
24
|
+
urlReplace = {
|
|
25
|
+
missing: true
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
if (!urlReplace.replaces) {
|
|
29
|
+
urlReplace.replaces = [];
|
|
30
|
+
}
|
|
31
|
+
return urlReplace;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
get autoResponder() {
|
|
35
|
+
var autoResponder = this["pro-xy-auto-responder"];
|
|
36
|
+
if (!autoResponder) {
|
|
37
|
+
autoResponder = {
|
|
38
|
+
missing: true
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
if (!autoResponder.responses) {
|
|
42
|
+
autoResponder.responses = [];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
autoResponder.responses.forEach(obj => {
|
|
46
|
+
let p = obj.urlPattern;
|
|
47
|
+
obj.shortUrlPattern = p.length > 80 ? `${p.substring(0, 78)}..` : p;
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
return autoResponder;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
get delay() {
|
|
54
|
+
var delay = this["pro-xy-delay"];
|
|
55
|
+
if (!delay) {
|
|
56
|
+
delay = {
|
|
57
|
+
missing: true
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
if (!delay.rules) {
|
|
61
|
+
delay.rules = [];
|
|
62
|
+
}
|
|
63
|
+
return delay;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
addAutoResponse(response) {
|
|
67
|
+
var autoResponder = this.autoResponder;
|
|
68
|
+
if (autoResponder.missing) {
|
|
69
|
+
autoResponder = this["pro-xy-auto-responder"] = {
|
|
70
|
+
disabled: false,
|
|
71
|
+
responses: []
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
if (!autoResponder.responses) {
|
|
75
|
+
autoResponder.responses = [];
|
|
76
|
+
}
|
|
77
|
+
autoResponder.responses.push(response);
|
|
78
|
+
}
|
|
79
|
+
}
|
package/lib/app/model/http.js
CHANGED
|
@@ -1,116 +1,116 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var http = nw.require("http");
|
|
4
|
-
var zlib = nw.require("zlib");
|
|
5
|
-
var url = nw.require("url");
|
|
6
|
-
var stringify = nw.require("json-stable-stringify");
|
|
7
|
-
const core_1 = require("@angular/core");
|
|
8
|
-
var Update;
|
|
9
|
-
(function (Update) {
|
|
10
|
-
Update[Update["RES_HEADERS"] = 0] = "RES_HEADERS";
|
|
11
|
-
Update[Update["REQ_BODY"] = 1] = "REQ_BODY";
|
|
12
|
-
Update[Update["RES_BODY"] = 2] = "RES_BODY";
|
|
13
|
-
})(Update = exports.Update || (exports.Update = {}));
|
|
14
|
-
class ReqRes {
|
|
15
|
-
constructor(_req) {
|
|
16
|
-
this._req = _req;
|
|
17
|
-
this._reqBody = [];
|
|
18
|
-
this._resBody = [];
|
|
19
|
-
this.reqBody = "";
|
|
20
|
-
this.resBody = "";
|
|
21
|
-
this.resFlags = "";
|
|
22
|
-
this.reqFlags = "";
|
|
23
|
-
this.updated = new core_1.EventEmitter();
|
|
24
|
-
this.isFinished = false;
|
|
25
|
-
this.isReqFinished = false;
|
|
26
|
-
}
|
|
27
|
-
set res(res) {
|
|
28
|
-
this._res = res;
|
|
29
|
-
this.updated.emit(Update.RES_HEADERS);
|
|
30
|
-
}
|
|
31
|
-
get id() { return this._req && this._req.id; }
|
|
32
|
-
get url() { return this._req && this._req.url; }
|
|
33
|
-
get urlParts() { return this.url && url.parse(this.url); }
|
|
34
|
-
get method() { return this._req && this._req.method; }
|
|
35
|
-
get isReplaced() { return !!this.getReqHeader("x-pro-xy-url-replace"); }
|
|
36
|
-
get statusCode() { return this._res && this._res.statusCode; }
|
|
37
|
-
get reqContentType() {
|
|
38
|
-
var ct = this.getReqHeader('content-type');
|
|
39
|
-
return ct && ct.split(";")[0];
|
|
40
|
-
}
|
|
41
|
-
get resContentType() {
|
|
42
|
-
var ct = this.getResHeader('content-type');
|
|
43
|
-
return ct && ct.split(";")[0];
|
|
44
|
-
}
|
|
45
|
-
get reqHeaders() { return Object.assign({}, this._req && this._req.headers); }
|
|
46
|
-
get resHeaders() { return Object.assign({}, this._res && this._res.headers); }
|
|
47
|
-
get reqHeadersStr() {
|
|
48
|
-
return Object.keys(this.reqHeaders).map(name => `${name}: ${this.reqHeaders[name]}`).join("\n");
|
|
49
|
-
}
|
|
50
|
-
get resHeadersStr() {
|
|
51
|
-
return Object.keys(this.resHeaders).map(name => `${name}: ${this.resHeaders[name]}`).join("\n");
|
|
52
|
-
}
|
|
53
|
-
get statusStr() {
|
|
54
|
-
return this.statusCode ? `${this.statusCode} ${http.STATUS_CODES[this.statusCode]}` : "";
|
|
55
|
-
}
|
|
56
|
-
getResHeader(name) {
|
|
57
|
-
return this.resHeaders[name];
|
|
58
|
-
}
|
|
59
|
-
getReqHeader(name) {
|
|
60
|
-
return this.reqHeaders[name];
|
|
61
|
-
}
|
|
62
|
-
addReqChunk(chunk) {
|
|
63
|
-
chunk && this._reqBody.push(ab2b(chunk));
|
|
64
|
-
}
|
|
65
|
-
addResChunk(chunk) {
|
|
66
|
-
chunk && this._resBody.push(ab2b(chunk));
|
|
67
|
-
}
|
|
68
|
-
endReq() {
|
|
69
|
-
this.reqBody = Buffer.concat(this._reqBody).toString();
|
|
70
|
-
if (this.reqBody && this.reqContentType == "application/json") {
|
|
71
|
-
try {
|
|
72
|
-
this.reqBody = stringify(JSON.parse(this.reqBody), { space: 2 });
|
|
73
|
-
this.reqFlags += "[JSON formatted & sorted]";
|
|
74
|
-
}
|
|
75
|
-
catch (e) {
|
|
76
|
-
this.reqFlags += "[UNPARSABLE JSON]";
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
this.updated.emit(Update.REQ_BODY);
|
|
80
|
-
this.isReqFinished = true;
|
|
81
|
-
}
|
|
82
|
-
endRes() {
|
|
83
|
-
var buff = Buffer.concat(this._resBody);
|
|
84
|
-
if (this.isGzip) {
|
|
85
|
-
this.resFlags += "[GZIP decoded]";
|
|
86
|
-
buff = zlib.gunzipSync(buff);
|
|
87
|
-
}
|
|
88
|
-
this.resBody = buff.toString('utf8');
|
|
89
|
-
if (this.resBody && this.resContentType == "application/json") {
|
|
90
|
-
try {
|
|
91
|
-
this.resBody = stringify(JSON.parse(this.resBody), { space: 2 });
|
|
92
|
-
this.resFlags += "[JSON formatted & sorted]";
|
|
93
|
-
}
|
|
94
|
-
catch (e) {
|
|
95
|
-
this.resFlags += "[UNPARSABLE JSON]";
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
this.updated.emit(Update.RES_BODY);
|
|
99
|
-
this.isFinished = true;
|
|
100
|
-
}
|
|
101
|
-
get isGzip() {
|
|
102
|
-
return this.getResHeader("content-encoding") == "gzip";
|
|
103
|
-
}
|
|
104
|
-
toString() {
|
|
105
|
-
return `${this.method} ${this.url}\n${this.reqHeadersStr}\n\n${this.reqBody}\n\n${this.statusStr}\n${this.resHeadersStr}\n\n${this.resBody}`;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
exports.ReqRes = ReqRes;
|
|
109
|
-
function ab2b(ab) {
|
|
110
|
-
var buffer = new Buffer(ab.byteLength);
|
|
111
|
-
var view = new Uint8Array(ab);
|
|
112
|
-
for (var i = 0; i < buffer.length; ++i) {
|
|
113
|
-
buffer[i] = view[i];
|
|
114
|
-
}
|
|
115
|
-
return buffer;
|
|
116
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var http = nw.require("http");
|
|
4
|
+
var zlib = nw.require("zlib");
|
|
5
|
+
var url = nw.require("url");
|
|
6
|
+
var stringify = nw.require("json-stable-stringify");
|
|
7
|
+
const core_1 = require("@angular/core");
|
|
8
|
+
var Update;
|
|
9
|
+
(function (Update) {
|
|
10
|
+
Update[Update["RES_HEADERS"] = 0] = "RES_HEADERS";
|
|
11
|
+
Update[Update["REQ_BODY"] = 1] = "REQ_BODY";
|
|
12
|
+
Update[Update["RES_BODY"] = 2] = "RES_BODY";
|
|
13
|
+
})(Update = exports.Update || (exports.Update = {}));
|
|
14
|
+
class ReqRes {
|
|
15
|
+
constructor(_req) {
|
|
16
|
+
this._req = _req;
|
|
17
|
+
this._reqBody = [];
|
|
18
|
+
this._resBody = [];
|
|
19
|
+
this.reqBody = "";
|
|
20
|
+
this.resBody = "";
|
|
21
|
+
this.resFlags = "";
|
|
22
|
+
this.reqFlags = "";
|
|
23
|
+
this.updated = new core_1.EventEmitter();
|
|
24
|
+
this.isFinished = false;
|
|
25
|
+
this.isReqFinished = false;
|
|
26
|
+
}
|
|
27
|
+
set res(res) {
|
|
28
|
+
this._res = res;
|
|
29
|
+
this.updated.emit(Update.RES_HEADERS);
|
|
30
|
+
}
|
|
31
|
+
get id() { return this._req && this._req.id; }
|
|
32
|
+
get url() { return this._req && this._req.url; }
|
|
33
|
+
get urlParts() { return this.url && url.parse(this.url); }
|
|
34
|
+
get method() { return this._req && this._req.method; }
|
|
35
|
+
get isReplaced() { return !!this.getReqHeader("x-pro-xy-url-replace"); }
|
|
36
|
+
get statusCode() { return this._res && this._res.statusCode; }
|
|
37
|
+
get reqContentType() {
|
|
38
|
+
var ct = this.getReqHeader('content-type');
|
|
39
|
+
return ct && ct.split(";")[0];
|
|
40
|
+
}
|
|
41
|
+
get resContentType() {
|
|
42
|
+
var ct = this.getResHeader('content-type');
|
|
43
|
+
return ct && ct.split(";")[0];
|
|
44
|
+
}
|
|
45
|
+
get reqHeaders() { return Object.assign({}, this._req && this._req.headers); }
|
|
46
|
+
get resHeaders() { return Object.assign({}, this._res && this._res.headers); }
|
|
47
|
+
get reqHeadersStr() {
|
|
48
|
+
return Object.keys(this.reqHeaders).map(name => `${name}: ${this.reqHeaders[name]}`).join("\n");
|
|
49
|
+
}
|
|
50
|
+
get resHeadersStr() {
|
|
51
|
+
return Object.keys(this.resHeaders).map(name => `${name}: ${this.resHeaders[name]}`).join("\n");
|
|
52
|
+
}
|
|
53
|
+
get statusStr() {
|
|
54
|
+
return this.statusCode ? `${this.statusCode} ${http.STATUS_CODES[this.statusCode]}` : "";
|
|
55
|
+
}
|
|
56
|
+
getResHeader(name) {
|
|
57
|
+
return this.resHeaders[name];
|
|
58
|
+
}
|
|
59
|
+
getReqHeader(name) {
|
|
60
|
+
return this.reqHeaders[name];
|
|
61
|
+
}
|
|
62
|
+
addReqChunk(chunk) {
|
|
63
|
+
chunk && this._reqBody.push(ab2b(chunk));
|
|
64
|
+
}
|
|
65
|
+
addResChunk(chunk) {
|
|
66
|
+
chunk && this._resBody.push(ab2b(chunk));
|
|
67
|
+
}
|
|
68
|
+
endReq() {
|
|
69
|
+
this.reqBody = Buffer.concat(this._reqBody).toString();
|
|
70
|
+
if (this.reqBody && this.reqContentType == "application/json") {
|
|
71
|
+
try {
|
|
72
|
+
this.reqBody = stringify(JSON.parse(this.reqBody), { space: 2 });
|
|
73
|
+
this.reqFlags += "[JSON formatted & sorted]";
|
|
74
|
+
}
|
|
75
|
+
catch (e) {
|
|
76
|
+
this.reqFlags += "[UNPARSABLE JSON]";
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
this.updated.emit(Update.REQ_BODY);
|
|
80
|
+
this.isReqFinished = true;
|
|
81
|
+
}
|
|
82
|
+
endRes() {
|
|
83
|
+
var buff = Buffer.concat(this._resBody);
|
|
84
|
+
if (this.isGzip) {
|
|
85
|
+
this.resFlags += "[GZIP decoded]";
|
|
86
|
+
buff = zlib.gunzipSync(buff);
|
|
87
|
+
}
|
|
88
|
+
this.resBody = buff.toString('utf8');
|
|
89
|
+
if (this.resBody && this.resContentType == "application/json") {
|
|
90
|
+
try {
|
|
91
|
+
this.resBody = stringify(JSON.parse(this.resBody), { space: 2 });
|
|
92
|
+
this.resFlags += "[JSON formatted & sorted]";
|
|
93
|
+
}
|
|
94
|
+
catch (e) {
|
|
95
|
+
this.resFlags += "[UNPARSABLE JSON]";
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
this.updated.emit(Update.RES_BODY);
|
|
99
|
+
this.isFinished = true;
|
|
100
|
+
}
|
|
101
|
+
get isGzip() {
|
|
102
|
+
return this.getResHeader("content-encoding") == "gzip";
|
|
103
|
+
}
|
|
104
|
+
toString() {
|
|
105
|
+
return `${this.method} ${this.url}\n${this.reqHeadersStr}\n\n${this.reqBody}\n\n${this.statusStr}\n${this.resHeadersStr}\n\n${this.resBody}`;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.ReqRes = ReqRes;
|
|
109
|
+
function ab2b(ab) {
|
|
110
|
+
var buffer = new Buffer(ab.byteLength);
|
|
111
|
+
var view = new Uint8Array(ab);
|
|
112
|
+
for (var i = 0; i < buffer.length; ++i) {
|
|
113
|
+
buffer[i] = view[i];
|
|
114
|
+
}
|
|
115
|
+
return buffer;
|
|
116
|
+
}
|