I am trying to work out an efficient way of checking that a URL returns an existing resource/page.
Performing a GET
and checking the response status = 200
works but is inefficient as it requests the whole page/resource.
Using a HEAD
request method and checking the status response of that would seem ideal except that my target site does not support HEAD
requests (just GET
and POST
according to an options request. (It is not my site/sites that are being checked so enabling HEAD
requests is not an option.)
Requesting a known good URL with the HEAD
method results in a 405
error.
By experimenting I have found that if I request non-existing pages I get a return status code of 404
and various other errors also seem to make sense. I would prefer to confirm the existence of the page, though, rather than just assume existence by checking for a non-404 status code.
Can I, therefore, safely assume that if I get a 405
error that the page/resource exists?
This seems to be a question of response status precedence/priority.
Will a 404
error always take precedence over a 405
error or is this server or server configuration dependent?
If the order of precedence is defined, is this in an RFC or something?
(This question addresses a similar situation but for another specific situation)