Skip to content

Commit

Permalink
Optimize codes
Browse files Browse the repository at this point in the history
  • Loading branch information
tindy2013 committed Sep 8, 2020
1 parent 4459dd7 commit 372140c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
12 changes: 6 additions & 6 deletions scripts/build.windows.release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ set -xe

git clone https://github.com/curl/curl --depth=1
cd curl
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_USE_LIBSSH2=OFF -DHTTP_ONLY=ON -DCMAKE_USE_SCHANNEL=ON -DBUILD_SHARED_LIBS=OFF -DBUILD_CURL_EXE=OFF -DCMAKE_INSTALL_PREFIX=$MINGW_PREFIX -G "Unix Makefiles" .
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_USE_LIBSSH2=OFF -DHTTP_ONLY=ON -DCMAKE_USE_SCHANNEL=ON -DBUILD_SHARED_LIBS=OFF -DBUILD_CURL_EXE=OFF -DCMAKE_INSTALL_PREFIX="$MINGW_PREFIX" -G "Unix Makefiles" .
make install -j4
cd ..

git clone https://github.com/jbeder/yaml-cpp --depth=1
cd yaml-cpp
cmake -DCMAKE_BUILD_TYPE=Release -DYAML_CPP_BUILD_TESTS=OFF -DYAML_CPP_BUILD_TOOLS=OFF -DCMAKE_INSTALL_PREFIX=$MINGW_PREFIX -G "Unix Makefiles" .
cmake -DCMAKE_BUILD_TYPE=Release -DYAML_CPP_BUILD_TESTS=OFF -DYAML_CPP_BUILD_TOOLS=OFF -DCMAKE_INSTALL_PREFIX="$MINGW_PREFIX" -G "Unix Makefiles" .
make install -j4
cd ..

Expand All @@ -23,14 +23,14 @@ gcc -c -O3 -o duktape.o duktape.c
gcc -c -O3 -o duk_module_node.o -I. ../extras/module-node/duk_module_node.c
ar cr libduktape.a duktape.o
ar cr libduktape_module.a duk_module_node.o
install -m0644 ./*.a $MINGW_PREFIX/lib
install -m0644 ./duk*.h $MINGW_PREFIX/include
install -m0644 ../extras/module-node/duk_module_node.h $MINGW_PREFIX/include
install -m0644 ./*.a "$MINGW_PREFIX/lib"
install -m0644 ./duk*.h "$MINGW_PREFIX/include"
install -m0644 ../extras/module-node/duk_module_node.h "$MINGW_PREFIX/include"
cd ../../../..

git clone https://github.com/Tencent/rapidjson --depth=1
cd rapidjson
cmake -DRAPIDJSON_BUILD_DOC=OFF -DRAPIDJSON_BUILD_EXAMPLES=OFF -DRAPIDJSON_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=$MINGW_PREFIX -G "Unix Makefiles" .
cmake -DRAPIDJSON_BUILD_DOC=OFF -DRAPIDJSON_BUILD_EXAMPLES=OFF -DRAPIDJSON_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX="$MINGW_PREFIX" -G "Unix Makefiles" .
make install -j4
cd ..

Expand Down
2 changes: 1 addition & 1 deletion src/webget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ void flushCache()
//guarded_mutex guard(cache_rw_lock);
cache_rw_lock.writeLock();
defer(cache_rw_lock.writeUnlock();)
operateFiles("cache", [](std::string file){ remove(("cache/" + file).data()); return 0; });
operateFiles("cache", [](const std::string &file){ remove(("cache/" + file).data()); return 0; });
}

int curlPost(const std::string &url, const std::string &data, const std::string &proxy, const string_array &request_headers, std::string *retData)
Expand Down
11 changes: 8 additions & 3 deletions src/webserver_libevent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ bool matchSpaceSeparatedList(const std::string& source, const std::string &targe
return false;
}

std::string checkMIMEType(const std::string filename)
std::string checkMIMEType(const std::string &filename)
{
string_size name_begin = 0, name_end = 0;
name_begin = filename.rfind('/');
Expand Down Expand Up @@ -102,6 +102,7 @@ const char *request_header_blacklist[] = {"host", "accept", "accept-encoding"};

static inline void buffer_cleanup(struct evbuffer *eb)
{
(void)eb;
//evbuffer_free(eb);
#ifdef MALLOC_TRIM
malloc_trim(0);
Expand All @@ -121,7 +122,7 @@ static inline int process_request(Request &request, Response &response, std::str

for(responseRoute &x : responses)
{
if(request.method == "OPTIONS" && startsWith(request.postdata, x.method) && x.path == request.url)
if(request.method == "OPTIONS" && matchSpaceSeparatedList(replace_all_distinct(request.postdata, ",", ""), x.method) && x.path == request.url)
{
return 1;
}
Expand Down Expand Up @@ -160,6 +161,7 @@ static inline int process_request(Request &request, Response &response, std::str

void OnReq(evhttp_request *req, void *args)
{
(void)args;
const char *req_content_type = evhttp_find_header(req->input_headers, "Content-Type"), *req_ac_method = evhttp_find_header(req->input_headers, "Access-Control-Request-Method");
const char *uri = req->uri, *internal_flag = evhttp_find_header(req->input_headers, "SubConverter-Request");

Expand Down Expand Up @@ -193,6 +195,9 @@ void OnReq(evhttp_request *req, void *args)
case EVHTTP_REQ_GET: request.method = "GET"; break;
case EVHTTP_REQ_POST: request.method = "POST"; break;
case EVHTTP_REQ_OPTIONS: request.method = "OPTIONS"; break;
case EVHTTP_REQ_PUT: request.method = "PUT"; break;
case EVHTTP_REQ_PATCH: request.method = "PATCH"; break;
case EVHTTP_REQ_DELETE: request.method = "DELETE"; break;
default: break;
}
request.url = uri;
Expand Down Expand Up @@ -276,7 +281,7 @@ int start_web_server(void *argv)
return -1;
}

evhttp_set_allowed_methods(Server.get(), EVHTTP_REQ_GET | EVHTTP_REQ_POST | EVHTTP_REQ_OPTIONS);
evhttp_set_allowed_methods(Server.get(), EVHTTP_REQ_GET | EVHTTP_REQ_POST | EVHTTP_REQ_OPTIONS | EVHTTP_REQ_PUT | EVHTTP_REQ_PATCH | EVHTTP_REQ_DELETE);
evhttp_set_gencb(Server.get(), OnReq, nullptr);
evhttp_set_timeout(Server.get(), 30);
if (event_dispatch() == -1)
Expand Down

0 comments on commit 372140c

Please sign in to comment.