File indexing completed on 2025-02-02 04:36:32

0001 /* Copyright 2013 Robert Schroll
0002  *
0003  * This file is part of Beru and is distributed under the terms of
0004  * the GPL. See the file COPYING for full details.
0005  */
0006 
0007 #include "fileserver.h"
0008 #include <QFile>
0009 #include <../mimetype/mimetype.h>
0010 
0011 void FileServer::serve(const QString &filename, QHttpResponse *response)
0012 {
0013     QFile file(filename);
0014     if (!file.open(QIODevice::ReadOnly)) {
0015         response->writeHead(404);
0016         response->end("File not found");
0017         return;
0018     }
0019 
0020     response->setHeader("Content-Type", guessMimeType(filename));
0021     response->writeHead(200);
0022     response->write(file.readAll());
0023     response->end();
0024 }