Skip to content

Commit

Permalink
fix:route Chinese bug
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxuan520 committed Mar 24, 2023
1 parent 67a9b0c commit 39611f2
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 15 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
bin
*.out
*.exe
main
main_ssl
old
*.vim
*.pid
*.log
8 changes: 4 additions & 4 deletions doc/HttpServer.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

- 介绍httpserver类的函数和使用

## 类说明
## 类说明
1. 强烈建议您先看这个类这个是2.0版本的server,入门非常简单

2. 该类private继承ServerTcpIp,但您不需要提前学其父类

## 类定义类型
## 类定义类型

### RouteType
### RouteType

```cpp
enum RouteType{//oneway stand for like /hahah,wild if /hahah/*,static is recource static
Expand Down Expand Up @@ -242,4 +242,4 @@ inline void stopServer()
inline void resetServer()
```

- 清除所有路由信息
- 清除所有路由信息
2 changes: 1 addition & 1 deletion doc/serverbuild.cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

4. 服务器运行

##### 填入信息
##### 填入信息

5. 填入绑定的端口(如5200)

Expand Down
10 changes: 6 additions & 4 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ pro_source=./src/hpp/cppweb.h ./src/hpp/argc.h ./src/hpp/email.h
source=./src/cpp/main.cpp ./src/hpp/cppweb.h ./src/hpp/proxy.h ./src/hpp/config.h ./src/hpp/route.h ./src/hpp/argc.h
link=-lpthread
link_ssl=-lpthread -lssl -lcrypto
macro=-D CPPWEB_OPENSSL
ssl_macro=-D CPPWEB_OPENSSL
debug_macro=-D CPPWEB_DEBUG
install_dir=/usr/local/include/cppweb

.PHONY:ssl
Expand All @@ -23,12 +24,13 @@ main: $(source)
$(cc) -O2 $(obj_source) -o $(obj) $(link)
clean:
rm -f *.o
rm server.pid access.log main
ssl: $(source)
$(cc) -O2 $(obj_source) -o $(obj) $(macro) $(link_ssl)
$(cc) -O2 $(obj_source) -o $(obj) $(ssl_macro) $(link_ssl)
debug:
$(cc) -g $(obj_source) -o $(obj) $(link)
$(cc) -g $(obj_source) -o $(obj) $(debug_macro) $(link)
ssldebug:
$(cc) -g $(obj_source) -o $(obj) $(macro) $(link_ssl)
$(cc) -g $(obj_source) -o $(obj) $(debug_macro) $(ssl_macro) $(link_ssl)
install:
mkdir $(install_dir)
cp $(pro_source) $(install_dir)
Expand Down
5 changes: 3 additions & 2 deletions makefile.win
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ pro_source=./src/hpp/cppweb.h ./src/hpp/argc.h ./src/hpp/email.h
source=./src/cpp/main.cpp ./src/hpp/cppweb.h ./src/hpp/proxy.h ./src/hpp/config.h ./src/hpp/route.h ./src/hpp/argc.h
link=-lpthread -lwsock32
link_ssl=-lpthread -lwsock32 -lssl -lcrypto
macro=-D CPPWEB_OPENSSL
ssl_macro=-D CPPWEB_OPENSSL
debug_macro=-D CPPWEB_DEBUG
compile_option=-std=c++11

main: $(source)
$(cc) -O2 $(obj_source) -o $(obj) $(link) $(compile_option)
clean:
rm -f *.o
ssl: $(source)
$(cc) -O2 $(obj_source) -o $(obj) $(macro) $(link_ssl)
$(cc) -O2 $(obj_source) -o $(obj) $(ssl_macro) $(link_ssl)
debug:
$(cc) -g $(obj_source) -o $(obj) $(link)
18 changes: 14 additions & 4 deletions src/hpp/cppweb.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@
#define CPPWEB_VERSION "v1.0.1"
#endif

#ifndef CPPWEB_DEBUG
#define CPPWEBDEBUG(text) std::cout<<"Debug: "<<text<<std::endl;
#define CPPWEBASSERT(text) assert(text)
#else
#define CPPWEBDEBUG(text) (void*)0
#define CPPWEBASSERT(text) (void*)0
#endif

namespace cppweb{
typedef std::unordered_map<std::string,std::string> KeyMap;
//this class for windows
Expand Down Expand Up @@ -2782,6 +2790,7 @@ class DealHttp{
isFull=true;
req.method=one;
req.askPath=two;
req.urlDecode(req.askPath);
req.version=three;
req.body=end+4;
if(!onlyTop)
Expand Down Expand Up @@ -2886,7 +2895,7 @@ class DealHttp{
this->method.clear();
this->askPath.clear();
}
void urlDecode(std::string& srcString)
static void urlDecode(std::string& srcString)
{
char ch=0;
int temp=0;
Expand Down Expand Up @@ -3437,6 +3446,7 @@ class DealHttp{
const char* ask=this->analysisHttpAsk(message);
if(askPath.size()==0||NULL==ask)
return 1;
DealHttp::Request::urlDecode(askPath);
int temp=0;
if(strcmp(ask,"HTTP/1.1")==0||strcmp(ask,"HTTP/1.0")==0)
temp=this->createSendMsg(HTML,psend,bufferLen,pfirstFile,plen);
Expand Down Expand Up @@ -5079,7 +5089,7 @@ class HttpServer:private ServerTcpIp{
{
strcpy(ask,http.analysisHttpAsk(getText));
do{
flag=http.autoAnalysisGet((char*)getText,senText.buffer,senText.getMaxSize(),defaultFile,&len);
flag=http.autoAnalysisGet((const char*)getText,senText.buffer,senText.getMaxSize(),defaultFile,&len);
if(flag==2&&senText.getMaxSize()<maxLen*1024*1024)
senText.enlargeMemory();
}while(flag==2&&senText.getMaxSize()<maxLen*1024*1024);
Expand Down Expand Up @@ -5305,11 +5315,11 @@ class HttpServer:private ServerTcpIp{
int len=0,flag=0;
char ask[200]={0},buf[500]={0},temp[200]={0};
http.getAskRoute(server.recText(http),"GET",ask,200);
DealHttp::urlDecode(ask);
HttpServer::RouteFuntion& route=*server.getNowRoute(http.info.nowRoute);
http.getWildUrl(ask,route.route,temp,200);
sprintf(buf,"GET %s%s HTTP/1.1",route.pathExtra,temp);
do
{
do{
flag=http.autoAnalysisGet(buf,(char*)server.getSenBuffer(http),server.senBuffer.getMaxSize(),NULL,&len);
if(flag==2&&server.senBuffer.getMaxSize()<server.maxLen*1024*1024)
server.enlagerSenBuffer();
Expand Down
13 changes: 13 additions & 0 deletions src/test/urldecode_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <iostream>
#include <vector>
#include <string>
#include "../hpp/cppweb.h"
using namespace std;

int main()
{
char temp[100]="/ji%E7%A7%AF%E6%9E%81";
cppweb::DealHttp::urlDecode(temp);
std::cout << temp << std::endl;
return 0;
}

0 comments on commit 39611f2

Please sign in to comment.