Hoper 展示一个 URL 在到达最终目的地之前所经过的每一次跳转(重定向)—— 适用于短链接、电子邮件中的跟踪链接、SSO 流程,或调试重定向规则。
$ hoper http://github.com
Tracing http://github.com
1. → 301 Moved Permanently http://github.com/ 81ms
2. ✔ 200 OK https://github.com/ 50ms
1 redirect → https://github.com/
HEAD(不下载响应体),对于拒绝 HEAD 的服务器自动回退到 GET。HTTP_PROXY / HTTPS_PROXY / NO_PROXY 以及 NO_COLOR。需要 Ruby 3.1 或更高版本。
gem install hoper
在 Windows 上,使用 RubyInstaller 安装 Ruby,然后运行相同的命令。
hoper [options] URL [URL...]
-m, --max-hops N Maximum redirects to follow (default: 20)
-t, --timeout SECONDS Timeout per request (default: 10)
-X, --method METHOD HTTP method: HEAD or GET (default: HEAD)
-A, --user-agent UA User-Agent header to send
-H, --header 'NAME: VALUE' Extra request header (repeatable)
-k, --insecure Do not verify TLS certificates
-j, --json Output results as JSON
--[no-]color Force/disable colored output
-v, --version Print version and exit
-h, --help Show this help
如果省略了协议方案,则默认使用 https://(hoper example.com)。
hoper --json http://github.com
{
"start_url": "http://github.com/",
"final_url": "https://github.com/",
"final_status": 200,
"redirects": 1,
"hops": [
{ "url": "http://github.com/", "status": 301, "reason": "Moved Permanently", "location": "https://github.com/", "duration_ms": 81 },
{ "url": "https://github.com/", "status": 200, "reason": "OK", "duration_ms": 50 }
]
}
当有多个 URL 时,输出为一个数组。
| 代码 | 含义 |
|---|---|
| 0 | 每个 URL 都解析为无错误(< 400)的最终响应 |
| 1 | 至少有一个 URL 失败(网络错误、循环、跳转次数过多、4xx/5xx) |
| 2 | 用法/选项无效 |
require "hoper"
result = Hoper.trace("https://bit.ly/example", max_hops: 10)
result.hops.each { |hop| puts "#{hop.status} #{hop.url}" }
result.final_url # => "https://example.com/"
result.success? # => true
bundle install
bundle exec rake test
CI 在 Ubuntu、macOS 和 Windows(Ruby 4.0)上运行测试套件,并在 Ubuntu 上运行支持的最旧 Ruby 版本(3.1)。测试使用本地进程内 HTTP 服务器,因此不需要网络访问。
发布通过 GitHub Actions 和 RubyGems Trusted Publishing 自动化:
更新 lib/hoper/version.rb 并在 CHANGELOG.md 中添加一节;合并到 master。
打标签并推送:
git tag v1.2.3 && git push origin v1.2.3
Release 工作流会检查标签是否与版本匹配、运行测试、将 gem 发布到 RubyGems.org,并使用 CHANGELOG 说明创建 GitHub Release。
欢迎在 GitHub 上提交缺陷报告和拉取请求:https://github.com/gabamnml/hoper。本项目旨在成为一个安全、友好的协作空间,贡献者应遵守 Contributor Covenant 行为准则。
该 gem 依据 MIT License 条款作为开源软件提供。