ithewei 5 years ago
parent
commit
4f1876262e
6 changed files with 52 additions and 42 deletions
  1. 1 1
      README.md
  2. 1 1
      examples/hmain_test.cpp
  3. 1 1
      examples/httpd/httpd.cpp
  4. 44 36
      getting_started.sh
  5. 0 1
      html/index.html
  6. 5 2
      http/client/http_client.cpp

+ 1 - 1
README.md

@@ -4,7 +4,7 @@
 
 
 Like `libevent, libev, and libuv`,
 Like `libevent, libev, and libuv`,
 `libhv` provides event-loop with non-blocking IO and timer,
 `libhv` provides event-loop with non-blocking IO and timer,
-but simpler apis and richer protocols.
+but simpler api and richer protocols.
 
 
 ## Features
 ## Features
 
 

+ 1 - 1
examples/hmain_test.cpp

@@ -41,7 +41,7 @@ static const char detail_options[] = R"(
   -h|--help                 Print this information
   -h|--help                 Print this information
   -v|--version              Print version
   -v|--version              Print version
   -c|--confile <confile>    Set configure file, default etc/{program}.conf
   -c|--confile <confile>    Set configure file, default etc/{program}.conf
-  -t|--test                 Test Configure file and exit
+  -t|--test                 Test configure file and exit
   -s|--signal <signal>      Send <signal> to process,
   -s|--signal <signal>      Send <signal> to process,
                             <signal>=[start,stop,restart,status,reload]
                             <signal>=[start,stop,restart,status,reload]
   -d|--daemon               Daemonize
   -d|--daemon               Daemonize

+ 1 - 1
examples/httpd/httpd.cpp

@@ -30,7 +30,7 @@ static const char detail_options[] = R"(
   -h|--help                 Print this information
   -h|--help                 Print this information
   -v|--version              Print version
   -v|--version              Print version
   -c|--confile <confile>    Set configure file, default etc/{program}.conf
   -c|--confile <confile>    Set configure file, default etc/{program}.conf
-  -t|--test                 Test Configure file and exit
+  -t|--test                 Test configure file and exit
   -s|--signal <signal>      Send <signal> to process,
   -s|--signal <signal>      Send <signal> to process,
                             <signal>=[start,stop,restart,status,reload]
                             <signal>=[start,stop,restart,status,reload]
   -d|--daemon               Daemonize
   -d|--daemon               Daemonize

+ 44 - 36
getting_started.sh

@@ -1,63 +1,71 @@
 #!/bin/bash
 #!/bin/bash
 
 
+echo "Welcome to libhv!"
+echo "Press any key to run ..."
+
+# run curl
+echo_cmd() {
+    echo -e "\n\033[36m$cmd\033[0m"
+    read -n1
+}
+
+run_cmd() {
+    echo_cmd
+    $cmd
+}
+
+# compile httpd curl
 if [ ! -x bin/httpd -o ! -x bin/curl ]; then
 if [ ! -x bin/httpd -o ! -x bin/curl ]; then
+    cmd="make httpd curl" && echo_cmd
+    ./configure
     make clean
     make clean
-    make httpd curl
+    make -j4 httpd curl
 fi
 fi
 
 
+# run httpd
 processes=$(ps aux | grep -v grep | grep httpd | wc -l)
 processes=$(ps aux | grep -v grep | grep httpd | wc -l)
 if [ $processes -lt 1 ]; then
 if [ $processes -lt 1 ]; then
-    bin/httpd -s restart -d
+    cmd="bin/httpd -c etc/httpd.conf -s restart -d" && run_cmd
 fi
 fi
-ps aux | grep httpd
-
-PS4="\033[32m+ \033[0m"
-set -x
+ps aux | grep -v grep | grep httpd
 
 
 # http web service
 # http web service
-read -n1
-bin/curl -v localhost:8080
+cmd="bin/curl -v localhost:8080" && run_cmd
 
 
 # http indexof service
 # http indexof service
-read -n1
-bin/curl -v localhost:8080/downloads/
+cmd="bin/curl -v localhost:8080/downloads/" && run_cmd
 
 
 # http api service
 # http api service
