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:
parent
624bf47c8d
commit
c2013ff47f
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2021, Tomasz Sowa
|
||||
* Copyright (c) 2008-2022, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -53,28 +53,24 @@ Download::Download()
|
|||
|
||||
void Download::MakeGet()
|
||||
{
|
||||
// !! moze wywalic to no_item i wszedzie w takich miejscach dac poprostu permission_denied?
|
||||
if( !cur->request->is_item )
|
||||
{
|
||||
log << log1 << "Content: download function requires an item" << logend;
|
||||
cur->request->status = WINIX_ERR_NO_ITEM;
|
||||
log << log1 << "Download: download function requires an item" << logend;
|
||||
cur->request->http_status = Header::status_403_forbidden;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if( !system->HasReadAccess(cur->request->item) ||
|
||||
cur->request->item.item_content.file_type == WINIX_ITEM_FILETYPE_NONE ||
|
||||
cur->request->item.item_content.file_path.empty() )
|
||||
{
|
||||
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
|
||||
cur->request->http_status = Header::status_403_forbidden;
|
||||
return;
|
||||
}
|
||||
|
||||
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"));
|
||||
|
||||
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);
|
||||
bool ok = true;
|
||||
|
||||
if( config->send_file_mode == 0 || config->send_file_mode == 1 )
|
||||
{
|
||||
|
@ -82,16 +78,20 @@ void Download::MakeGet()
|
|||
|
||||
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;
|
||||
// may it would be good to return a html page with an error?
|
||||
cur->request->send_bin_stream = true;
|
||||
}
|
||||
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->send_bin_stream = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -102,6 +102,15 @@ void Download::MakeGet()
|
|||
else
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue