xcbosa-itx 2 жил өмнө
parent
commit
1950ed1867

+ 14 - 2
frp.cpp

@@ -110,9 +110,17 @@ namespace xc::frp {
                     return;
                 }
             }
+            INIFile profileINI(this->filePath);
+            bool shouldRunning = profileINI.data.size() > 1;
             if (getRunningPid() == 0) {
-                cout << "[FrpProcessWrapper] [" << fileName << "] Exit unexpectedly, restarting..." << endl;
-                this->doStart();
+                if (shouldRunning) {
+                    cout << "[FrpProcessWrapper] [" << fileName << "] Exit unexpectedly, restarting..." << endl;
+                    this->doStart();
+                }
+            } else {
+                if (!shouldRunning) {
+                    this->doKill();
+                }
             }
         }
 
@@ -162,6 +170,10 @@ namespace xc::frp {
             if (stat(this->filePath.c_str(), &buf) == 0) {
                 this->mutationTime = buf.st_mtime;
             }
+            INIFile profileINI(this->filePath);
+            if (profileINI.data.size() < 2) {
+                return;
+            }
             ostringstream oss;
             oss << "frpc -c " << this->filePath << " &";
             string launchCmd = oss.str();

+ 14 - 9
httpserver/ClientConnection.cpp

@@ -66,6 +66,11 @@ namespace xc {
                 bool lastLineIsEmpty = false;
                 bool lastLineEmptyAndZero = false;
                 while (::fgets(requestBuff, urlRequestBuffSize, clRead)) {
+                    if (method == "GET") {
+                        if (strcmp(requestBuff, "\r\n") == 0) {
+                            break;
+                        }
+                    }
                     int len = ::strlen(requestBuff);
                     char *lineBuff = (char *) ::malloc(len + 1), *pLineBuff = lineBuff;
                     bool leftHasContext = false;
@@ -89,16 +94,16 @@ namespace xc {
                     }
                     if (::strlen(lineBuff) == 0) {
                         // TODO: Fix Linux POST Method
-//                        isHeader = false;
-//                        lastLineIsEmpty = true;
-//                        if (lastLineEmptyAndZero) {
-//                            break;
-//                        } else {
-//                            lastLineEmptyAndZero = false;
-//                        }
-//                        if (method == "GET") {
+                        isHeader = false;
+                        lastLineIsEmpty = true;
+                        if (lastLineEmptyAndZero) {
                             break;
-//                        }
+                        } else {
+                            lastLineEmptyAndZero = false;
+                        }
+                        if (method == "GET") {
+                            break;
+                        }
                         continue;
                     }
                     if (lineBuff[0] == '0') {

+ 5 - 5
utils/TextResponseData.cpp

@@ -57,18 +57,18 @@ namespace xc {
 
         void TextResponseData::writeTo(::FILE *fp) const {
             ::fprintf(fp, "HTTP/1.1 %d XCHttpServer\r\n", this->statusCode);
-            map<string, string> headers(this->headers);
             if (!this->cookies.empty()) {
-                ostringstream oss;
                 for (auto it : this->cookies) {
+                    ostringstream oss;
                     oss << it.first;
                     oss << "=";
                     oss << it.second;
-                    oss << "; ";
+                    oss << "; Path=/";
+                    string str = oss.str();
+                    ::fprintf(fp, "%s: %s\r\n", "Set-Cookie", str.c_str());
                 }
-                headers["Set-Cookie"] = oss.str();
             }
-            for (auto item : headers) {
+            for (auto item : this->headers) {
                 ::fprintf(fp, "%s: %s\r\n", item.first.c_str(), item.second.c_str());
             }
             ::fputs("\r\n", fp);