unshorten 0.1.0
unshorten: ^0.1.0 copied to clipboard
Unshorten URLs
unshorten #
一个用于展开短链接的 Dart/Flutter 包,支持手动处理 HTTP 重定向,智能识别并停止跟随非 HTTP 协议的重定向。
功能特性 #
- 自动跟随重定向链,展开短链接到最终 URL
- 智能识别非 HTTP(S) 协议(如
app://,intent:,shopee://)并停止跟随 - 优先使用 HEAD 请求减少流量,失败时自动回退到 GET
- 支持追踪重定向过程和自定义超时时间
安装 #
dependencies:
unshorten: ^0.1.0
flutter pub get
使用方法 #
基本用法 #
import 'package:unshorten/unshorten.dart';
void main() async {
final unshorten = Unshorten();
final result = await unshorten.expand('https://short.url/abc123');
if (result.success) {
print('展开后的 URL: ${result.expandedUrl}');
}
}
自定义超时和追踪 #
final result = await unshorten.expand(
'https://short.url/abc123',
timeoutMs: 30000,
onStep: (step) {
print('[${step.index}] ${step.url}');
},
);
限制 #
- 最多跟随 10 次重定向
- 只处理 HTTP/HTTPS 协议的重定向
许可证 #
BSD 3-Clause License - 详见 LICENSE 文件。