https://github.com/wille-io/httq
httq is an HTTP Server for Qt. Allows WebSocket connections. Based on NodeJS's http-parser.
https://github.com/wille-io/httq
http-parser http-server httpd qt websocket websocket-server websockets
Last synced: 16 days ago
JSON representation
httq is an HTTP Server for Qt. Allows WebSocket connections. Based on NodeJS's http-parser.
- Host: GitHub
- URL: https://github.com/wille-io/httq
- Owner: wille-io
- License: mit
- Created: 2020-07-06T20:05:27.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-04-22T08:51:10.000Z (about 2 years ago)
- Last Synced: 2025-01-10T03:51:41.269Z (over 1 year ago)
- Topics: http-parser, http-server, httpd, qt, websocket, websocket-server, websockets
- Language: C++
- Homepage:
- Size: 84 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# httq
HTTP server library for Qt. Doesn't clog the memory like The Other HTTP Server™.
Based on NodeJS's wonderful http-parser.
Can download a message's body in chunks, instead of reading it all into memory that allows an easy DoS, like The Other HTTP Server™.
## CMake Integration
### Option A: Add as Subdirectory (recommended for local use)
```
add_subdirectory(path/to/httq)
add_executable(my_app main.cpp)
target_link_libraries(my_app
PRIVATE
httq
Qt${Qt_VERSION_MAJOR}::Core
Qt${Qt_VERSION_MAJOR}::Network
Qt${Qt_VERSION_MAJOR}::WebSockets
)
target_include_directories(my_app PRIVATE path/to/httq/include)
```
### Option B: Installed Library via find_package
```
find_package(httq REQUIRED)
add_executable(my_app main.cpp)
target_link_libraries(my_app PRIVATE httq::httq)
```
> Note: This works after installing httq (exports targets and config files).
> For local projects, option A is currently the simplest approach.
### Installing httq
```
cmake -S . -B build
cmake --build build
sudo cmake --install build
```
## C++ Examples
### Minimal HTTP Handler
```cpp
#include
#include
class HelloHandler : public httq::AbstractHandler
{
public:
void handle() override
{
answer(200, "Hello from httq");
}
};
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
httq::HandlerServer server;
server.addHandler("GET", "/hello", []() { return new HelloHandler(); });
server.listen(8080);
return app.exec();
}
```
### JSON Response
```cpp
#include
#include
class JsonHandler : public httq::AbstractHandler
{
public:
void handle() override
{
QJsonObject obj { { "ok", true } };
answer(200, obj);
}
};
```
### Body Handling with AbstractBodyHandler
```cpp
#include
class EchoHandler : public httq::AbstractBodyHandler
{
public:
using httq::AbstractBodyHandler::AbstractBodyHandler;
void bodyHandle() override
{
answer(200, body(), "text/plain");
}
};
```
## Build and Run Tests (QTest)
```
cmake -S . -B build -DHTTQ_BUILD_TESTS=ON
cmake --build build
ctest --test-dir build
```