From 6e8b03eeb9af2abd44f60925b3e9315c90cd2221 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Sat, 24 Dec 2022 15:05:38 +0200 Subject: [PATCH] kdirshare: do not open the file when sending response KHTTP should send error response if opening the file fails Signed-off-by: Ivailo Monev --- kdirshare/kded/kdirshareimpl.cpp | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/kdirshare/kded/kdirshareimpl.cpp b/kdirshare/kded/kdirshareimpl.cpp index f6689eef..c1c9eec6 100644 --- a/kdirshare/kded/kdirshareimpl.cpp +++ b/kdirshare/kded/kdirshareimpl.cpp @@ -202,18 +202,10 @@ void KDirShareImpl::respond(const QByteArray &url, QByteArray *outdata, outheaders->insert("Content-Type", "text/html; charset=UTF-8"); outdata->append(contentForDirectory(pathinfo.filePath(), m_directory)); } else if (pathinfo.isFile()) { - QFile pathfile(pathinfo.filePath()); - if (!pathfile.open(QFile::ReadOnly)) { - kWarning() << "Could not open" << pathinfo.filePath() << pathfile.errorString(); - outdata->append(s_data500); - *outhttpstatus = 500; - outheaders->insert("Content-Type", "text/html; charset=UTF-8"); - } else { - const QString filemime = getFileMIME(pathinfo.filePath()); - *outhttpstatus = 200; - outheaders->insert("Content-Type", QString::fromLatin1("%1; charset=UTF-8").arg(filemime).toAscii()); - outfilepath->append(pathinfo.filePath()); - }; + const QString filemime = getFileMIME(pathinfo.filePath()); + *outhttpstatus = 200; + outheaders->insert("Content-Type", QString::fromLatin1("%1; charset=UTF-8").arg(filemime).toAscii()); + outfilepath->append(pathinfo.filePath()); } else { outdata->append(s_data404); *outhttpstatus = 404;