Skip to content

Commit

Permalink
feat: change mellow format
Browse files Browse the repository at this point in the history
close #91
  • Loading branch information
geekdada committed Jun 28, 2020
1 parent 641b81e commit 95182a4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(', ');
}

Expand Down
8 changes: 6 additions & 2 deletions lib/utils/v2ray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
'@',
Expand All @@ -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;
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/utils/snapshots/index.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)`
Expand Down
Binary file modified test/utils/snapshots/index.test.ts.snap
Binary file not shown.

0 comments on commit 95182a4

Please sign in to comment.