From 95182a4af73a67b93d0355f3c302ccf8a79511aa Mon Sep 17 00:00:00 2001 From: Roy Li Date: Sun, 28 Jun 2020 21:16:16 +0800 Subject: [PATCH] feat: change mellow format close #91 --- lib/utils/index.ts | 2 +- lib/utils/v2ray.ts | 8 ++++++-- test/utils/snapshots/index.test.ts.md | 4 ++-- test/utils/snapshots/index.test.ts.snap | Bin 433 -> 431 bytes 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/utils/index.ts b/lib/utils/index.ts index e5e53df46..b7fa15e4c 100644 --- a/lib/utils/index.ts +++ b/lib/utils/index.ts @@ -645,7 +645,7 @@ export const getMellowNodes = function( .map(nodeConfig => { switch (nodeConfig.type) { case NodeTypeEnum.Vmess: { - const uri = formatVmessUri(nodeConfig); + const uri = formatVmessUri(nodeConfig, { isMellow: true }); return [nodeConfig.nodeName, 'vmess1', uri.trim().replace('vmess://', 'vmess1://')].join(', '); } diff --git a/lib/utils/v2ray.ts b/lib/utils/v2ray.ts index 018fc763f..2f1dc699a 100644 --- a/lib/utils/v2ray.ts +++ b/lib/utils/v2ray.ts @@ -2,7 +2,7 @@ import { VmessNodeConfig } from "../types"; import queryString from 'query-string'; // https://github.com/v2ray/v2ray-core/issues/1569 -export const formatVmessUri = (nodeConfig: VmessNodeConfig): string => { +export const formatVmessUri = (nodeConfig: VmessNodeConfig, options?: { readonly isMellow: boolean }): string => { const uri: string[] = [ nodeConfig.uuid, '@', @@ -27,7 +27,11 @@ export const formatVmessUri = (nodeConfig: VmessNodeConfig): string => { }); } if (nodeConfig.host) { - queries[`ws.headers.host`] = nodeConfig.host; + if (options?.isMellow) { + queries[`ws.host`] = nodeConfig.host; + } else { + queries[`ws.headers.host`] = nodeConfig.host; + } } } diff --git a/test/utils/snapshots/index.test.ts.md b/test/utils/snapshots/index.test.ts.md index c99e4a462..c32ec2039 100644 --- a/test/utils/snapshots/index.test.ts.md +++ b/test/utils/snapshots/index.test.ts.md @@ -8,8 +8,8 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 - `Test Node 3, vmess1, vmess1://1386f85e-657b-4d6e-9d56-78badb75e1fd@1.1.1.1:8080/?network=ws&tls=false&ws.headers.host=example.com␊ - Test Node 3, vmess1, vmess1://1386f85e-657b-4d6e-9d56-78badb75e1fd@1.1.1.1:8080/?network=ws&tls=true&tls.allowInsecure=true&ws.headers.foo=bar&ws.headers.host=example.com␊ + `Test Node 3, vmess1, vmess1://1386f85e-657b-4d6e-9d56-78badb75e1fd@1.1.1.1:8080/?network=ws&tls=false&ws.host=example.com␊ + Test Node 3, vmess1, vmess1://1386f85e-657b-4d6e-9d56-78badb75e1fd@1.1.1.1:8080/?network=ws&tls=true&tls.allowInsecure=true&ws.headers.foo=bar&ws.host=example.com␊ Test Node 4, vmess1, vmess1://1386f85e-657b-4d6e-9d56-78badb75e1fd@1.1.1.1:8080/?network=tcp&tls=false␊ Test Node 5, vmess1, vmess1://1386f85e-657b-4d6e-9d56-78badb75e1fd@1.1.1.1:8080/?network=tcp&tls=true␊ 🇭🇰HK(Example), ss, ss://Y2hhY2hhMjAtaWV0Zi1wb2x5MTMwNTpwYXNzd29yZA@example.com:8443/?plugin=obfs-local%3Bobfs%3Dtls%3Bobfs-host%3Dgateway.icloud.com&group=Surgio#%F0%9F%87%AD%F0%9F%87%B0HK(Example)` diff --git a/test/utils/snapshots/index.test.ts.snap b/test/utils/snapshots/index.test.ts.snap index d91827b5329f785fe51ad7f6cc193148d541a106..96e8c91fff4a78fe45607d66749a9a86f6d70c02 100644 GIT binary patch literal 431 zcmV;g0Z{%yRzVCcIXj1yLnwz< zKe@~b+Q>d;+rVO>NqrFX9pQ2ajA`F*MNu@}E(Nv;QpvPj$?!`cm3^}$S+_nT2b4N4j()Ld{H?{<3xCpCkTI7d!*|ZV-rr7Um>wQ)9n5#!-Vqq% zn5lG%{XR$Iyc*-v6SX_gQnz?zHrkD}*$&grS@Xs(man_jy@iA-wqfYXZb*{eVB}CY zU=pDoCZfL28&R*##<+Y+m_ ZpL$me{E|I~6mFDr)b8X5??R69;*Qq#izFRiM7Yc;UFMOrBtZ8JH?{DvY&8yAd_pUevj0-a3WSO}DzAN~mn8s*E45_cm4jIRdk~U%W2T1#i13X#un7&F