ithewei 4 anni fa
parent
commit
8fa05c1787
2 ha cambiato i file con 6 aggiunte e 2 eliminazioni
  1. 3 0
      cpputil/hfile.h
  2. 3 2
      http/HttpMessage.h

+ 3 - 0
cpputil/hfile.h

@@ -71,12 +71,14 @@ public:
 
     size_t readall(HBuf& buf) {
         size_t filesize = size();
+        if (filesize == 0) return 0;
         buf.resize(filesize);
         return fread(buf.base, 1, filesize, fp);
     }
 
     size_t readall(std::string& str) {
         size_t filesize = size();
+        if (filesize == 0) return 0;
         str.resize(filesize);
         return fread((void*)str.data(), 1, filesize, fp);
     }
@@ -105,6 +107,7 @@ public:
 
     int readrange(std::string& str, size_t from = 0, size_t to = 0) {
         size_t filesize = size();
+        if (filesize == 0) return 0;
         if (to == 0 || to >= filesize) to = filesize - 1;
         size_t readbytes = to - from + 1;
         str.resize(readbytes);

+ 3 - 2
http/HttpMessage.h

@@ -445,8 +445,9 @@ public:
     }
 
     // ?query_params
-    void SetParam(const char* key, const std::string& value) {
-        query_params[key] = value;
+    template<typename T>
+    void SetParam(const char* key, const T& t) {
+        query_params[key] = hv::to_string(t);
     }
     std::string GetParam(const char* key, const std::string& defvalue = "") {
         auto iter = query_params.find(key);