Loading examples/httpsysinfo.cpp +5 −6 Changes for examples/httpsysinfo.cpp: 5 added lines, 6 removed lines. Original line number Diff line number Diff line Loading @@ -219,13 +219,13 @@ public: sys.TimeInfo(index); sys.KernelInfo(index); libhtmlpp::print(index,html); curres.send(curreq,html.data(),html.size()); curres.send(curreq,html.data(),html.length()); }else if(curreq.getRequestURL()=="/images/header.png"){ curres.setContentType("image/png"); curres.setContentLength(header_png_size); curres.send(curreq,"", -1); }else if(curreq.getRequestURL()=="/favicon.ico "){ curres.setContentType("image/ico"); curres.setContentType("image/x-icon"); curres.setContentLength(favicon_ico_size); curres.send(curreq,"", -1); }else{ Loading @@ -238,7 +238,6 @@ public: } /*virtual method from event will call for every incomming Request*/ void RequestEvent(libhttppp::HttpRequest& curreq, const int tid,ULONG_PTR args){ std::cout << "url: " << curreq.getRequestURL() << std::endl; try{ /*self implemented controller see above*/ IndexController(curreq); Loading @@ -251,12 +250,12 @@ public: } void ResponseEvent(libhttppp::HttpRequest& curreq, const int tid,ULONG_PTR args){ if(curreq.getRequestURL()=="/images/header.png"){ std::cerr << "ResponseEvent called for: [" << curreq.getRequestURL() << "]\n"; if (curreq.SendData.pos < header_png_size) { size_t si = BLOCKSIZE < (header_png_size-curreq.SendData.pos) ? BLOCKSIZE : (header_png_size-curreq.SendData.pos); size_t rem = header_png_size - curreq.SendData.pos; size_t si = (rem > BLOCKSIZE) ? BLOCKSIZE : rem; curreq.SendData.append((const char*)header_png + curreq.SendData.pos, si); curreq.SendData.pos += si; } } else if(curreq.getRequestURL()=="/favicon.ico "){ if(curreq.SendData.pos < favicon_ico_size){ size_t si = BLOCKSIZE < (favicon_ico_size-curreq.SendData.pos) ? BLOCKSIZE : (favicon_ico_size-curreq.SendData.pos); Loading src/http.cpp +2 −2 Changes for src/http.cpp: 2 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -42,7 +42,7 @@ #include "exception.h" #include <netplus/base64.h> #include <netplus/crypto/base64.h> #include <netplus/connection.h> #include <netplus/exception.h> Loading Loading @@ -1356,7 +1356,7 @@ size_t libhttppp::HttpRequest::parse() { // 3) Consume header (and the delimiter) from RecvData endpos += 4; // include "\r\n\r\n" RecvData.resize(endpos); RecvData.erase(RecvData.begin(),RecvData.begin()+endpos); // 4) Parse the request line (first line until CRLF) size_t line_end = 0; Loading src/httpd.cpp +23 −3 Changes for src/httpd.cpp: 23 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -85,7 +85,7 @@ REQUESTHANDLING: case POSTREQUEST: if(cureq.RecvData.size()>=cureq.getContentLength()){ RequestEvent(cureq,tid,args); cureq.RecvData.resize(cureq.getContentLength()); cureq.RecvData.erase(cureq.RecvData.begin(),cureq.RecvData.begin()+cureq.getContentLength()); cureq._RequestType=PARSEREQUEST; } break; Loading Loading @@ -135,7 +135,8 @@ libhttppp::HttpD::HttpD(int argc, char** argv) { HTTPDCmdController.registerCmd("httpaddr",'a', true,"","Address to listen"); HTTPDCmdController.registerCmd("httpport", 'p', false, 8080, "Port to listen"); HTTPDCmdController.registerCmd("maxconnections", 'm',false, MAXDEFAULTCONN, "Max connections that can connect"); HTTPDCmdController.registerCmd("httpsder", 's',false,"", "SSL DER File"); HTTPDCmdController.registerCmd("httpsder", 'c',false,"", "SSL DER File"); HTTPDCmdController.registerCmd("httpskeyder", 'k', false, "", "SSL RSA private key (DER)"); /*Parse Parameters*/ HTTPDCmdController.parseCmd(argc,argv); Loading Loading @@ -173,11 +174,30 @@ libhttppp::HttpD::HttpD(int argc, char** argv) { if (HTTPDCmdController.getCmdbyKey("httpsder")) derfile = HTTPDCmdController.getCmdbyKey("httpsder")->getValue(); std::string keyder; if (HTTPDCmdController.getCmdbyKey("httpskeyder")) keyder = HTTPDCmdController.getCmdbyKey("httpskeyder")->getValue(); try { if (!derfile.empty()) { if (keyder.empty()) { _httpexception[HTTPException::Critical] << "httpsder set but httpskeyder missing"; throw _httpexception; } netplus::x509cert x509; x509.loadFromFile(derfile); _ServerSocket = std::make_unique<netplus::ssl>(httpaddr, port, maxconnections,-1,x509); if (!x509.checkValidity()) { _httpexception[HTTPException::Critical] << "invalid certfile!"; throw _httpexception; } auto ss = std::make_unique<netplus::ssl>(httpaddr, port, maxconnections, -1, x509); // IMPORTANT: load private key to fill ss->_rsa.n/e/d ss->loadServerPrivateKeyDer(keyder); _ServerSocket = std::move(ss); }else{ #ifndef Windows if (portset == true) Loading Loading
examples/httpsysinfo.cpp +5 −6 Changes for examples/httpsysinfo.cpp: 5 added lines, 6 removed lines. Original line number Diff line number Diff line Loading @@ -219,13 +219,13 @@ public: sys.TimeInfo(index); sys.KernelInfo(index); libhtmlpp::print(index,html); curres.send(curreq,html.data(),html.size()); curres.send(curreq,html.data(),html.length()); }else if(curreq.getRequestURL()=="/images/header.png"){ curres.setContentType("image/png"); curres.setContentLength(header_png_size); curres.send(curreq,"", -1); }else if(curreq.getRequestURL()=="/favicon.ico "){ curres.setContentType("image/ico"); curres.setContentType("image/x-icon"); curres.setContentLength(favicon_ico_size); curres.send(curreq,"", -1); }else{ Loading @@ -238,7 +238,6 @@ public: } /*virtual method from event will call for every incomming Request*/ void RequestEvent(libhttppp::HttpRequest& curreq, const int tid,ULONG_PTR args){ std::cout << "url: " << curreq.getRequestURL() << std::endl; try{ /*self implemented controller see above*/ IndexController(curreq); Loading @@ -251,12 +250,12 @@ public: } void ResponseEvent(libhttppp::HttpRequest& curreq, const int tid,ULONG_PTR args){ if(curreq.getRequestURL()=="/images/header.png"){ std::cerr << "ResponseEvent called for: [" << curreq.getRequestURL() << "]\n"; if (curreq.SendData.pos < header_png_size) { size_t si = BLOCKSIZE < (header_png_size-curreq.SendData.pos) ? BLOCKSIZE : (header_png_size-curreq.SendData.pos); size_t rem = header_png_size - curreq.SendData.pos; size_t si = (rem > BLOCKSIZE) ? BLOCKSIZE : rem; curreq.SendData.append((const char*)header_png + curreq.SendData.pos, si); curreq.SendData.pos += si; } } else if(curreq.getRequestURL()=="/favicon.ico "){ if(curreq.SendData.pos < favicon_ico_size){ size_t si = BLOCKSIZE < (favicon_ico_size-curreq.SendData.pos) ? BLOCKSIZE : (favicon_ico_size-curreq.SendData.pos); Loading
src/http.cpp +2 −2 Changes for src/http.cpp: 2 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -42,7 +42,7 @@ #include "exception.h" #include <netplus/base64.h> #include <netplus/crypto/base64.h> #include <netplus/connection.h> #include <netplus/exception.h> Loading Loading @@ -1356,7 +1356,7 @@ size_t libhttppp::HttpRequest::parse() { // 3) Consume header (and the delimiter) from RecvData endpos += 4; // include "\r\n\r\n" RecvData.resize(endpos); RecvData.erase(RecvData.begin(),RecvData.begin()+endpos); // 4) Parse the request line (first line until CRLF) size_t line_end = 0; Loading
src/httpd.cpp +23 −3 Changes for src/httpd.cpp: 23 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -85,7 +85,7 @@ REQUESTHANDLING: case POSTREQUEST: if(cureq.RecvData.size()>=cureq.getContentLength()){ RequestEvent(cureq,tid,args); cureq.RecvData.resize(cureq.getContentLength()); cureq.RecvData.erase(cureq.RecvData.begin(),cureq.RecvData.begin()+cureq.getContentLength()); cureq._RequestType=PARSEREQUEST; } break; Loading Loading @@ -135,7 +135,8 @@ libhttppp::HttpD::HttpD(int argc, char** argv) { HTTPDCmdController.registerCmd("httpaddr",'a', true,"","Address to listen"); HTTPDCmdController.registerCmd("httpport", 'p', false, 8080, "Port to listen"); HTTPDCmdController.registerCmd("maxconnections", 'm',false, MAXDEFAULTCONN, "Max connections that can connect"); HTTPDCmdController.registerCmd("httpsder", 's',false,"", "SSL DER File"); HTTPDCmdController.registerCmd("httpsder", 'c',false,"", "SSL DER File"); HTTPDCmdController.registerCmd("httpskeyder", 'k', false, "", "SSL RSA private key (DER)"); /*Parse Parameters*/ HTTPDCmdController.parseCmd(argc,argv); Loading Loading @@ -173,11 +174,30 @@ libhttppp::HttpD::HttpD(int argc, char** argv) { if (HTTPDCmdController.getCmdbyKey("httpsder")) derfile = HTTPDCmdController.getCmdbyKey("httpsder")->getValue(); std::string keyder; if (HTTPDCmdController.getCmdbyKey("httpskeyder")) keyder = HTTPDCmdController.getCmdbyKey("httpskeyder")->getValue(); try { if (!derfile.empty()) { if (keyder.empty()) { _httpexception[HTTPException::Critical] << "httpsder set but httpskeyder missing"; throw _httpexception; } netplus::x509cert x509; x509.loadFromFile(derfile); _ServerSocket = std::make_unique<netplus::ssl>(httpaddr, port, maxconnections,-1,x509); if (!x509.checkValidity()) { _httpexception[HTTPException::Critical] << "invalid certfile!"; throw _httpexception; } auto ss = std::make_unique<netplus::ssl>(httpaddr, port, maxconnections, -1, x509); // IMPORTANT: load private key to fill ss->_rsa.n/e/d ss->loadServerPrivateKeyDer(keyder); _ServerSocket = std::move(ss); }else{ #ifndef Windows if (portset == true) Loading