File resource status shall be managed only for File mode answers
dsauvage opened this issue · comments
Description
As we can see in src/core/aws-server-http_utils.adb:1587
File_Mode : constant Boolean :=
Response.Mode (Answer) in
Response.File .. Response.Stream;
With_Body : constant Boolean := Messages.With_Body (Status_Code);
File_Time : Ada.Calendar.Time;
F_Status : constant Resource_Status :=
Get_Resource_Status (C_Stat, Filename, File_Time);
File : Resources.File_Type;
begin
if F_Status in Up_To_Date .. Not_Found then
if F_Status = Up_To_Date then
-- [RFC 2616 - 10.3.5]
Status_Code := Messages.S304;
else
-- File is not found on disk, returns now with 404
Status_Code := Messages.S404;
end if;
Set_General_Header (Status_Code);
Headers.Send_Header
(Socket => Sock, Headers => H_List, End_Block => True);
return;
File resource status is managed in all cases, even when Response.Mode (Answer) = Response.Message
. This can happen in the following context;
Server A web service creates an answer using AWS.Response.File
Server B web service calls server A web service above using AWS.Client.Get
and send back the response to the client
The patch below fix this issue by managing the file resource status only when the answer File_Mode
is True
, that is when Response.Mode (Answer) in Response.File .. Response.Stream
. However shall we instead manage the file resource status for the File
and File_Once
modes only, keeping Stream
mode out of it ?
File_Mode : constant Boolean :=
Response.Mode (Answer) in
Response.File .. Response.Stream;
With_Body : constant Boolean := Messages.With_Body (Status_Code);
File_Time : Ada.Calendar.Time;
F_Status : constant Resource_Status :=
(case File_Mode is
when False => Changed,
when True => Get_Resource_Status (C_Stat, Filename, File_Time)
);
File : Resources.File_Type;
begin
if File_Mode and then F_Status in Up_To_Date .. Not_Found then
if F_Status = Up_To_Date then
Thanks, this makes sense indeed.