4 Star 3 Fork 4

Gitee 极速下载/Tiny-httpd

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/Huangtuzhi/Tinyhttpd
克隆/下载
responsefile.cpp 1.33 KB
一键复制 编辑 原始数据 按行查看 历史
Huangtuzhi 提交于 10年前 . a
#include "responsefile.h"
#include "mime.h"
#include <QFile>
#include <QFileInfo>
bool ResponseFile::s_initialized = false;
int ResponseFile::s_buffer_size = DEFAULT_REQUEST_BUFFER_SIZE;
int ResponseFile::vistor = 0;
void ResponseFile::initialize()
{
s_initialized = true;
s_buffer_size = 1048576;
}
//return the page in server
ResponseFile::ResponseFile(QTcpSocket* socket, int http_status_code, QMap<QString, QString>& header, QString filename):
Response(socket, http_status_code, header),
m_filename(filename)
{
if (!s_initialized)
initialize();
if (m_http_status_code != 200)
{
m_filename = QString("response/%1.html").arg(m_http_status_code);
}
QFileInfo file_info(m_filename);
m_header["Content-Type"] = Mime::instance().getMimeType(file_info.suffix());
m_header["Content-Length"] = QString("%1").arg(file_info.size());
m_header["Last-Modified"] = Common::getTimeStampString(file_info.lastModified().toUTC());
}
void ResponseFile::response()
{
responseHeader();
QFile file(m_filename);
if (!file.open(QFile::ReadOnly))
; //TODO
char* buffer = new char[s_buffer_size];
while (!file.atEnd())
{
int len = file.read(buffer, s_buffer_size);
m_socket->write(buffer, len);
m_socket->flush();
}
delete[] buffer;
incrVistor();
}
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

搜索帮助