Comments (4)
目前不能自动搜索和匹配文件,需要手动根据传入的数据匹配对应的文件,然后调用replyFile接口返回
from jqhttpserver.
from jqhttpserver.
可以参考下这个
void onRequestAccepted(const QPointer< JQHttpServer::Session > &session)
{
if ( session->requestMethod() != "GET" )
{
session->replyText( "unsupport request method", 404 );
return;
}
auto relativeFilePath = session->requestUrlPath();
if ( relativeFilePath.isEmpty() )
{
session->replyText( "path is empty", 404 );
return;
}
if ( relativeFilePath.isEmpty() ||
relativeFilePath.startsWith( "." ) ||
!relativeFilePath.startsWith( "/" ) ||
relativeFilePath.contains( ".." ) ||
relativeFilePath.contains( "\\" ) ||
( relativeFilePath.size() > 1000 ) )
{
session->replyText( "path error", 404 );
return;
}
QFileInfo fileIfno( QString( "%1%2" ).arg( webPath_, relativeFilePath ) );
if ( !fileIfno.exists() )
{
session->replyText( "file not exists", 404 );
return;
}
if ( fileIfno.suffix().toLower() == "html" )
{
QFile file( fileIfno.filePath() );
file.open( QIODevice::ReadOnly );
const auto data = file.readAll();
session->replyBytes( data, "text/html;charset=UTF-8" );
}
else if ( QSet< QString >( { "png", "jpg", "jpeg", "ico", "bmp" } ).contains( fileIfno.suffix().toLower() ) )
{
session->replyImage( fileIfno.filePath() );
}
else
{
session->replyFile( fileIfno.filePath() );
}
}
from jqhttpserver.
from jqhttpserver.
Related Issues (20)
- 用于地图瓦片数据的发布中的优化建议(tms) HOT 3
- 80端口启动失败 HOT 2
- 在onHttpAccepted里面阻塞30 再回复为什么会失败 HOT 2
- /home/queue/Qt5.12.0/5.12.0/gcc_64/include/QtCore/qvariant.h:273: warning: implicitly-declared ‘QVariant::Private& QVariant::Private::operator=(const QVariant::Private&)’ is deprecated [-Wdeprecated-copy] 273 | { other.d = Private(); } | ^ HOT 2
- AbstractManage 中的 QMutex 互斥锁是否必要? HOT 1
- 如何在session中返回一个自定义的错误? HOT 6
- 长连接时后续请求会被忽略 HOT 1
- 静态路由使用不便 HOT 2
- 设置最大处理线程数,这里的最大线程数指的可以处理 一台机器的并发(post多次)请求还是 指的是多台机器的(post一次)并发请求 HOT 2
- Qt6支持 HOT 3
- 会遗漏请求 HOT 12
- 编译过程中 error: no match for ‘operator+=’ (operand types are ‘QString’ and ‘QStringView’) HOT 2
- 传输大文件问题 HOT 4
- 关闭程序,会一直等待HTTP服务器完全停止,服务器不会停止吗? HOT 1
- 如何构建多个server监听不同端口 HOT 1
- 服务端无法退出 HOT 4
- 不停访问服务器会造成系统崩溃 HOT 6
- 对于https server而言,要想在回吐的头中加入token应该要使用什么方法 HOT 2
- 请问使用JQNet::HTTP::post方法向一个https://ip:port/url发送请求时,https证书是在哪里添加的呢 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jqhttpserver.