vinipsmaker / tufao Goto Github PK
View Code? Open in Web Editor NEWAn asynchronous web framework for C++ built on top of Qt
Home Page: http://vinipsmaker.github.io/tufao/
License: GNU Lesser General Public License v2.1
An asynchronous web framework for C++ built on top of Qt
Home Page: http://vinipsmaker.github.io/tufao/
License: GNU Lesser General Public License v2.1
I use tufao for playing video and audio from libtorrent. So, when I make frequently requests, like frequently switching audio files, tufao starts hanging. I added additional logs in sources and here what have I got:
virtual void Tufao::TcpServerWrapper::incomingConnection(qintptr)
void Tufao::HttpServer::onNewConnection(qintptr)
virtual bool Tufao::HttpConnectionHandler::incomingConnection(qintptr)
virtual void Tufao::TcpServerWrapper::incomingConnection(qintptr)
void Tufao::HttpServer::onNewConnection(qintptr)
virtual bool Tufao::HttpConnectionHandler::incomingConnection(qintptr)
As You see, starting from Tufao::TcpServerWrapper::incomingConnection(qintptr) we have recirculation. In 10 seconds I've got more than 10 000 of calls of these methods.
So, can it be fixed and in what may be problem? In tufao or in Qt?
Hello,
I've created a simple project with 2 plugins and this routes.json :
{
"version": 1,
"plugins": [
{
"name": "SimplePlugin",
"path": "plugins/libSimplePlugin.so"
},
{
"name": "SimplePlugin2",
"path": "plugins/libSimplePlugin2.so"
}
],
"requests": [
{
"method": "GET",
"path": "^/$",
"plugin": "SimplePlugin"
},
{
"method": "PUT",
"path": "^/$",
"plugin": "SimplePlugin2"
}
]
}
The handler of SimplePlugin is called using PUT verbs, not the one of SimplePlugin2.
I'm developping on ArchLinux with the lastest release from AUR.
Thx.
These methods are declared but no implementation exists in httpfileserver.cpp
Hi. I'm moving from Qt 4.8.4 to Qt 5.1 on linux 32 bit (MinGW). Building libtufao.so is working fine, but while compiling qt project I get errors:
expected type-specifier in file abstracthttpserverrequesthandler.h line 65 and 86
Any idea? I have added CONFIG += TUFAO1
Hi, could you please submit a tufao app for the web framework benchmark here:
http://www.techempower.com/benchmarks/#section=intro
so we can see how tufao perform compared to other web frameworks,
thanks
Hi,
First of all, thanks for the awesome library.
Tried the HelloWorld example on windows 8.1 64 bit, but get not any response.
When starting the test, the port is opened (checked with netstat), the browser connects and waiting until the test program is stopped.
Tested with Qt5 3.0/3.1 and mingw482_32 with tufao 1.x current master and tag-1.2.3.
Tests on linux (openSuse 13.1 and debian wheezy) worked as expected.
Any Idea?
Regards
Currently the Websocket class does not provide a means to ignore any SSL errors.
This is usually only a problem when using a QSslSocket as a client with a server that uses a self-signed certificate (need to ignore QSslError::SelfSignedCertificate). Additionally on some builds of QT 4.x on windows, QT may report QSslError::NoError and forces the user to ignore it in order to continue (bug in QT).
I suggest a new method WebSocket::setExpectedSslErrors(QList<QSslError>&)
which would store the list in a member variable. In case all the error codes of SSL errors QT reports in WebSocket::onSslErrors
are in the expected list, call qobject_cast<QSslSocket*>(sender())->ignoreSslErrors(m_ignoreList)
, otherwise do what it does now.
To clarify, it is possible to use the current Websocket class with a self-signed certificate as a server, but not as a client.
Hello,
Is there a solution to access to the members of a plugin from its request handler (the lambda function) in order to keep a state like the number of processed requests ?
Thanks in advance.
Hi everyone,
I have many handlers inherit Tufao::AbstractHttpServerRequestHandler. In each handler, I have slots: onData(QByteArray) connect with signal data(QByteArray) and onEndRequest() connect with signal end() of each request comes to handler.
I also have router to route request to right handler.
But every time new request comes, it emits signal data(QByteArray), signal end() and all of my handlers catch these signal and connect to their slots.
Can you have a try to give an answer? thanks a lot.
Edited: I use Tufao on branch 0.x for Qt 4.7
Currently build exposes ALL configure-time defines to the sources appending arguments to the compilder command line.
This choice is suboptimal, because exposes unneeded defines to files not wanting it and, worse, it will recompile every source file if you change the configure-time defines.
Solution: Create a config.h (preferably out-of-tree in shadow builds) build-time generated file to aggregate all these changes. The config.h file could have its own directory, then the -I
compiler arg wouldn't expose more files than needed.
Hi, (issue copied from code.google, I saw that git is new repo)
Maybe will be better when you read this stackoverflow topic:
http://stackoverflow.com/questions/15029894/qt-cant-add-external-package
I have also tried precompiled binaries but they need Qt 4. So I don't know what to do.
Notice that on linux 64bit Qt 5.0.1 it is working fine. I just added whole tufao source into my project and everything works fine. On windows this trick doesn't work. I get hounded of errors "undefined reference...".
Regards
Tufão should have a logo.
The logo should be licensed under http://creativecommons.org/licenses/by/3.0/
The logo should use the color palette of Tango! project.
The HttpServerRequestRouter could cache path strings to avoid regex processing.
This enhancement proposal was originally documented on issue #14.
I have tryed to compile Tufao 1.0 using VS 2013 and I run into some problems:
After fixing both problems the compiler has problems with the definition of a template in this struct (priv/httpserverrequest.h line 99):
struct RawData
{
template<int N>
constexpr RawData(const char (&data)[N]) :
data(data),
size(N - 1)
{}
const char *data;
int size;
};
Any plan to support VS 2013? I'm doing something wrong at configuration level?
My CMake command is:
cmake .. -DCMAKE_INSTALL_PREFIX=c:/Qt/Qt5.3.0/5.3/msvc2013_64_opengl/ -DCMAKE_BUILD_TYPE=Release -G "NMake Makefiles"
Thanks,
David
Hi all,
i'm currently looking into adding SCGI support to Tufao, since i don't want Tufao to
do static file serving in a production environment.
I personally would go for scgi instead of fcgi because its much easier to implement,
basically just a netstring containing the headers, followed by the request body.
I thought maybe we could hijack onReadyRead in a HttpServerRequest subclass, parse
the netstring and assemble a Http compatible request and forward it to the already
implemented http parser.
Otoh, a scgi connector needs to worry about less things, like there will be no
websocket upgrades.
What solutions do you use currently? Is there maybe some request forwarder
for apache that works on request uris?
Like: GET index.html --> served by Apache
vs: GET api/something --> served by Tufao
I find no discussion on templating. I can think of several ways to implement a templating system with tufao, but, would like to hear why it's not there already? I can only assume no one has though it necessary, and everyone is just using strings for HTML. Which is incredibly cumbersome.
API to ease the creation of config files for HttpPluginServer
programatically.
Greetings.
The following minimum code demonstrates the problem:
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
HttpServer server;
QObject::connect(&server, &HttpServer::requestReady,
[](HttpServerRequest &request, HttpServerResponse &res) {
qDebug() << "request body = " << request.readBody();
res.writeHead(200, "OK");
res.end("Hello World\n");
});
server.listen(QHostAddress::Any, 8000);
return a.exec();
}
When client sends POST request with some time pause between headers and request body, i see empty request body in handler.
Investigation of source has not yet led to a beautiful solution. Please advise how to act in a case where I need to use POST request data in handler?
Thank.
Hi,
I'm building Tufao on Fedora and running on a 64-bit Intel CPU. On this OS, the x86_64 libraries need to go to /usr/lib64
and the i686 ones to /usr/lib
because you can have x86_64 and i686 libraries installed alongside each other.
Unfortunately, I'm not familiar enough with cmake to know how to solve this, but it shouldn't be too hard. :)
In main.cpp, when the router is being created, QRegularExpression{""} is used twice. What would cause the second one to hit? Wouldn't all match the first entry, and use the HttpFileServer, and not the NotFoundHandler?
How to compile tufao as a lib using qtcreator? thanks.
Tested on Ubuntu LTS 12.04 with GCC 4.6.3.
When compiled againt Qt5.2.1 the hello-world example works fine but the threads-example does not respond to any request. With strace we can see a single request being read but no handler is never called.
Tested on Qt4, same platform and compiler and the threaded example works fine.
Does tufao support media streaming downloading? such as mp3, mp4 and flv and so on.
I want to play these media and downloading the remaining parts at the same time.
I am new to tufao. and have no idea about the thead use of tufao, So, the following code maybe stupid.
1.
HttpServer *server;
WebThread webthread(server); #
server->moveToThread(&webthread);
webthread.start();
run with the fellowing error and exit.
QML debugging is enabled. Only use this in a safe environment.
Error - RtlWerpReportException failed with status code :-1073741823. Will try to launch the process directly
when using ThreadedHttpServer in the main.cpp, build result show:
E:\...\main.cpp:75: error: undefined reference to `Tufao::ThreadedHttpServer::ThreadedHttpServer(QObject*)'
How?
and if any example about ThreadedHttpServer will be great. and I want to set the Url Route.
Please help,Thanks.
Related to #29
When a new request is received I am doing something a long:
resp.writeHead(Tufao::HttpResponseStatus::OK);
resp.flush();
The application will process some data (when it arrives) and then issue the resp.write with the data that was received. Quite some time can pass between the resp.writehead and the first resp.write. In the client I am using QNAM and the metaDataChanged() signal is only emitted once the first piece of data was written. I would love to force the writing of the Keep-Alive and Transfer encoding.
It would be great to have some API that prevents me from issuing a resp.write(" ") just to force the writing of headers.
Hi,
Recently I'm impressed by the design model of NodeJS which uses the async IO event-driven model to gain a great concurrency. Which apache's model seems to be wrong for IO intensive requests.
I'm searching for c++ framework of the same/similar model, I found this, node.native, QtWebApp, Pion, etc.
For pion, I believe (not sure) it is a threaded model just like apache web server.
For node.native, it is the same model of NodeJS as it is a c++ port of NodeJS.
For this server, I still couldn't find any documentation about the design model being used. But I can see the keyword "asynchronous IO framework". Could you please clarify whether it is a similar model as NodeJS and/or its advantanges?
Thanks & Regards,
Simon
Hi @vinipsmaker,
I would like to know, what is the current state of tufao project and if it is alive?
I am asking because i liked the idea and i love Qt and i have interest to help.
Best regards.
I openend this as a own issue. I came over it while stress testing the threading code
with autobench/httperf.
And i found 2 problems but they come both from the same source:
Httperf opens lots of connections at the same time and runs requests on the server.
Every request has a timeout and if the timeout is reached it just closes the socket.
This may be no problem with the non threaded version ( i didn't check yet) but in the
threaded version you have pending requests if the server load is high.
They are waiting in a queue, the problem is if they reach the connection timeout the
sockets are closed and deleted WHILE they are still waiting. Also we don't have
socket error handling code (a error maybe should emit some signal and close the
request).
This creates two problems:
If you call flush on a closed socket you get a SIGPIPE termination. HttpFileHandler runs into this because it does not enter the eventloop when writing
multiple times to the socket. This can maybe be fixed with using
waitForBytesWritten() instead of flush as the docs state. This will return false
if a error occured.
The requests object are deleted behind the back of the application, i worked
around this by using QPointer objects , so at least i know when they are gone.
The question is if we should think about a different approach than directly connecting
request objects to their deleteLater slot, so we can handle these things better.
Hi all,
Is there any ways to synchronize between clients ? That means when a client request, server will response back to all clients, not just the client who makes request. In my cases, the number of clients is fixed, and the server knows information of all clients.
Many tks,
Check and import this commit: vegansk@4632bd0
Maybe it'll be a good idea to change others parts of the code too.
Initial work on the parse_form_data_uploaded_files branch.
Hi,
I'm using 0.x branch for my Qt 4.8.4. Cmake is going well, but make don't. This is my output:
make
[ 1%] Generating moc_httpupgraderouter.cxx
[ 3%] Generating moc_httpserver.cxx
[ 5%] Generating moc_httpserverrequest.cxx
[ 7%] Generating moc_httpserverresponse.cxx
[ 8%] Generating moc_httpsserver.cxx
[ 10%] Generating priv/moc_tcpserverwrapper.cxx
[ 12%] Generating moc_websocket.cxx
[ 14%] Generating moc_abstractmessagesocket.cxx
[ 16%] Generating moc_httpfileserver.cxx
[ 17%] Generating moc_abstracthttpserverrequesthandler.cxx
[ 19%] Generating moc_httpserverrequestrouter.cxx
[ 21%] Generating moc_httppluginserver.cxx
[ 23%] Generating moc_sessionstore.cxx
[ 25%] Generating moc_simplesessionstore.cxx
[ 26%] Generating moc_urlrewriterhandler.cxx
[ 28%] Generating moc_abstracthttpupgradehandler.cxx
Scanning dependencies of target tufao
[ 30%] Building CXX object src/CMakeFiles/tufao.dir/httpserver.cpp.o
[ 32%] Building CXX object src/CMakeFiles/tufao.dir/httpserverrequest.cpp.o
[ 33%] Building CXX object src/CMakeFiles/tufao.dir/httpserverresponse.cpp.o
[ 35%] Building CXX object src/CMakeFiles/tufao.dir/httpsserver.cpp.o
In file included from /home/x/Pobrane/tufao/src/httpsserver.cpp:19:0:
/home/x/Pobrane/tufao/src/priv/httpsserver.h:32:21: error: field ‘localCertificate’ has incomplete type
/home/x/Pobrane/tufao/src/priv/httpsserver.h:33:13: error: field ‘privateKey’ has incomplete type
/home/x/Pobrane/tufao/src/httpsserver.cpp: In member function ‘void Tufao::HttpsServer::setLocalCertificate(const QSslCertificate&)’:
/home/x/Pobrane/tufao/src/httpsserver.cpp:37:11: error: ‘struct Tufao::HttpsServer::Priv’ has no member named ‘localCertificate’
/home/x/Pobrane/tufao/src/httpsserver.cpp: In member function ‘void Tufao::HttpsServer::setPrivateKey(const QSslKey&)’:
/home/x/Pobrane/tufao/src/httpsserver.cpp:42:11: error: ‘struct Tufao::HttpsServer::Priv’ has no member named ‘privateKey’
/home/x/Pobrane/tufao/src/httpsserver.cpp: In member function ‘virtual void Tufao::HttpsServer::incomingConnection(int)’:
/home/x/Pobrane/tufao/src/httpsserver.cpp:51:5: error: ‘QSslSocket’ was not declared in this scope
/home/x/Pobrane/tufao/src/httpsserver.cpp:51:17: error: ‘socket’ was not declared in this scope
/home/x/Pobrane/tufao/src/httpsserver.cpp:51:30: error: expected type-specifier before ‘QSslSocket’
/home/x/Pobrane/tufao/src/httpsserver.cpp:51:30: error: expected ‘;’ before ‘QSslSocket’
/home/x/Pobrane/tufao/src/httpsserver.cpp:57:39: error: ‘struct Tufao::HttpsServer::Priv’ has no member named ‘localCertificate’
/home/x/Pobrane/tufao/src/httpsserver.cpp:58:33: error: ‘struct Tufao::HttpsServer::Priv’ has no member named ‘privateKey’
/home/x/Pobrane/tufao/src/httpsserver.cpp:61:16: error: type ‘’ argument given to ‘delete’, expected pointer
make[2]: *** [src/CMakeFiles/tufao.dir/httpsserver.cpp.o] Błąd 1
make[1]: *** [src/CMakeFiles/tufao.dir/all] Błąd 2
make: *** [all] Błąd 2
Regards
It would be nice to have a ThreadedHttpPluginServer, so the server can scale up when lots of requests come in at the same time.
A possible problem with this is the handling of the loaded plugins, each thread might need to load and unload them itself.
code below, MainHandler just copy from your other example.
TcpServer server;
// MainHandler h;
server.run(4, 8090, []() {
QSharedPointer<Tufao::HttpServerRequestRouter> router;
return [router](Tufao::HttpServerRequest &request,
Tufao::HttpServerResponse &response) mutable {
if (!router) {
MainHandler h;
router.reset(new Tufao::HttpServerRequestRouter);
router->map({QRegularExpression{"^/$"},
Tufao::UrlRewriterHandler::handler(QUrl("/index.html"))});
router->map({QRegularExpression{""}, h});
}
if (!router->handleRequest(request, response)) {
response.writeHead(Tufao::HttpResponseStatus::NOT_FOUND);
response.headers().insert("Content-Type", "text/plain");
response.end("Not found\n");
}
return true;
};
});
First of all, thanks for an awesome library.
Here's a small annoyance:
Currently websocket.h uses NO_ERROR as the first item in the Websocket::Error enum. This causes problems when building on windows as winerror.h does a #define NO_ERROR 0L. It fails to build unless the user is very careful not to include any files that end up including any windows headers before including <WebSocket>.
I suggest you rename the enum item.
Thanks.
example sessionusage not work when run opening the url, the browser always be loading,but not show the index.html file.
in 1.x release version and Qt5.3.1
can you have a try to give an answer? thanks a lot.
cmake -G "Visual Studio 11 Win64" .
results in
Performing Test CXX11_FLAG_DETECTED - Failed
Because the test case given in FindCXX11.cmake uses C++11 initializer lists and Visual Studio 2012 does not support this feature, it fails.
Unfortunately, it is not possible to build tufao with MSVC11.
Moreover, there might be further more C++11 features tufao uses, but VS11 does not support (http://cpprocks.com/a-comparison-of-c11-language-support-in-vs2012-g-4-7-and-clang-3-1/).
My code is doing:
response.writeHead(Tufao::HttpResponseStatus::NO_CONTENT);
response.end();
This generates a 204 No Content, with Transfer-Encoding: chunked and includes and empty chunk '0\r\n\r\n'. But this is not valid according to the RFC2616:
10.2.5 204 No Content
...
The 204 response MUST NOT include a message-body, and thus is always terminated by the first empty line after the header fields.
The Microsoft .NET HTTP Client is upset by the extra chunk being sent. The only work-around is to disable keep-alive by adding Connection: close to the request.
Currently the 0.x branch code does slightly incorrect unescaping of URL query string parameters.
Tufao::QueryString::parse("foo=bar¶m_with_significant_plus=%3B123") leads to a map with items foo="bar" and param_with_significant_plus=" 123".
It would be nice to cache often used files content to improve response time (in HttpFileServer::serveFile).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.