Skip to content

Support hysteria2 port ranges in URI import#889

Open
hellcatjack wants to merge 1 commit intotindy2013:masterfrom
hellcatjack:master
Open

Support hysteria2 port ranges in URI import#889
hellcatjack wants to merge 1 commit intotindy2013:masterfrom
hellcatjack:master

Conversation

@hellcatjack
Copy link
Copy Markdown

Summary

This PR adds support for importing Hysteria 2 standard URIs that use a port range or multi-port spec in the authority section.

Previously, these links were rejected as invalid because the parser only accepted a single numeric port.

Problem

The current Hysteria 2 URI parser only matches a numeric-only port value. As a result, valid port hopping style inputs such as port ranges or comma-separated port specs cannot be imported from standard URIs.

There is also an argument ordering issue in the Clash importer path for Hysteria 2, which can cause fields such as alpn, ca, and cwnd to be assigned incorrectly.

Changes

  • Allow Hysteria 2 standard URI parsing to accept port specs containing ranges and multiple ports
  • Preserve the full port spec in Ports
  • Derive a primary port internally from the first valid entry only when required by the internal proxy model
  • When exporting to Clash, omit port for Hysteria 2 if ports contains a range or multiple ports, and emit only ports
  • Keep existing single-port behavior unchanged
  • Fix the Hysteria 2 argument order in the Clash import path

Result

A URI like:

hysteria2://password@<server>:<port-range>/?sni=<server>#example-node

is now converted to Clash output like:

- {name: example-node, server: <server>, type: hysteria2, ports: <port-range>, password: password, sni: <server>}

A Hysteria 2 URI with a single port still produces:

`hysteria2://password@<server>:<single-port>/?sni=<server>#example-node`

- {name: example-node, server: <server>, port: <single-port>, type: hysteria2, password: password, sni: <server>}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant