Skip to content

GET fallback for link checker - #1164

Merged
fbacall merged 5 commits into
masterfrom
link-check-get
Nov 6, 2025
Merged

GET fallback for link checker#1164
fbacall merged 5 commits into
masterfrom
link-check-get

Conversation

@fbacall

@fbacall fbacall commented Oct 24, 2025

Copy link
Copy Markdown
Member

Summary of changes

  • Try a GET request if a link returns a 400 or 405 code when trying a HEAD
  • Move some link checker logic out into a class

Motivation and context

Certain services will not respond to HEAD requests

Checklist

  • I have read and followed the CONTRIBUTING guide.
  • I confirm that I have the authority necessary to make this contribution on behalf of its copyright owner and agree
    to license it to the TeSS codebase under the
    BSD license.

@fbacall
fbacall requested a review from Copilot October 24, 2025 19:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 LinkChecker class 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.

Comment thread lib/link_checker.rb
Comment thread lib/link_checker.rb Outdated
Comment thread lib/link_checker.rb
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)

Copilot AI Oct 24, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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'.

Suggested change
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

Copilot uses AI. Check for mistakes.
@fbacall
fbacall marked this pull request as ready for review October 27, 2025 11:54
@fbacall
fbacall merged commit 7ab91a0 into master Nov 6, 2025
11 checks passed
@fbacall
fbacall deleted the link-check-get branch November 6, 2025 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants