dshost-plugin 0.1.3 → 0.1.4
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/lib/core.js +33 -6
- package/package.json +1 -1
package/lib/core.js
CHANGED
|
@@ -256,9 +256,13 @@ export function startAgent(opts) {
|
|
|
256
256
|
if (serveArtifactIfRequested(ws, msg)) return;
|
|
257
257
|
handleHttpRequest(ws, msg);
|
|
258
258
|
} else if (msg.type === 'http:body') {
|
|
259
|
+
const ab = artifactFormBodies.get(msg.streamId);
|
|
260
|
+
if (ab) { ab.push(un64(msg.data)); return; }
|
|
259
261
|
const stream = streams.get(msg.streamId);
|
|
260
262
|
if (stream && stream.dshReq) stream.dshReq.write(un64(msg.data));
|
|
261
263
|
} else if (msg.type === 'http:end') {
|
|
264
|
+
const ab = artifactFormBodies.get(msg.streamId);
|
|
265
|
+
if (ab) { artifactFormBodies.delete(msg.streamId); serveArtifactFromForm(ws, msg.streamId, Buffer.concat(ab)); return; }
|
|
262
266
|
const stream = streams.get(msg.streamId);
|
|
263
267
|
if (stream && stream.dshReq) stream.dshReq.end();
|
|
264
268
|
} else if (msg.type === 'ws:open') {
|
|
@@ -360,17 +364,40 @@ export function startAgent(opts) {
|
|
|
360
364
|
send(ws, { type: 'http:end', streamId });
|
|
361
365
|
}
|
|
362
366
|
|
|
367
|
+
const artifactFormBodies = new Map();
|
|
368
|
+
|
|
369
|
+
function serveArtifactFromForm(ws, sid, body) {
|
|
370
|
+
let pth = '';
|
|
371
|
+
const ct = 'application/x-www-form-urlencoded';
|
|
372
|
+
try { pth = new URLSearchParams(body.toString('utf8')).get('path') || ''; } catch {}
|
|
373
|
+
serveArtifactResolved(ws, sid, pth);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
function serveArtifactResolved(ws, sid, rawPath) {
|
|
377
|
+
const fail = (status, text) => artifactRespond(ws, sid, status,
|
|
378
|
+
{ 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' },
|
|
379
|
+
Buffer.from(JSON.stringify({ ok: false, error: { code: 'artifact', message: text } })));
|
|
380
|
+
return serveArtifactFile(ws, sid, rawPath, fail);
|
|
381
|
+
}
|
|
382
|
+
|
|
363
383
|
function serveArtifactIfRequested(ws, msg) {
|
|
364
|
-
if (msg.method !== 'GET') return false;
|
|
365
384
|
let u;
|
|
366
385
|
try { u = new URL(msg.path, 'http://local'); } catch { return false; }
|
|
367
386
|
if (u.pathname !== '/api/host.artifact') return false;
|
|
368
387
|
const sid = msg.streamId;
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
388
|
+
if (msg.method === 'POST') {
|
|
389
|
+
// [EO规避] 该URL的GET响应会被EdgeOne静默吞杀(三出口实测),改走POST表单体
|
|
390
|
+
artifactFormBodies.set(sid, []);
|
|
391
|
+
return true;
|
|
392
|
+
}
|
|
393
|
+
if (msg.method === 'GET') {
|
|
394
|
+
const pth = u.searchParams.get('path') || '';
|
|
395
|
+
return serveArtifactResolved(ws, sid, pth);
|
|
396
|
+
}
|
|
397
|
+
return false;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
function serveArtifactFile(ws, sid, rawPath, fail) {
|
|
374
401
|
const ext = path.extname(rawPath).toLowerCase();
|
|
375
402
|
const dotfile = /(^|\/)(\.[a-z0-9_.-]+)$/i.test(path.basename(rawPath));
|
|
376
403
|
if (!ARTIFACT_TEXT_EXT.has(ext) && !dotfile) return fail(415, `unsupported artifact type: ${ext || '(none)'}`);
|
package/package.json
CHANGED