Skip to content

Commit

Permalink
Updated wsjcpp-core to v0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
sea5kg committed Apr 5, 2020
1 parent 133fbc3 commit ec6effa
Show file tree
Hide file tree
Showing 26 changed files with 550 additions and 429 deletions.
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ RewriteRule . index.html

Contains base handler:
```
WSJCppLightWebHttpHandlerRewriteFolder(sPrefixPath, sDirPath)
WsjcppLightWebHttpHandlerRewriteFolder(sPrefixPath, sDirPath)
```
Where
* sPrefixPath - like "/app1/" -> "http://localhost:1234/app1/"
Expand All @@ -61,10 +61,10 @@ Example init, add handler and start server
#include <wsjcpp_light_web_http_handler_rewrite_folder.h>
...
WSJCppLightWebServer httpServer;
WsjcppLightWebServer httpServer;
httpServer.setPort(1234);
httpServer.setMaxWorkers(1);
httpServer.addHandler((WSJCppLightWebHttpHandlerBase *)new WSJCppLightWebHttpHandlerRewriteFolder("/app1/", "./web"));
httpServer.addHandler((WsjcppLightWebHttpHandlerBase *)new WsjcppLightWebHttpHandlerRewriteFolder("/app1/", "./web"));
httpServer.startSync(); // this method will be hold current thread, if you with you can call just start/stop command
```

Expand All @@ -74,7 +74,7 @@ After compile and start will be available on `http://localhost:1234/app1/`

Contains base handler:
```
WSJCppLightWebHttpHandlerWebFolder(sPrefixPath, sDirPath)
WsjcppLightWebHttpHandlerWebFolder(sPrefixPath, sDirPath)
```

