@jonathanleelx/meddle 0.0.3 → 0.1.1
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/bin/commands/version.js +40 -0
- package/bin/index.js +2 -0
- package/dist/core/streaming-response.d.ts +2 -0
- package/dist/core/streaming-response.d.ts.map +1 -0
- package/dist/core/streaming-response.js +18 -0
- package/dist/core/streaming-response.js.map +1 -0
- package/index.js +9 -5
- package/package.json +1 -1
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* meddle version - Print version information
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const os = require('os')
|
|
6
|
+
const path = require('path')
|
|
7
|
+
const output = require('../lib/output')
|
|
8
|
+
|
|
9
|
+
const args = process.argv.slice(2)
|
|
10
|
+
const jsonFlag = args.includes('--json')
|
|
11
|
+
output.setJsonMode(jsonFlag)
|
|
12
|
+
|
|
13
|
+
function getVersionInfo() {
|
|
14
|
+
const pkg = require(path.join(__dirname, '../../package.json'))
|
|
15
|
+
return {
|
|
16
|
+
name: pkg.name,
|
|
17
|
+
version: pkg.version,
|
|
18
|
+
node: process.version,
|
|
19
|
+
platform: `${os.platform()} ${os.arch()}`,
|
|
20
|
+
homepage: pkg.homepage,
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function run() {
|
|
25
|
+
const info = getVersionInfo()
|
|
26
|
+
|
|
27
|
+
if (output.isJsonMode()) {
|
|
28
|
+
output.jsonRaw(info)
|
|
29
|
+
return
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
output.header('Meddle Version')
|
|
33
|
+
output.kv('Package', info.name)
|
|
34
|
+
output.kv('Version', info.version)
|
|
35
|
+
output.kv('Node.js', info.node)
|
|
36
|
+
output.kv('Platform', info.platform)
|
|
37
|
+
output.kv('Homepage', info.homepage)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
run()
|
package/bin/index.js
CHANGED
|
@@ -31,6 +31,7 @@ const commands = {
|
|
|
31
31
|
'supervise': './commands/supervise.js',
|
|
32
32
|
'url': './commands/url.js',
|
|
33
33
|
'status': './commands/status.js',
|
|
34
|
+
'version': './commands/version.js',
|
|
34
35
|
'session': './commands/session/index.js',
|
|
35
36
|
'mock': './commands/mock/index.js',
|
|
36
37
|
'route': './commands/route/index.js'
|
|
@@ -68,6 +69,7 @@ Meddle - 开发代理工具
|
|
|
68
69
|
meddle doctor 检查配置文件健康状况
|
|
69
70
|
meddle url 获取代理 URL
|
|
70
71
|
meddle status 查看代理状态
|
|
72
|
+
meddle version 查看版本信息
|
|
71
73
|
|
|
72
74
|
Session 命令 (多实例隔离,预览功能):
|
|
73
75
|
meddle session create [--name <label>] [--port <port>]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streaming-response.d.ts","sourceRoot":"","sources":["../../core/streaming-response.ts"],"names":[],"mappings":"AAQA,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAAG,OAAO,CAMlF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isStreamingResponse = isStreamingResponse;
|
|
4
|
+
const STREAMING_CONTENT_TYPES = [
|
|
5
|
+
'text/event-stream',
|
|
6
|
+
'application/x-ndjson',
|
|
7
|
+
'application/ndjson',
|
|
8
|
+
'application/json-seq',
|
|
9
|
+
'application/stream+json',
|
|
10
|
+
];
|
|
11
|
+
function isStreamingResponse(headers = {}) {
|
|
12
|
+
const contentType = Object.entries(headers).find(([key]) => key.toLowerCase() === 'content-type')?.[1];
|
|
13
|
+
if (typeof contentType !== 'string')
|
|
14
|
+
return false;
|
|
15
|
+
const mediaType = contentType.split(';', 1)[0].trim().toLowerCase();
|
|
16
|
+
return STREAMING_CONTENT_TYPES.includes(mediaType);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=streaming-response.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streaming-response.js","sourceRoot":"","sources":["../../core/streaming-response.ts"],"names":[],"mappings":";;AAQA,kDAMC;AAdD,MAAM,uBAAuB,GAAG;IAC5B,mBAAmB;IACnB,sBAAsB;IACtB,oBAAoB;IACpB,sBAAsB;IACtB,yBAAyB;CAC5B,CAAA;AAED,SAAgB,mBAAmB,CAAC,UAAmC,EAAE;IACrE,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,cAAc,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IACtG,IAAI,OAAO,WAAW,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;IAEjD,MAAM,SAAS,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;IACnE,OAAO,uBAAuB,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAA;AACtD,CAAC"}
|
package/index.js
CHANGED
|
@@ -106,6 +106,7 @@ const { createMockHandler } = require('./dist/core/mock-handler')
|
|
|
106
106
|
const { handleMapLocalRequest } = require('./dist/core/map-local')
|
|
107
107
|
const { createRouteLoader } = require('./dist/core/route-loader')
|
|
108
108
|
const { createPluginIntercept } = require('./dist/core/plugin-intercept')
|
|
109
|
+
const { isStreamingResponse } = require('./dist/core/streaming-response')
|
|
109
110
|
const { createPluginBootstrapRunner } = require('./dist/core/plugin-bootstrap-runner')
|
|
110
111
|
const { openBrowserWithProxy } = require('./dist/core/browser')
|
|
111
112
|
const { handleLocalRequest } = require('./dist/core/static-server')
|
|
@@ -382,10 +383,11 @@ const proxyServer = http.createServer(async (req, res) => {
|
|
|
382
383
|
const url = new URL(target.startsWith('http') ? target : req.url, 'http://' + req.headers.host)
|
|
383
384
|
const routeChanged = source !== url.href
|
|
384
385
|
const startTime = Date.now()
|
|
385
|
-
const intercepting = pluginIntercept.shouldInterceptResponse()
|
|
386
|
-
|
|
387
386
|
const proxyReq = http.request(url, { method: req.method, headers: stripProxyHeaders(req.headers) }, (proxyRes) => {
|
|
388
387
|
const resChunks = []
|
|
388
|
+
const pluginResponseInterception = pluginIntercept.shouldInterceptResponse()
|
|
389
|
+
const streamingResponse = isStreamingResponse(proxyRes.headers)
|
|
390
|
+
const intercepting = pluginResponseInterception && !streamingResponse
|
|
389
391
|
let proxyResponseSettled = false
|
|
390
392
|
const handleProxyResponseError = (err) => {
|
|
391
393
|
if (proxyResponseSettled) return
|
|
@@ -426,7 +428,7 @@ const proxyServer = http.createServer(async (req, res) => {
|
|
|
426
428
|
duration: Date.now() - startTime,
|
|
427
429
|
...clientIdentity,
|
|
428
430
|
}
|
|
429
|
-
if (!
|
|
431
|
+
if (!pluginResponseInterception) pluginIntercept.emitLegacyResponseToPlugins(logData)
|
|
430
432
|
const responseEncoding = proxyRes.headers && proxyRes.headers['content-encoding']
|
|
431
433
|
// 获取 inspection 信息
|
|
432
434
|
const inspectionStages = routeDecision.meta?._inspectionStages || []
|
|
@@ -624,10 +626,12 @@ proxyServer.on('connect', async (req, socket, head) => {
|
|
|
624
626
|
|
|
625
627
|
const routeChanged = source !== target
|
|
626
628
|
const startTime = Date.now()
|
|
627
|
-
const intercepting = pluginIntercept.shouldInterceptResponse()
|
|
628
629
|
try {
|
|
629
630
|
const proxyRes = await makeProxyRequest(target, req.method, stripProxyHeaders(req.headers), reqBody)
|
|
630
631
|
const resChunks = []
|
|
632
|
+
const pluginResponseInterception = pluginIntercept.shouldInterceptResponse()
|
|
633
|
+
const streamingResponse = isStreamingResponse(proxyRes.headers)
|
|
634
|
+
const intercepting = pluginResponseInterception && !streamingResponse
|
|
631
635
|
let proxyResponseSettled = false
|
|
632
636
|
const handleProxyResponseError = (err) => {
|
|
633
637
|
if (proxyResponseSettled) return
|
|
@@ -669,7 +673,7 @@ proxyServer.on('connect', async (req, socket, head) => {
|
|
|
669
673
|
statusCode: proxyRes.statusCode, duration: Date.now() - startTime,
|
|
670
674
|
...requestClientIdentity,
|
|
671
675
|
}
|
|
672
|
-
if (!
|
|
676
|
+
if (!pluginResponseInterception) pluginIntercept.emitLegacyResponseToPlugins(logData)
|
|
673
677
|
const responseEncoding = proxyRes.headers && proxyRes.headers['content-encoding']
|
|
674
678
|
// 获取 inspection 信息
|
|
675
679
|
const inspectionStages = routeDecision.meta?._inspectionStages || []
|
package/package.json
CHANGED