@@ -61,13 +61,15 @@ export default function Egern_Producer() {
6161 '2022-blake3-aes-256-gcm' ,
6262 ] . includes ( proxy . cipher ) ) ) ||
6363 ( proxy . type === 'vmess' &&
64- ! [ 'http' , 'ws' , 'tcp' ] . includes ( proxy . network ) &&
64+ ! [ 'h2' , ' http', 'ws' , 'tcp' ] . includes ( proxy . network ) &&
6565 proxy . network ) ||
6666 ( proxy . type === 'trojan' &&
6767 ! [ 'http' , 'ws' , 'tcp' ] . includes ( proxy . network ) &&
6868 proxy . network ) ||
6969 ( proxy . type === 'vless' &&
70- ( ( ! [ 'http' , 'ws' , 'tcp' ] . includes ( proxy . network ) &&
70+ ( ( ! [ 'h2' , 'http' , 'ws' , 'tcp' ] . includes (
71+ proxy . network ,
72+ ) &&
7173 proxy . network ) ||
7274 ( typeof proxy . flow !== 'undefined' &&
7375 ! [ 'xtls-rprx-vision' , '' ] . includes (
@@ -132,6 +134,24 @@ export default function Egern_Producer() {
132134 }
133135 : { } ) ,
134136 } ;
137+ } else if ( proxy . type === 'https' ) {
138+ proxy = {
139+ type : 'https' ,
140+ name : proxy . name ,
141+ server : proxy . server ,
142+ port : proxy . port ,
143+ username : proxy . username ,
144+ password : proxy . password ,
145+ ...( hasHeaders ( proxy )
146+ ? {
147+ headers : proxy . headers ,
148+ }
149+ : { } ) ,
150+ tfo : proxy . tfo || proxy [ 'fast-open' ] ,
151+ next_hop : proxy . next_hop ,
152+ sni : proxy . sni ,
153+ skip_tls_verify : proxy [ 'skip-cert-verify' ] ,
154+ } ;
135155 } else if ( proxy . type === 'socks5' ) {
136156 proxy = {
137157 type : 'socks5' ,
@@ -312,13 +332,8 @@ export default function Egern_Producer() {
312332 path : Array . isArray ( proxy [ 'h2-opts' ] ?. path )
313333 ? proxy [ 'h2-opts' ] ?. path [ 0 ]
314334 : proxy [ 'h2-opts' ] ?. path ,
315- headers : {
316- Host : Array . isArray (
317- proxy [ 'h2-opts' ] ?. headers ?. Host ,
318- )
319- ? proxy [ 'h2-opts' ] ?. headers ?. Host [ 0 ]
320- : proxy [ 'h2-opts' ] ?. headers ?. Host ,
321- } ,
335+ headers : getH2Headers ( proxy [ 'h2-opts' ] ) ,
336+ sni : proxy . sni ,
322337 skip_tls_verify : proxy [ 'skip-cert-verify' ] ,
323338 } ,
324339 } ;
@@ -393,6 +408,18 @@ export default function Egern_Producer() {
393408 skip_tls_verify : proxy [ 'skip-cert-verify' ] ,
394409 } ,
395410 } ;
411+ } else if ( proxy . network === 'h2' ) {
412+ proxy . transport = {
413+ http2 : {
414+ method : proxy [ 'h2-opts' ] ?. method ,
415+ path : Array . isArray ( proxy [ 'h2-opts' ] ?. path )
416+ ? proxy [ 'h2-opts' ] ?. path [ 0 ]
417+ : proxy [ 'h2-opts' ] ?. path ,
418+ headers : getH2Headers ( proxy [ 'h2-opts' ] ) ,
419+ sni : proxy . sni ,
420+ skip_tls_verify : proxy [ 'skip-cert-verify' ] ,
421+ } ,
422+ } ;
396423 } else if ( proxy . network === 'tcp' || ! proxy . network ) {
397424 let reality ;
398425 if (
@@ -518,6 +545,16 @@ export default function Egern_Producer() {
518545 } ;
519546 }
520547 }
548+ const fingerprintSha256 = getFingerprintSha256 ( original ) ;
549+ if ( fingerprintSha256 ) {
550+ if ( supportsRootFingerprintSha256 ( original , proxy ) ) {
551+ proxy . fingerprint_sha256 = fingerprintSha256 ;
552+ }
553+ addTransportFingerprintSha256 (
554+ proxy . transport ,
555+ fingerprintSha256 ,
556+ ) ;
557+ }
521558 if (
522559 [
523560 'socks5' ,
@@ -611,3 +648,72 @@ function hasHeaders(proxy) {
611648 Object . keys ( proxy . headers ) . length > 0
612649 ) ;
613650}
651+
652+ function getFirstHeaderValue ( headers , ...keys ) {
653+ for ( const key of keys ) {
654+ const value = getFirstValue ( headers ?. [ key ] ) ;
655+ if ( value ) return value ;
656+ }
657+ return undefined ;
658+ }
659+
660+ function getFirstH2Host ( h2Opts ) {
661+ return (
662+ getFirstValue ( h2Opts ?. host ) ||
663+ getFirstHeaderValue ( h2Opts ?. headers , 'host' , 'Host' )
664+ ) ;
665+ }
666+
667+ function getH2Headers ( h2Opts ) {
668+ const headers = { } ;
669+ if (
670+ h2Opts ?. headers &&
671+ typeof h2Opts . headers === 'object' &&
672+ ! Array . isArray ( h2Opts . headers )
673+ ) {
674+ for ( const [ key , value ] of Object . entries ( h2Opts . headers ) ) {
675+ if ( / ^ h o s t $ / i. test ( key ) ) continue ;
676+ const headerValue = getFirstValue ( value ) ;
677+ if ( headerValue != null ) {
678+ headers [ key ] = headerValue ;
679+ }
680+ }
681+ }
682+ const host = getFirstH2Host ( h2Opts ) ;
683+ if ( host ) {
684+ headers . Host = host ;
685+ }
686+ return Object . keys ( headers ) . length > 0 ? headers : undefined ;
687+ }
688+
689+ function getFirstValue ( value ) {
690+ if ( Array . isArray ( value ) ) return value [ 0 ] ;
691+ if ( value != null ) return value ;
692+ return undefined ;
693+ }
694+
695+ function getFingerprintSha256 ( proxy ) {
696+ const fingerprint = proxy ?. [ 'tls-fingerprint' ] ;
697+ if ( typeof fingerprint !== 'string' ) return undefined ;
698+ const trimmedFingerprint = fingerprint . trim ( ) ;
699+ return trimmedFingerprint . length > 0 ? trimmedFingerprint : undefined ;
700+ }
701+
702+ function supportsRootFingerprintSha256 ( original , proxy ) {
703+ return (
704+ [ 'anytls' , 'https' , 'hysteria2' , 'trojan' , 'tuic' ] . includes (
705+ original . type ,
706+ ) ||
707+ ( original . type === 'http' && proxy . type === 'https' )
708+ ) ;
709+ }
710+
711+ function addTransportFingerprintSha256 ( transport , fingerprintSha256 ) {
712+ if ( ! transport ) return ;
713+
714+ for ( const key of [ 'http2' , 'tls' , 'wss' ] ) {
715+ if ( transport [ key ] ) {
716+ transport [ key ] . fingerprint_sha256 = fingerprintSha256 ;
717+ }
718+ }
719+ }
0 commit comments