GET fallback for link checker - #1164
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the link checker to handle services that don't respond to HEAD requests by implementing a GET request fallback. The implementation has been refactored from procedural code in a rake task into a dedicated LinkChecker class.
Key Changes:
- Added GET request fallback when HEAD requests return 400 or 405 status codes
- Refactored link checking logic into a new
LinkCheckerclass with caching support - Added comprehensive test coverage for the new link checker functionality
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| lib/link_checker.rb | New class implementing link checking with HEAD/GET fallback and URL caching |
| lib/tasks/check_urls.rake | Simplified to delegate to LinkChecker class instead of containing inline logic |
| test/unit/link_checker_test.rb | New test suite covering various link checking scenarios including GET fallback and redirect handling |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| end | ||
| @prev_host = host | ||
| code = HTTParty.head(url, verify: false).code | ||
| code = get_code(url) if code == 400 || code == 405 # Try a GET if HEAD not allowed (or generic 400 error) |
There was a problem hiding this comment.
[nitpick] The comment mentions trying GET for '400 or generic 400 error' which is redundant. Consider revising to clarify why 400 is included alongside 405. A clearer comment would be: 'Try a GET if HEAD returns Method Not Allowed (405) or Bad Request (400), as some servers reject HEAD requests'.
| code = get_code(url) if code == 400 || code == 405 # Try a GET if HEAD not allowed (or generic 400 error) | |
| code = get_code(url) if code == 400 || code == 405 # Try a GET if HEAD returns Method Not Allowed (405) or Bad Request (400), as some servers reject HEAD requests |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Summary of changes
Motivation and context
Certain services will not respond to HEAD requests
Checklist
to license it to the TeSS codebase under the
BSD license.