4 Star 3 Fork 4

Gitee 极速下载/Tiny-httpd

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/Huangtuzhi/Tinyhttpd
克隆/下载
responsedirectory.cpp 1.95 KB
一键复制 编辑 原始数据 按行查看 历史
Huangtuzhi 提交于 10年前 . new
#include "responsedirectory.h"
#include "mime.h"
#include <QDir>
#include <QFileInfoList>
#include <QTextStream>
#include <QByteArray>
#include <QBuffer>
//Display the first page showing the files
ResponseDirectory::ResponseDirectory(QTcpSocket* socket, QMap<QString, QString>& header, QString dir_name, QString url_path):
Response(socket, 200, header),
m_dir_name(dir_name),
m_url_path(url_path)
{
}
void ResponseDirectory::response()
{
QDir dir(m_dir_name);
if (!dir.isReadable())
return; //TODO error
QByteArray buffer;
QBuffer qbuffer(&buffer);
qbuffer.open(QIODevice::WriteOnly);
QTextStream sbuffer(&qbuffer);
sbuffer << "<html><head><title>"
<< m_url_path
<< "</title></head><body><h1>"
<< m_url_path
<< "</h1><hr/><table><tr>"
"<td>Filename</td>"
"<td>Size</td>"
"</tr>";
dir.setFilter(QDir::Dirs|QDir::Files);
dir.setSorting(QDir::DirsFirst|QDir::Name);
QFileInfoList file_list = dir.entryInfoList();
for (QFileInfoList::Iterator i = file_list.begin(); i != file_list.end(); ++i)
{
if (i->isDir())
{
sbuffer << QString("<tr><td><a hred='%1'>%2/</a></td><td>-</td></tr>")
.arg(m_url_path + i->fileName())
.arg(i->fileName());
}
else
{
sbuffer << QString("<tr><td><a href='%1'>%2</a></td><td>%3</td></tr>")
.arg(m_url_path + i->fileName())
.arg(i->fileName())
.arg(i->size());
}
}
sbuffer << "</table><hr/>"
<< APPLICATION_IDENTIFIER
<< "</body></html>";
sbuffer.flush();
m_header["Content-Type"] = Mime::instance().getMimeType("html");
m_header["content-Length"] = QString("%1").arg(buffer.length());
responseHeader();
m_socket->write(buffer);
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C/C++
1
https://gitee.com/mirrors/Tiny-httpd.git
git@gitee.com:mirrors/Tiny-httpd.git
mirrors
Tiny-httpd
Tiny-httpd
master

搜索帮助