0

I wanted to do an existence check before I actually GET an item, and I was planning to use a HEAD request. But my server is having problems with HEAD requests.

It returns an error 403 for new items. I have to make a GET request before making a HEAD request for new items, or my HEAD request consistently returns a 403.

I cannot change anything about my server. What alternatives do I have? I really don't want to download the items to do an existence check (the items are images).

Daniel
  • 2,355
  • 9
  • 23
  • 30
user9910093
  • 119
  • 1
  • 12
  • Possible duplicate of [HEAD request receives "403 forbidden" while GET "200 ok"?](https://stackoverflow.com/questions/3454286/head-request-receives-403-forbidden-while-get-200-ok) – Capricorn Jun 26 '18 at 21:25
  • 1
    *"I wanted to do an existence check before I actually GET an item..."* If you are going to get the item, anyway, as implied by *"before,"* then why does it matter? – Michael - sqlbot Jun 26 '18 at 23:24
  • 1
    If `HEAD` does not work reliably for you, try using `GET` with a `Range` header to request only the 1st byte of the file. If the response code is 200, then ranges are not supported on that file, and you get the whole file (in which case, just close the connection as soon as you detect the response code). If the response code is 206, the range was accepted and you get just the 1st byte sent to you. – Remy Lebeau Jun 26 '18 at 23:46
  • My bad Micheal, that was a typo. I do not intend to do a GET request. I will try Remy's solution. – user9910093 Jun 27 '18 at 18:42

1 Answers1

0

HTTP ranges could be an option, for example, using curl to get the first 200 bytes:

curl -r 0-199 http://example.com
nbari
  • 25,603
  • 10
  • 76
  • 131