Skip to content

Commit 34dfd48

Browse files
author
hewei.it
committed
show httpbin.org/get
1 parent 790ef1a commit 34dfd48

File tree

5 files changed

+37
-0
lines changed

5 files changed

+37
-0
lines changed

README-CN.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ int main() {
108108
return resp->Json(router.Paths());
109109
});
110110

111+
router.GET("/get", [](HttpRequest* req, HttpResponse* resp) {
112+
resp->json["origin"] = req->client_addr.ip;
113+
resp->json["url"] = req->url;
114+
resp->json["args"] = req->query_params;
115+
resp->json["headers"] = req->headers;
116+
return 200;
117+
});
118+
111119
router.POST("/echo", [](HttpRequest* req, HttpResponse* resp) {
112120
resp->content_type = req->content_type;
113121
resp->body = req->body;

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ int main() {
106106
return resp->Json(router.Paths());
107107
});
108108

109+
router.GET("/get", [](HttpRequest* req, HttpResponse* resp) {
110+
resp->json["origin"] = req->client_addr.ip;
111+
resp->json["url"] = req->url;
112+
resp->json["args"] = req->query_params;
113+
resp->json["headers"] = req->headers;
114+
return 200;
115+
});
116+
109117
router.POST("/echo", [](HttpRequest* req, HttpResponse* resp) {
110118
resp->content_type = req->content_type;
111119
resp->body = req->body;

examples/http_server_test.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ int main() {
3939
return resp->Json(router.Paths());
4040
});
4141

42+
router.GET("/get", [](HttpRequest* req, HttpResponse* resp) {
43+
resp->json["origin"] = req->client_addr.ip;
44+
resp->json["url"] = req->url;
45+
resp->json["args"] = req->query_params;
46+
resp->json["headers"] = req->headers;
47+
return 200;
48+
});
49+
4250
router.POST("/echo", [](HttpRequest* req, HttpResponse* resp) {
4351
resp->content_type = req->content_type;
4452
resp->body = req->body;

examples/httpd/router.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ class Router {
3636
return resp->Json(router.Paths());
3737
});
3838

39+
// curl -v http://ip:port/get?env=1
40+
router.GET("/get", [](HttpRequest* req, HttpResponse* resp) {
41+
resp->json["origin"] = req->client_addr.ip;
42+
resp->json["url"] = req->url;
43+
resp->json["args"] = req->query_params;
44+
resp->json["headers"] = req->headers;
45+
return 200;
46+
});
47+
3948
// curl -v http://ip:port/echo -d "hello,world!"
4049
router.POST("/echo", [](HttpRequest* req, HttpResponse* resp) {
4150
resp->content_type = req->content_type;

getting_started.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ cmd="bin/curl -v localhost:8080/data" && run_cmd
4343

4444
cmd="bin/curl -v localhost:8080/html/index.html" && run_cmd
4545

46+
cmd="bin/curl -v localhost:8080/get?env=1" && run_cmd
47+
48+
cmd="bin/curl -v localhost:8080/wildcard/test" && run_cmd
49+
4650
cmd="bin/curl -v localhost:8080/echo -d 'hello,world!'" && echo_cmd
4751
bin/curl -v localhost:8080/echo -d 'hello,world!'
4852

0 commit comments

Comments
 (0)