Hoper は、URL が最終的な宛先に到達するまでに経由するすべてのホップ(リダイレクト)を表示します — 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 を使用し(ボディのダウンロードなし)、それを拒否するサーバーには自動的に 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 | 少なくとも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 の条件に基づきオープンソースとして利用可能です。