Procházet zdrojové kódy

show httpbin.org/get

hewei.it před 4 roky
rodič
revize
34dfd487c2
5 změnil soubory, kde provedl 37 přidání a 0 odebrání
  1. 8 0
      README-CN.md
  2. 8 0
      README.md
  3. 8 0
      examples/http_server_test.cpp
  4. 9 0
      examples/httpd/router.h
  5. 4 0
      getting_started.sh

+ 8 - 0
README-CN.md

@@ -108,6 +108,14 @@ int main() {
         return resp->Json(router.Paths());
     });
 
+    router.GET("/get", [](HttpRequest* req, HttpResponse* resp) {
+        resp->json["origin"] = req->client_addr.ip;
+        resp->json["url"] = req->url;
+        resp->json["args"] = req->query_params;
+        resp->json["headers"] = req->headers;
+        return 200;
+    });
+
     router.POST("/echo", [](HttpRequest* req, HttpResponse* resp) {
         resp->content_type = req->content_type;
         resp->body = req->body;

+ 8 - 0
README.md

@@ -106,6 +106,14 @@ int main() {
         return resp->Json(router.Paths());
     });
 
+    router.GET("/get", [](HttpRequest* req, HttpResponse* resp) {
+        resp->json["origin"] = req->client_addr.ip;
+        resp->json["url"] = req->url;
+        resp->json["args"] = req->query_params;
+        resp->json["headers"] = req->headers;
+        return 200;
+    });
+
     router.POST("/echo", [](HttpRequest* req, HttpResponse* resp) {
         resp->content_type = req->content_type;
         resp->body = req->body;

+ 8 - 0
examples/http_server_test.cpp

@@ -39,6 +39,14 @@ int main() {
         return resp->Json(router.Paths());
     });
 
+    router.GET("/get", [](HttpRequest* req, HttpResponse* resp) {
+        resp->json["origin"] = req->client_addr.ip;
+        resp->json["url"] = req->url;
+        resp->json["args"] = req->query_params;
+        resp->json["headers"] = req->headers;
+        return 200;
+    });
+
     router.POST("/echo", [](HttpRequest* req, HttpResponse* resp) {
         resp->content_type = req->content_type;
         resp->body = req->body;

+ 9 - 0
examples/httpd/router.h

@@ -36,6 +36,15 @@ public:
             return resp->Json(router.Paths());
         });
 
+        // curl -v http://ip:port/get?env=1
+        router.GET("/get", [](HttpRequest* req, HttpResponse* resp) {
+            resp->json["origin"] = req->client_addr.ip;
+            resp->json["url"] = req->url;
+            resp->json["args"] = req->query_params;
+            resp->json["headers"] = req->headers;
+            return 200;
+        });
+
         // curl -v http://ip:port/echo -d "hello,world!"
         router.POST("/echo", [](HttpRequest* req, HttpResponse* resp) {
             resp->content_type = req->content_type;

+ 4 - 0
getting_started.sh

@@ -43,6 +43,10 @@ cmd="bin/curl -v localhost:8080/data" && run_cmd
 
 cmd="bin/curl -v localhost:8080/html/index.html" && run_cmd
 
+cmd="bin/curl -v localhost:8080/get?env=1" && run_cmd
+
+cmd="bin/curl -v localhost:8080/wildcard/test" && run_cmd
+
 cmd="bin/curl -v localhost:8080/echo -d 'hello,world!'" && echo_cmd
 bin/curl -v localhost:8080/echo -d 'hello,world!'