Proxy URL Parser is a lightweight Dart package that parses proxy URLs into structured configurations. It supports multiple proxy protocols and makes it easy to integrate proxy functionality into your Dart and Flutter applications.
- 🧩 Parse multiple proxy protocol URLs into structured configurations
- 🔀 Support for VMess, VLESS, Shadowsocks, and Trojan protocols
- 🧰 Easy integration with proxy_core implementations
- 🛠️ Inject parsed configurations into existing config structures
- ✅ VMess (
vmess://) - ✅ VLESS (
vless://) - ✅ Shadowsocks (
ss://) - ✅ Trojan (
trojan://) - 🔜 WireGuard, SOCKS, Hysteria2 (Coming soon)
| Function | Description |
|---|---|
parse(String proxyUrl) |
Parse a proxy URL into a specific configuration type |
injectToConfig(Map baseConfig, Map outbound) |
Inject parsed outbound configuration into an existing base configuration |
toXrayJson(bool allowInsecure) |
Convert a parsed configuration to Xray JSON format |
The package includes comprehensive test coverage for all supported protocols. Tests are organized into two main categories:
Located in test/proxy_url_parser_test.dart, these tests verify individual protocol parsing functionality with predefined test vectors.
Located in test/proxy_url_parser_vector_test.dart, these tests read proxy URLs from a vector bucket file (test/vector_bucket) and perform comprehensive validation of all fields for each protocol type.
# Run all tests
dart test
# Run specific test file
dart test test/proxy_url_parser_test.dart
dart test test/proxy_url_parser_vector_test.dart
# Run tests with coverage
dart test --coverage=coverageTo add new test vectors:
- Add your proxy URLs to
test/vector_bucket - Each URL should be on a new line
- Lines starting with
#are treated as comments - Empty lines are ignored
Example vector bucket format:
# VLESS URLs
vless://uuid@host:port?type=tcp&security=none#remark
vless://uuid@host:port?type=ws&path=/path&security=tls#remark
# VMess URLs
vmess://base64-encoded-json
# Shadowsocks URLs
ss://method:password@host:port#remark
# Trojan URLs
trojan://password@host:port?security=tls#remark
To use this package, add proxy_url_parser as a dependency in your pubspec.yaml file:
dependencies:
proxy_url_parser: ^latestimport 'package:proxy_url_parser/proxy_url_parser.dart';
void main() {
// Parse a VMess URL
try {
final vmessConfig = ProxyUrlParser.parse("vmess://your-vmess-url-here");
print("Parsed VMess config: ${vmessConfig.server}:${vmessConfig.port}");
// Inject into a base configuration
final baseConfig = <String, dynamic>{
"log": {"loglevel": "info"},
"dns": {},
// Other base config elements
};
xrayJson = vmessConfig.toXrayJson();
final fullConfig = ProxyUrlParser.injectToConfig(
baseConfig,
xrayJson,
);
// Use the full configuration with your proxy core
} catch (e) {
if (e is UnsupportedProxyTypeException) {
print("Unsupported proxy protocol");
} else if (e is InvalidUrlFormatException) {
print("Invalid URL format: ${e.message}");
} else {
print("Error parsing URL: $e");
}
}
}The package provides custom exceptions for better error handling:
DecodingException- Thrown when decoding fails (e.g., base64 or JSON)UnsupportedProxyTypeException- Thrown when an unsupported protocol is encounteredInvalidUrlFormatException- Thrown when the URL format is invalid
The package includes a logging utility (ProxyUrlParserLogger) that can be enabled for debugging:
// Enable debug logging
ProxyUrlParserLogger.enableDebugLogs = true;For more detailed examples, check the example directory in the repository.
This project is licensed under the MIT License.
Contributions are welcome! Please feel free to submit a Pull Request.