#1 2024-01-28 13:54:59

wfbhappy
Member
Registered: 2022-02-16
Posts: 4

unit mormot.net.http.pas Methods: the function THttpRequestContext bug

Output a file as a file stream
2.Mormot2 BUG Fix Please fix this unit mormot.net.http.pas
Methods: the function THttpRequestContext. ContentFromFile Bug  reasons, the file is empty when the output is false, can not find a file, is wrong.
Amended as follows :
ContentLength := FileSize(FileName):// Add this judgment to this sentence:
if ContentLength=0 then
begin
result := true;

Last edited by wfbhappy (2024-01-28 13:59:55)

Offline

#2 2024-01-29 07:55:11

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: unit mormot.net.http.pas Methods: the function THttpRequestContext bug

Are you sure?

With the latest source code version,
if ContentLength=0 then the "ContentLength < 1 shl 20" branch is taken, and FileReadAll() returns true with Content=''.
As expected.

Or did I miss something?

Offline

#3 2024-01-30 04:45:50

wfbhappy
Member
Registered: 2022-02-16
Posts: 4

Re: unit mormot.net.http.pas Methods: the function THttpRequestContext bug

//-- This works fine
ContentLength := FileSize(FileName);
  if ContentLength=0 then
  begin
    result := true;
    exit;
  end;
  result := ContentLength <> 0;
  if result and
     (rfWantRange in ResponseFlags) then
    if not ValidateRange then
      result := false; // invalid offset
  if not result then
    // there is no such file available, or range clearly wrong
    exit;
  include(ResponseFlags, rfAcceptRange);

Offline

Board footer

Powered by FluxBB