1
0
ithewei 4 жил өмнө
parent
commit
d3d0fb0eb0
3 өөрчлөгдсөн 10 нэмэгдсэн , 11 устгасан
  1. 1 1
      README-CN.md
  2. 1 1
      README.md
  3. 8 9
      http/HttpMessage.cpp

+ 1 - 1
README-CN.md

@@ -195,7 +195,7 @@ int main() {
     const char host[] = "127.0.0.1";
     int port = 1234;
     hloop_t* loop = hloop_new(0);
-    hio_t* io = hio_create_socket(hloop, host, port, HIO_TYPE_TCP, HIO_CLIENT_SIDE);
+    hio_t* io = hio_create_socket(loop, host, port, HIO_TYPE_TCP, HIO_CLIENT_SIDE);
     if (io == NULL) {
         perror("socket");
         exit(1);

+ 1 - 1
README.md

@@ -192,7 +192,7 @@ int main() {
     const char host[] = "127.0.0.1";
     int port = 1234;
     hloop_t* loop = hloop_new(0);
-    hio_t* io = hio_create_socket(hloop, host, port, HIO_TYPE_TCP, HIO_CLIENT_SIDE);
+    hio_t* io = hio_create_socket(loop, host, port, HIO_TYPE_TCP, HIO_CLIENT_SIDE);
     if (io == NULL) {
         perror("socket");
         exit(1);

+ 8 - 9
http/HttpMessage.cpp

@@ -460,16 +460,15 @@ std::string HttpMessage::Dump(bool is_dump_headers, bool is_dump_body) {
 }
 
 void HttpRequest::DumpUrl() {
+    std::string str;
     if (url.size() != 0 && strstr(url.c_str(), "://") != NULL) {
         // have been complete url
-        return;
+        goto query;
     }
-    std::string str;
     // scheme://
     str = scheme;
     str += "://";
     // host:port
-    char c_str[256] = {0};
     if (url.size() != 0 && *url.c_str() != '/') {
         // url begin with host
         str += url;
@@ -481,8 +480,7 @@ void HttpRequest::DumpUrl() {
             str += Host();
         }
         else {
-            snprintf(c_str, sizeof(c_str), "%s:%d", host.c_str(), port);
-            str += c_str;
+            str += hv::asprintf("%s:%d", host.c_str(), port);
         }
     }
     // /path
@@ -496,13 +494,14 @@ void HttpRequest::DumpUrl() {
     else if (url.size() == 0) {
         str += '/';
     }
+    url = str;
+query:
     // ?query
-    if (strchr(str.c_str(), '?') == NULL &&
+    if (strchr(url.c_str(), '?') == NULL &&
         query_params.size() != 0) {
-        str += '?';
-        str += dump_query_params(query_params);
+        url += '?';
+        url += dump_query_params(query_params);
     }
-    url = str;
 }
 
 void HttpRequest::ParseUrl() {