do not use the ezc engine when sending a static file

while here:
- in send_file_mode=0 return a 404 if a static file was not correctly read
This commit is contained in:
Tomasz Sowa 2022-11-14 00:54:50 +01:00
parent 624bf47c8d
commit c2013ff47f
1 changed files with 23 additions and 14 deletions

View File

@ -5,7 +5,7 @@
*/ */
/* /*
* Copyright (c) 2008-2021, Tomasz Sowa * Copyright (c) 2008-2022, Tomasz Sowa
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -53,28 +53,24 @@ Download::Download()
void Download::MakeGet() void Download::MakeGet()
{ {
// !! moze wywalic to no_item i wszedzie w takich miejscach dac poprostu permission_denied?
if( !cur->request->is_item ) if( !cur->request->is_item )
{ {
log << log1 << "Content: download function requires an item" << logend; log << log1 << "Download: download function requires an item" << logend;
cur->request->status = WINIX_ERR_NO_ITEM; cur->request->http_status = Header::status_403_forbidden;
return; return;
} }
if( !system->HasReadAccess(cur->request->item) || if( !system->HasReadAccess(cur->request->item) ||
cur->request->item.item_content.file_type == WINIX_ITEM_FILETYPE_NONE || cur->request->item.item_content.file_type == WINIX_ITEM_FILETYPE_NONE ||
cur->request->item.item_content.file_path.empty() ) cur->request->item.item_content.file_path.empty() )
{ {
cur->request->status = WINIX_ERR_PERMISSION_DENIED; cur->request->http_status = Header::status_403_forbidden;
return; return;
} }
cur->request->send_as_attachment = cur->request->IsParam(L"attachment"); cur->request->send_as_attachment = cur->request->IsParam(L"attachment");
bool is_thumb = (cur->request->item.item_content.file_has_thumb && cur->request->IsParam(L"thumb")); bool is_thumb = (cur->request->item.item_content.file_has_thumb && cur->request->IsParam(L"thumb"));
bool ok = true;
if( !cur->request->item.item_content.file_mime_type.empty() )
cur->request->out_headers.add(Header::content_type, cur->request->item.item_content.file_mime_type);
if( config->send_file_mode == 0 || config->send_file_mode == 1 ) if( config->send_file_mode == 0 || config->send_file_mode == 1 )
{ {
@ -82,16 +78,20 @@ void Download::MakeGet()
if( config->send_file_mode == 0 ) if( config->send_file_mode == 0 )
{ {
log << log3 << "Download: reading content of file: " << cur->request->x_sendfile << logend; log << log3 << "Download: reading the content of a file: " << cur->request->x_sendfile << logend;
if( !GetBinaryFile(cur->request->x_sendfile, cur->request->out_bin_stream) ) if( GetBinaryFile(cur->request->x_sendfile, cur->request->out_bin_stream) )
{ {
log << log1 << "Download: I cannot read the content of the file: " << cur->request->x_sendfile << logend; cur->request->send_bin_stream = true;
// may it would be good to return a html page with an error? }
else
{
ok = false;
cur->request->http_status = Header::status_404_not_found;
log << log2 << "Download: I cannot read the content of a file: " << cur->request->x_sendfile << logend;
} }
cur->request->x_sendfile.clear(); cur->request->x_sendfile.clear();
cur->request->send_bin_stream = true;
} }
} }
else else
@ -102,6 +102,15 @@ void Download::MakeGet()
else else
{ {
log << log1 << "Download: send_file_mode in the config should be either 0, 1 or 2" << logend; log << log1 << "Download: send_file_mode in the config should be either 0, 1 or 2" << logend;
cur->request->http_status = Header::status_403_forbidden;
}
if( ok )
{
cur->request->use_ezc_engine = false;
if( !cur->request->item.item_content.file_mime_type.empty() )
cur->request->out_headers.add(Header::content_type, cur->request->item.item_content.file_mime_type);
} }
} }