Where
Expand All @@ -88,10 +88,10 @@ Example init, add handler and start server
#include <wsjcpp_light_web_http_handler_web_folder.h>
...
WSJCppLightWebServer httpServer;
WsjcppLightWebServer httpServer;
httpServer.setPort(1234);
httpServer.setMaxWorkers(1);
httpServer.addHandler((WSJCppLightWebHttpHandlerBase *)new WSJCppLightWebHttpHandlerWebFolder("/app2/", "./web"));
httpServer.addHandler((WsjcppLightWebHttpHandlerBase *)new WsjcppLightWebHttpHandlerWebFolder("/app2/", "./web"));
httpServer.startSync(); // this method will be hold current thread, if you with you can call just start/stop command
```

Expand All @@ -108,11 +108,11 @@ header-file `http_handler_custom.h`:
#include <wsjcpp_light_web_server.h>
class HttpHandlerCustom : WSJCppLightWebHttpHandlerBase {
class HttpHandlerCustom : WsjcppLightWebHttpHandlerBase {
public:
HttpHandlerCustom();
virtual bool canHandle(const std::string &sWorkerId, WSJCppLightWebHttpRequest *pRequest);
virtual bool handle(const std::string &sWorkerId, WSJCppLightWebHttpRequest *pRequest);
virtual bool canHandle(const std::string &sWorkerId, WsjcppLightWebHttpRequest *pRequest);
virtual bool handle(const std::string &sWorkerId, WsjcppLightWebHttpRequest *pRequest);
private:
std::string TAG;
Expand All @@ -128,13 +128,13 @@ source-file `http_handler_custom.cpp`:
// ----------------------------------------------------------------------
HttpHandlerCustom::HttpHandlerCustom()
: WSJCppLightWebHttpHandlerBase("custom") {
: WsjcppLightWebHttpHandlerBase("custom") {
TAG = "HttpHandlerCustom";
}
// ----------------------------------------------------------------------
bool HttpHandlerCustom::canHandle(const std::string &sWorkerId, WSJCppLightWebHttpRequest *pRequest) {
bool HttpHandlerCustom::canHandle(const std::string &sWorkerId, WsjcppLightWebHttpRequest *pRequest) {
std::string _tag = TAG + "-" + sWorkerId;
std::string sRequestPath = pRequest->getRequestPath();
Expand All @@ -149,12 +149,12 @@ bool HttpHandlerCustom::canHandle(const std::string &sWorkerId, WSJCppLightWebHt
// ----------------------------------------------------------------------
bool HttpHandlerCustom::handle(const std::string &sWorkerId, WSJCppLightWebHttpRequest *pRequest) {
bool HttpHandlerCustom::handle(const std::string &sWorkerId, WsjcppLightWebHttpRequest *pRequest) {
std::string _tag = TAG + "-" + sWorkerId;
std::string sRequestPath = pRequest->getRequestPath();
// WSJCppLog::warn(_tag, sRequestPath);
// WsjcppLog::warn(_tag, sRequestPath);
WSJCppLightWebHttpResponse resp(pRequest->getSockFd());
WsjcppLightWebHttpResponse resp(pRequest->getSockFd());
if (sRequestPath == "/custom" || sRequestPath == "/custom/") {
resp.cacheSec(60).ok().sendText(
"<h1>This is custom</h1>"
Expand All @@ -175,10 +175,10 @@ bool HttpHandlerCustom::handle(const std::string &sWorkerId, WSJCppLightWebHttpR
Example init, add handler and start server
__order is important! Server will call canHandle & handle in same order as addHandler called__
```
WSJCppLightWebServer httpServer;
WsjcppLightWebServer httpServer;
httpServer.setPort(1234);
httpServer.setMaxWorkers(1);
httpServer.addHandler((WSJCppLightWebHttpHandlerBase *)new HttpHandlerCustom());
httpServer.addHandler((WSJCppLightWebHttpHandlerBase *)new WSJCppLightWebHttpHandlerRewriteFolder("/", "./web"));
httpServer.addHandler((WsjcppLightWebHttpHandlerBase *)new HttpHandlerCustom());
httpServer.addHandler((WsjcppLightWebHttpHandlerBase *)new WsjcppLightWebHttpHandlerRewriteFolder("/", "./web"));
httpServer.startSync(); // this method will be hold current thread, if you with you can call just start/stop command
```
20 changes: 10 additions & 10 deletions scripts.wsjcpp/generate.WsjcppLightWebHttpHandler
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ concat content_header "#ifndef " ifndef_header "

#include <wsjcpp_light_web_server.h>

class " class_name " : public WSJCppLightWebHttpHandlerBase {
class " class_name " : public WsjcppLightWebHttpHandlerBase {
public:
" class_name "();
virtual bool canHandle(const std::string &sWorkerId, WSJCppLightWebHttpRequest *pRequest);
virtual bool handle(const std::string &sWorkerId, WSJCppLightWebHttpRequest *pRequest);
virtual bool canHandle(const std::string &sWorkerId, WsjcppLightWebHttpRequest *pRequest);
virtual bool handle(const std::string &sWorkerId, WsjcppLightWebHttpRequest *pRequest);

private:
std::string TAG;
Expand All @@ -58,29 +58,29 @@ concat content_source "
// " class_name "

" class_name "::" class_name "()
: WSJCppLightWebHttpHandlerBase(\"" http_handler_name "\") {
: WsjcppLightWebHttpHandlerBase(\"" http_handler_name "\") {
TAG = \"" class_name "\";
}

// ---------------------------------------------------------------------

bool " class_name "::canHandle(const std::string &sWorkerId, WSJCppLightWebHttpRequest *pRequest) {
bool " class_name "::canHandle(const std::string &sWorkerId, WsjcppLightWebHttpRequest *pRequest) {
std::string _tag = TAG + \"-\" + sWorkerId;
std::string sRequestPath = pRequest->getRequestPath();
WSJCppLog::warn(_tag, \"canHandle: \" + sRequestPath);
WsjcppLog::warn(_tag, \"canHandle: \" + sRequestPath);

// TODO
WSJCppLog::err(TAG, \"Not implemented\");
WsjcppLog::err(TAG, \"Not implemented\");
return false;
}

// ---------------------------------------------------------------------

bool " class_name "::handle(const std::string &sWorkerId, WSJCppLightWebHttpRequest *pRequest) {
bool " class_name "::handle(const std::string &sWorkerId, WsjcppLightWebHttpRequest *pRequest) {
std::string _tag = TAG + \"-\" + sWorkerId;
std::string sRequestPath = pRequest->getRequestPath();
WSJCppLog::warn(_tag, sRequestPath);
WSJCppLightWebHttpResponse resp(pRequest->getSockFd());
WsjcppLog::warn(_tag, sRequestPath);
WsjcppLightWebHttpResponse resp(pRequest->getSockFd());
resp.noCache().notImplemented().sendEmpty();
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src.wsjcpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Automaticly generated by wsjcpp@v0.0.1
cmake_minimum_required(VERSION 3.0)

add_definitions(-DWSJCPP_VERSION="v0.0.1")
add_definitions(-DWSJCPP_VERSION="v0.1.0")
add_definitions(-DWSJCPP_NAME="wsjcpp-light-web-server")

if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
Expand All @@ -17,7 +17,7 @@ set (WSJCPP_SOURCES "")
find_package(Threads REQUIRED)
list (APPEND WSJCPP_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})

# wsjcpp-core:v0.0.7
# wsjcpp-core:v0.1.1
list (APPEND WSJCPP_INCLUDE_DIRS "./src.wsjcpp/wsjcpp_core/")
list (APPEND WSJCPP_SOURCES "./src.wsjcpp/wsjcpp_core/wsjcpp_core.cpp")
list (APPEND WSJCPP_SOURCES "./src.wsjcpp/wsjcpp_core/wsjcpp_core.h")
Expand Down
8 changes: 7 additions & 1 deletion src.wsjcpp/wsjcpp_core/wsjcpp.hold.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_cxx_standard: 11
cmake_minimum_required: 3.0

name: wsjcpp-core
version: v0.0.7
version: v0.1.1
description: Basic Utils for wsjcpp
issues: https://github.com/wsjcpp/wsjcpp-core/issues
repositories:
Expand Down Expand Up @@ -62,3 +62,9 @@ unit-tests:
description: "Test split function"
- name: "CreateEmptyFile"
description: "Test create empty file"
- name: "ReadFileToBuffer"
description: "test for readFileToBuffer"
- name: "Join"
description: "Test join function"
- name: "getHumanSizeBytes"
description: "Test function get human size in bytes"
Loading

0 comments on commit ec6effa

Please sign in to comment.