Problem/Motivation

Certain pages return 404 when making a HEAD request, but they return 200 if GET is used; in this case the broken links report would be inaccurate and report correct pages as incorrect. For many sites with many links it would require a lot of work to change each individual link to GET.

Steps to reproduce

Create a page with a link to page that behaves like described in 'Motivation' (e.g. https://www.bible.com/bible/3290/MAT.1.MTHB). Then run checking the links and see the report.

Proposed resolution

Create a GET fallback for HEAD requests. If a HEAD request fails, a GET request to the target link would be called.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Livecan created an issue. See original summary.

eiriksm’s picture

Great suggestion.

This would have to be opt in, so make it configurable at least

Are you able to suggest something in a merge request or s patch?

Livecan’s picture

Here's the suggested change to get the idea: https://git.drupalcode.org/issue/linkchecker-3334240/-/commit/294a184e04....
We could have it configurable - have a checkbox in the config form? And maybe use default setting as fallback enabled for new installation but for existing installation leave the current behavior?
I could include the changes to the form and create the config tomorrow and put it here.

joelpittet’s picture

Version: 8.x-1.0-beta6 » 8.x-1.x-dev

Livecan’s picture

Sorry, had some problems with figuring out submitting my changes to the project. I hope now it should be really ready to merge.

eiriksm’s picture

Status: Active » Needs review

bwaindwain made their first commit to this issue’s fork.

bwaindwain’s picture

Version: 8.x-1.x-dev » 2.0.x-dev

Switched to 2.0.x branch and added a new branch and merge request for this feature.

anybody’s picture

Version: 2.0.x-dev » 2.1.x-dev

I agree this still makes sense as option, as several hosts refuse HEAD calls, for example:

  • Google
  • Amazon
  • Facebook
  • Pexels
  • ...

Which leads to failing / false-positive broken link checkes especially in the imprint.

anybody’s picture

Assigned: Livecan » Unassigned

@bwaindwain could you change the target branch to 2.1.x please?

Implementation looks nice, we should get this over the finish line! :)

anybody’s picture

Status: Needs review » Needs work

I also left a comment in code.

I tried this and for many links it works and links are marked correct now. But some still are marked failed, for example:

Yes, EXACTLY this URLs! Give it a try. Any idea for the reasons, if it's already GET, not HEAD?

konot changed the visibility of the branch 3334240-use-get-method to hidden.

konot changed the visibility of the branch 3334240-use-get-method to hidden.

xfxfca’s picture

StatusFileSize
new1.42 KB

try 'GET' if 'HEAD' fails

joseph.olstad made their first commit to this issue’s fork.

joseph.olstad’s picture

Assigned: Unassigned » joseph.olstad
Status: Needs work » Active
joseph.olstad’s picture

@xfxfca please back off your patch and test the latest MR here:

https://git.drupalcode.org/project/linkchecker/-/merge_requests/120.diff

need to confirm if this works.

xfxfca’s picture

StatusFileSize
new1.36 KB
xfxfca’s picture

updated patch

joseph.olstad’s picture

Assigned: joseph.olstad » Unassigned
Status: Active » Needs review

Please review MR 120

joseph.olstad’s picture

The small patch is from MR120.

The larger patch is from the double issue MR121.

joelpittet changed the visibility of the branch 2.0.x to hidden.

joelpittet changed the visibility of the branch 3334240-use-get-method-2 to hidden.

joelpittet’s picture

There are quite a few proposed solutions here, and it’s not clear which one is meant to move forward. I hid two that looked like accidental MRs (hopefully correctly!).

The issue summary is excellent though! Short, clear, and the title is specific. That really helps. Let’s make it easy for maintainers to commit something.

@joseph.olstad instead of me trying to guess, maybe you could hide any MRs/branches we no longer need? If you’re combining approaches, a patch might be a better fit anyway, since it’s composer-patchable and avoids branch clutter.

I think most of this confusion came from creating a 2.0.x target branch on a fork that didn’t already have it — GitLab makes you create it before you can select it as the MR target, which unintentionally makes it look like it’s part of the issue work. (I still haven’t figured out how to avoid that either.)

joseph.olstad changed the visibility of the branch 3334240-get-method-fallback-with-3213210-host-port-substitution to hidden.

joseph.olstad’s picture

I will argue that MR 56 is not needed since linkchecker already offers a domain blacklist to handle the option.

MR 120 has been extensively tested and also passes automated testing.

joseph.olstad changed the visibility of the branch 3334240-use-get-method-2.0.x to hidden.

joelpittet’s picture

Let’s make this simple, which MR only does what the issue summary and title asks of it and doesn’t creep on scope?

joseph.olstad’s picture

Answer: MR 120 and it is the only currently visible MR

joelpittet’s picture

Thanks @joseph.olstad I will reviewMR 121 later, first glance the test could use something a bit more explicit, but I will look closer as there is probably context lines that make it clearer already in place.