-read -n1
-bin/curl -v localhost:8080/ping
+cmd="bin/curl -v localhost:8080/ping" && run_cmd
 
 
-read -n1
-bin/curl -v localhost:8080/echo -d "hello,world!"
+cmd="bin/curl -v localhost:8080/echo -d 'hello,world!'" && echo_cmd
+bin/curl -v localhost:8080/echo -d 'hello,world!'
 
 
-read -n1
-bin/curl -v localhost:8080/query?page_no=1\&page_size=10
+cmd="bin/curl -v localhost:8080/query?page_no=1&page_size=10" && run_cmd
 
 
-read -n1
-bin/curl -v localhost:8080/kv   -H "Content-Type:application/x-www-form-urlencoded" -d 'user=admin&pswd=123456'
+cmd="bin/curl -v localhost:8080/kv   -H 'Content-Type:application/x-www-form-urlencoded' -d 'user=admin&pswd=123456'" && echo_cmd
+     bin/curl -v localhost:8080/kv   -H 'Content-Type:application/x-www-form-urlencoded' -d 'user=admin&pswd=123456'
 
 
-read -n1
-bin/curl -v localhost:8080/json -H "Content-Type:application/json" -d '{"user":"admin","pswd":"123456"}'
+cmd="bin/curl -v localhost:8080/json -H 'Content-Type:application/json' -d '{\"user\":\"admin\",\"pswd\":\"123456\"}'" && echo_cmd
+     bin/curl -v localhost:8080/json -H 'Content-Type:application/json' -d '{"user":"admin","pswd":"123456"}'
 
 
-read -n1
-bin/curl -v localhost:8080/form -F "user=admin pswd=123456"
+cmd="bin/curl -v localhost:8080/form -F 'user=admin pswd=123456'" && echo_cmd
+     bin/curl -v localhost:8080/form -F 'user=admin pswd=123456'
 
 
-read -n1
-bin/curl -v localhost:8080/upload -F "file=@LICENSE"
+cmd="bin/curl -v localhost:8080/upload -F 'file=@LICENSE'" && echo_cmd
+     bin/curl -v localhost:8080/upload -F 'file=@LICENSE'
 
 
-read -n1
-bin/curl -v localhost:8080/test -H "Content-Type:application/x-www-form-urlencoded" -d 'bool=1&int=123&float=3.14&string=hello'
+cmd="bin/curl -v localhost:8080/test -H 'Content-Type:application/x-www-form-urlencoded' -d 'bool=1&int=123&float=3.14&string=hello'" && echo_cmd
+     bin/curl -v localhost:8080/test -H 'Content-Type:application/x-www-form-urlencoded' -d 'bool=1&int=123&float=3.14&string=hello'
 
 
-read -n1
-bin/curl -v localhost:8080/test -H "Content-Type:application/json" -d '{"bool":true,"int":123,"float":3.14,"string":"hello"}'
+cmd="bin/curl -v localhost:8080/test -H 'Content-Type:application/json' -d '{\"bool\":true,\"int\":123,\"float\":3.14,\"string\":\"hello\"}'" && echo_cmd
+     bin/curl -v localhost:8080/test -H 'Content-Type:application/json' -d '{"bool":true,"int":123,"float":3.14,"string":"hello"}'
 
 
-read -n1
-bin/curl -v localhost:8080/test -F 'bool=1 int=123 float=3.14 string=hello'
+cmd="bin/curl -v localhost:8080/test -F 'bool=1 int=123 float=3.14 string=hello'" && echo_cmd
+     bin/curl -v localhost:8080/test -F 'bool=1 int=123 float=3.14 string=hello'
 
 
 # RESTful API: /group/:group_name/user/:user_id
 # RESTful API: /group/:group_name/user/:user_id
-read -n1
-bin/curl -v -X DELETE localhost:8080/group/test/user/123
-
-# see logs
-read -n1
-tail -n 100 logs/httpd*.log
+cmd="bin/curl -v -X DELETE localhost:8080/group/test/user/123" && run_cmd
 
 
+# show log
+cmd="tail -n 100 logs/httpd*.log" && run_cmd

+ 0 - 1
html/index.html

@@ -7,4 +7,3 @@
   <center><h1>Welcome to httpd!</h1></center>
   <center><h1>Welcome to httpd!</h1></center>
 </body>
 </body>
 </html>
 </html>
-

+ 5 - 2
http/client/http_client.cpp

@@ -196,9 +196,12 @@ int __http_client_send(http_client_t* cli, HttpRequest* req, HttpResponse* res)
 
 
     // http2
     // http2
     if (req->http_major == 2) {
     if (req->http_major == 2) {
-        //curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, (long)CURL_HTTP_VERSION_2_0);
-        //No Connection: Upgrade
+#if LIBCURL_VERSION_NUM < 0x073100 // 7.49.0
+        curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, (long)CURL_HTTP_VERSION_2_0);
+#else
+        // No Connection: Upgrade
         curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, (long)CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE);
         curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, (long)CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE);
+#endif
     }
     }
 
 
     // TCP_NODELAY
     // TCP_NODELAY