Response to a HEAD is to be the exact same as the response to a GET, but without the body.
(
https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.3) - so it should be 200 or 304 if the url asked for exists, 404 if not (or redirection codes or whatever)
This is definitely a flaw.
I have tried reading the returned headers, but they do not contain any indication of the status code.
It returns all the headers (mostly status of the connection - not the contens) Response 0 and raises an exception "unexcpected statuscode 404", instead of actually returning the statuscode.
Problem is, that the line Client.Get(url, ImgNavn); actually creates the image even when the image does not exist online, and the request actually fails.
And the odd thing is, that here TFPHttpClient actually returns the correct response code.
For now I have skipped checking, and simply delete the image again, if an image was not downloaded. This is not optimal.
procedure TFetchForm.CheckImg(aPath,aCard,aImg:string);
var
logStr, imgNavn, imgF, url : string;
Client : TFPHttpClient;
begin
imgF := aCard+aImg;
ImgNavn := aPath + imgF;
if FileExists(ImgNavn) and (TextfileSize(ImgNavn) > 0) then logStr := imgF + ' exists'
else begin // and this where img shold be downloaded ...
url := url1 + aCard + url2 + imgF;
Client := TFPHttpClient.Create(Self);
try
Client.Get(url, ImgNavn);
logStr := imgF + ' created from download';
except
on E : Exception do begin
if Client.ResponseStatusCode = 404 then
logStr := imgF + ' not found on server'
else logStr := 'Error reading ' + url;// + ' ' + E.Message;
DeleteFile(ImgNavn);
end;
end;
Client.Free;
end;
MemoLog.Lines.Add(logStr);
end;