joelpittet’s picture

The code looks great I should add, I am mostly concerned about the test

joseph.olstad’s picture

MR 120

This one

anybody’s picture

@joelpittet looks like you accidentally checked MR121 instead of MR120 as @joseph.olstad pointed out in #44?

@joseph.olstad the MR looks good and clear to me, I just left two notes, maybe you'd like to have a look.

I agree this is very helpful and should get released soon.

codebymikey made their first commit to this issue’s fork.

codebymikey’s picture

On further reflection, I think it makes sense to have a configuration and have it disabled by default, so existing sites don't have a bunch of extra requests being made that weren't previously being made.

Also improved the fidelity of the tests.

codebymikey’s picture

edit: Ignore the wrongly named diff file.

It's the latest static version of the current MR.

joseph.olstad’s picture

has tests, passes tests, let's merge that

joseph.olstad’s picture

Status: Needs review » Reviewed & tested by the community

MR 120 needs to be merged asap. To eliminate false 404s,many people need this and most of them do not even realize what's going on.

joseph.olstad’s picture

Priority: Normal » Major

Let's just merge this in today and cut a release.

joseph.olstad’s picture

bwaindwain’s picture

FYI: The array type breaks PHP 8.2 compatibility

const array HEAD_FALLBACK_STATUS_CODES = [
  400, 401, 403, 404, 405, 406,
];

ParseError: syntax error, unexpected identifier "HEAD_FALLBACK_STATUS_CODES", expecting "=" in Composer\Autoload\{closure}() (line 31 of /web/modules/contrib/linkchecker/src/LinkCheckerService.php).

joelpittet’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

I was about to merge this, but I felt like the other fix that I just made took priority so this one now needs a re-roll if somebody could take care of that, I will be happy to commit it as well

joseph.olstad’s picture

I attempted to resolve the conflicts and pushed it up, I have no idea if I resolved the conflicts correctly or not. Lets see what the tests say.

joseph.olstad’s picture

MR 21 is hosed since the conflicts. Will work on it later.

joseph.olstad’s picture

Meanwhile, MR 20 seems ok and is passing tests. MR21 is a combined solution patch with another issue (we are using an older version of it). Needs work.

joelpittet’s picture

@joseph.olstad sorry not totally understanding the need for this feature in MR 121 to me it feels outside the scope of this module and/or this issue and shouldn't be worked on here.

Can you move that to a different issue please? Or didn't you already in #3213210: provide optional host and port substitution to check links behind a reverse proxy and/or docker environment in comment #52? It seems to be just adding noise here and making it harder to get committed.

joseph.olstad’s picture

@joelpittet

it's because we require the solutions for this issue 3334240 and also 3213210 , we cannot apply both patches since there's conflicts. That's why we have MR 21

and there's conflicts with the recent changes.

I don't have time now to redo these patches. Significant time went in to getting them working the first time.

Would be great to move forward with MR #20 so that we have less bs to deal with.

Every time we upgrade linkchecker, it takes us days and days and days to do manual regression testing with all of the combined fixes. Both issues are serious for us. We won't be able to test this until there's solutions either merged or patchable for both of these issues.

3334240 is very important since many false broken links show up unless this solution is in place

3213210 is very important to us since we use docker with varnish in front and a reverse proxy and linkchecker simply will not function unless we run with a functional patch for this (ugh, rerolls are currently a mess).

For us, we're currently unable to upgrade until these two issues are either patchable or fixed.

Perhaps someone else will sort this out for us both ways before I have to.

joseph.olstad’s picture

Status: Needs work » Needs review

MR 20 needs review.

joelpittet’s picture

Throw a combined patch up if you’re needing both, exclude the tests to reduce patch conflicts. It’s easier to understand and you can be explicit in the filename.

joseph.olstad’s picture

I'm hoping MR 120 goes in and we'll have one less moving target to deal with.

joelpittet’s picture

I should clarify but you mean MR 120, not MR 20 from #3259507: Fragments of internal links are not checked?

joseph.olstad’s picture

Yes I actually meant MR 120 from this issue. lol, I think my brain did some strange concatenation with the ! exclamation keyword. some cache clear needed in my brain.

joelpittet’s picture

Yeah I figured, I am not sure why the explanation marks are used but they confuse me too

grevil made their first commit to this issue’s fork.

grevil’s picture

Issue tags: -Needs reroll

Rebased for current 2.1.x!

joseph.olstad’s picture

This should go in asap because it's ready and it's on the critical path.

Once this is in, I'll work on my other rerolls since there's conflicts touching the same lines of code elsewhere in my other issues.

anybody’s picture

Status: Needs review » Reviewed & tested by the community

Thank you all! In my eyes MR!120 is ready for RTBC. Any objections?

joseph.olstad’s picture

@joelpittet

I had another look, this is clean, has tests, still ready to go.

Please merge.

I need this one in before working on other merge requests.