hewei.it %!s(int64=4) %!d(string=hai) anos
pai
achega
6655bd96a4
Modificáronse 1 ficheiros con 22 adicións e 28 borrados
  1. 22 28
      http/HttpMessage.h

+ 22 - 28
http/HttpMessage.h

@@ -115,6 +115,27 @@ public:
         json = t;
         return 200;
     }
+
+    void UploadFormFile(const char* name, const char* filepath) {
+        content_type = MULTIPART_FORM_DATA;
+        form[name] = FormData(NULL, filepath);
+    }
+
+    int SaveFormFile(const char* name, const char* filepath) {
+        if (content_type != MULTIPART_FORM_DATA) {
+            return HTTP_STATUS_BAD_REQUEST;
+        }
+        FormData formdata = form[name];
+        if (formdata.content.empty()) {
+            return HTTP_STATUS_BAD_REQUEST;
+        }
+        HFile file;
+        if (file.open(filepath, "wb") != 0) {
+            return HTTP_STATUS_INTERNAL_SERVER_ERROR;
+        }
+        file.write(formdata.content.data(), formdata.content.size());
+        return 200;
+    }
 #endif
 
     HttpMessage() {
@@ -187,13 +208,7 @@ public:
         return content_type;
     }
 
-    int String(const char* str) {
-        content_type = TEXT_PLAIN;
-        body = str;
-        return 200;
-    }
-
-    int String(std::string& str) {
+    int String(const std::string& str) {
         content_type = TEXT_PLAIN;
         body = str;
         return 200;
@@ -221,27 +236,6 @@ public:
         file.readall(body);
         return 200;
     }
-
-    void UploadFormFile(const char* name, const char* filepath) {
-        content_type = MULTIPART_FORM_DATA;
-        form[name] = FormData(NULL, filepath);
-    }
-
-    int SaveFormFile(const char* name, const char* filepath) {
-        if (content_type != MULTIPART_FORM_DATA) {
-            return HTTP_STATUS_BAD_REQUEST;
-        }
-        FormData formdata = form[name];
-        if (formdata.content.empty()) {
-            return HTTP_STATUS_BAD_REQUEST;
-        }
-        HFile file;
-        if (file.open(filepath, "wb") != 0) {
-            return HTTP_STATUS_INTERNAL_SERVER_ERROR;
-        }
-        file.write(formdata.content.data(), formdata.content.size());
-        return 200;
-    }
 };
 
 #define DEFAULT_USER_AGENT "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"