diff --git a/net/ghttp/ghttp_unit_client_dump_test.go b/net/ghttp/ghttp_unit_client_dump_test.go
index 260f031a0..0bb505759 100644
--- a/net/ghttp/ghttp_unit_client_dump_test.go
+++ b/net/ghttp/ghttp_unit_client_dump_test.go
@@ -36,7 +36,7 @@ func Test_Client_Request_13_Dump(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
url := fmt.Sprintf("http://127.0.0.1:%d", p)
- client := ghttp.NewClient().SetPrefix(url).ContentJson()
+ client := g.Client().SetPrefix(url).ContentJson()
r, err := client.Post("/hello", g.Map{"field": "test_for_request_body"})
t.Assert(err, nil)
dumpedText := r.RawRequest()
@@ -45,7 +45,7 @@ func Test_Client_Request_13_Dump(t *testing.T) {
fmt.Println(dumpedText2)
t.Assert(gstr.Contains(dumpedText2, "test_for_response_body"), true)
- client2 := ghttp.NewClient().SetPrefix(url).ContentType("text/html")
+ client2 := g.Client().SetPrefix(url).ContentType("text/html")
r2, err := client2.Post("/hello2", g.Map{"field": "test_for_request_body"})
t.Assert(err, nil)
dumpedText3 := r2.RawRequest()
diff --git a/net/ghttp/ghttp_unit_client_test.go b/net/ghttp/ghttp_unit_client_test.go
index ef159e5e5..e48340209 100644
--- a/net/ghttp/ghttp_unit_client_test.go
+++ b/net/ghttp/ghttp_unit_client_test.go
@@ -34,7 +34,7 @@ func Test_Client_Basic(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
url := fmt.Sprintf("http://127.0.0.1:%d", p)
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(url)
t.Assert(ghttp.GetContent(""), ``)
@@ -82,7 +82,7 @@ func Test_Client_Cookie(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- c := ghttp.NewClient()
+ c := g.Client()
c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
c.SetCookie("test", "0123456789")
@@ -103,7 +103,7 @@ func Test_Client_MapParam(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- c := ghttp.NewClient()
+ c := g.Client()
c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(c.GetContent("/map", g.Map{"test": "1234567890"}), "1234567890")
@@ -125,7 +125,7 @@ func Test_Client_Cookies(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- c := ghttp.NewClient()
+ c := g.Client()
c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
resp, err := c.Get("/cookie")
@@ -159,7 +159,7 @@ func Test_Client_Chain_Header(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- c := ghttp.NewClient()
+ c := g.Client()
c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(c.Header(g.MapStrStr{"test1": "1234567890"}).GetContent("/header1"), "1234567890")
@@ -182,7 +182,7 @@ func Test_Client_Chain_Context(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- c := ghttp.NewClient()
+ c := g.Client()
c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
ctx, _ := context.WithTimeout(context.Background(), 100*time.Millisecond)
@@ -207,7 +207,7 @@ func Test_Client_Chain_Timeout(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- c := ghttp.NewClient()
+ c := g.Client()
c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(c.Timeout(100*time.Millisecond).GetContent("/timeout"), "")
t.Assert(c.Timeout(2000*time.Millisecond).GetContent("/timeout"), "ok")
@@ -227,7 +227,7 @@ func Test_Client_Chain_ContentJson(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- c := ghttp.NewClient()
+ c := g.Client()
c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(c.ContentJson().PostContent("/json", g.Map{
"name": "john",
@@ -256,7 +256,7 @@ func Test_Client_Chain_ContentXml(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- c := ghttp.NewClient()
+ c := g.Client()
c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(c.ContentXml().PostContent("/xml", g.Map{
"name": "john",
@@ -285,7 +285,7 @@ func Test_Client_Param_Containing_Special_Char(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- c := ghttp.NewClient()
+ c := g.Client()
c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(c.PostContent("/", "k1=MTIxMg==&k2=100"), "k1=MTIxMg==&k2=100")
t.Assert(c.PostContent("/", g.Map{
diff --git a/net/ghttp/ghttp_unit_context_test.go b/net/ghttp/ghttp_unit_context_test.go
index 8caab6091..86be300aa 100644
--- a/net/ghttp/ghttp_unit_context_test.go
+++ b/net/ghttp/ghttp_unit_context_test.go
@@ -35,7 +35,7 @@ func Test_Context(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), `123`)
diff --git a/net/ghttp/ghttp_unit_cookie_test.go b/net/ghttp/ghttp_unit_cookie_test.go
index 5b695eef9..83262b739 100644
--- a/net/ghttp/ghttp_unit_cookie_test.go
+++ b/net/ghttp/ghttp_unit_cookie_test.go
@@ -36,7 +36,7 @@ func Test_Cookie(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetBrowserMode(true)
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
r1, e1 := client.Get("/set?k=key1&v=100")
@@ -82,7 +82,7 @@ func Test_SetHttpCookie(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetBrowserMode(true)
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
r1, e1 := client.Get("/set?k=key1&v=100")
diff --git a/net/ghttp/ghttp_unit_ip_test.go b/net/ghttp/ghttp_unit_ip_test.go
index d94ff6d59..6d8f851ee 100644
--- a/net/ghttp/ghttp_unit_ip_test.go
+++ b/net/ghttp/ghttp_unit_ip_test.go
@@ -32,7 +32,7 @@ func TestRequest_GetRemoteIp(t *testing.T) {
time.Sleep(100 * time.Millisecond)
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "127.0.0.1")
diff --git a/net/ghttp/ghttp_unit_log_test.go b/net/ghttp/ghttp_unit_log_test.go
index 3511a97e7..28d1ed428 100644
--- a/net/ghttp/ghttp_unit_log_test.go
+++ b/net/ghttp/ghttp_unit_log_test.go
@@ -41,7 +41,7 @@ func Test_Log(t *testing.T) {
defer s.Shutdown()
defer gfile.Remove(logDir)
time.Sleep(100 * time.Millisecond)
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/hello"), "hello")
diff --git a/net/ghttp/ghttp_unit_mess_test.go b/net/ghttp/ghttp_unit_mess_test.go
index b9d4e678f..563d61dcf 100644
--- a/net/ghttp/ghttp_unit_mess_test.go
+++ b/net/ghttp/ghttp_unit_mess_test.go
@@ -30,7 +30,7 @@ func Test_GetUrl(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
prefix := fmt.Sprintf("http://127.0.0.1:%d", p)
- client := ghttp.NewClient()
+ client := g.Client()
client.SetBrowserMode(true)
client.SetPrefix(prefix)
diff --git a/net/ghttp/ghttp_unit_middleware_basic_test.go b/net/ghttp/ghttp_unit_middleware_basic_test.go
index 3a3ff45a3..7e72bff49 100644
--- a/net/ghttp/ghttp_unit_middleware_basic_test.go
+++ b/net/ghttp/ghttp_unit_middleware_basic_test.go
@@ -50,7 +50,7 @@ func Test_BindMiddleware_Basic1(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "Not Found")
@@ -77,7 +77,7 @@ func Test_BindMiddleware_Basic2(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "12")
@@ -117,7 +117,7 @@ func Test_BindMiddleware_Basic3(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "Not Found")
@@ -153,7 +153,7 @@ func Test_BindMiddleware_Basic4(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "Not Found")
@@ -182,7 +182,7 @@ func Test_Middleware_With_Static(t *testing.T) {
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "index")
@@ -210,7 +210,7 @@ func Test_Middleware_Status(t *testing.T) {
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "Not Found")
@@ -254,7 +254,7 @@ func Test_Middleware_Hook_With_Static(t *testing.T) {
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
// The length assert sometimes fails, so I added time.Sleep here for debug purpose.
@@ -293,7 +293,7 @@ func Test_BindMiddleware_Status(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "Not Found")
@@ -326,7 +326,7 @@ func Test_BindMiddlewareDefault_Basic1(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "1342")
@@ -357,7 +357,7 @@ func Test_BindMiddlewareDefault_Basic2(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "1342")
@@ -388,7 +388,7 @@ func Test_BindMiddlewareDefault_Basic3(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "12")
@@ -417,7 +417,7 @@ func Test_BindMiddlewareDefault_Basic4(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "21")
@@ -446,7 +446,7 @@ func Test_BindMiddlewareDefault_Basic5(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "12")
@@ -470,7 +470,7 @@ func Test_BindMiddlewareDefault_Status(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "Not Found")
@@ -521,7 +521,7 @@ func Test_BindMiddlewareDefault_Basic6(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "13100Object Index20042")
@@ -568,7 +568,7 @@ func Test_Hook_Middleware_Basic1(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "ac1342bd")
@@ -606,7 +606,7 @@ func Test_Middleware_CORSAndAuth(t *testing.T) {
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
// Common Checks.
t.Assert(client.GetContent("/"), "Not Found")
@@ -671,7 +671,7 @@ func Test_Middleware_Scope(t *testing.T) {
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "Not Found")
@@ -706,7 +706,7 @@ func Test_Middleware_Panic(t *testing.T) {
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "error")
diff --git a/net/ghttp/ghttp_unit_middleware_cors_test.go b/net/ghttp/ghttp_unit_middleware_cors_test.go
index 10dd657d6..117d51623 100644
--- a/net/ghttp/ghttp_unit_middleware_cors_test.go
+++ b/net/ghttp/ghttp_unit_middleware_cors_test.go
@@ -30,7 +30,7 @@ func Test_Middleware_CORS1(t *testing.T) {
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
// Common Checks.
t.Assert(client.GetContent("/"), "Not Found")
@@ -55,7 +55,7 @@ func Test_Middleware_CORS1(t *testing.T) {
})
// OPTIONS GET
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
client.SetHeader("Access-Control-Request-Method", "GET")
resp, err := client.Options("/api.v2/user/list")
@@ -67,7 +67,7 @@ func Test_Middleware_CORS1(t *testing.T) {
})
// OPTIONS POST
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
client.SetHeader("Access-Control-Request-Method", "POST")
resp, err := client.Options("/api.v2/user/list")
@@ -93,7 +93,7 @@ func Test_Middleware_CORS2(t *testing.T) {
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
// Common Checks.
t.Assert(client.GetContent("/"), "Not Found")
@@ -111,7 +111,7 @@ func Test_Middleware_CORS2(t *testing.T) {
})
// OPTIONS GET None.
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
client.SetHeader("Access-Control-Request-Method", "GET")
resp, err := client.Options("/api.v2/user")
@@ -122,7 +122,7 @@ func Test_Middleware_CORS2(t *testing.T) {
})
// OPTIONS GET
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
client.SetHeader("Access-Control-Request-Method", "GET")
resp, err := client.Options("/api.v2/user/list/1")
@@ -133,7 +133,7 @@ func Test_Middleware_CORS2(t *testing.T) {
})
// OPTIONS POST
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
client.SetHeader("Access-Control-Request-Method", "POST")
resp, err := client.Options("/api.v2/user/list/1")
diff --git a/net/ghttp/ghttp_unit_param_file_test.go b/net/ghttp/ghttp_unit_param_file_test.go
index 00ff39d93..0e068d824 100644
--- a/net/ghttp/ghttp_unit_param_file_test.go
+++ b/net/ghttp/ghttp_unit_param_file_test.go
@@ -42,7 +42,7 @@ func Test_Params_File_Single(t *testing.T) {
time.Sleep(100 * time.Millisecond)
// normal name
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
srcPath := gdebug.TestDataPath("upload", "file1.txt")
@@ -58,7 +58,7 @@ func Test_Params_File_Single(t *testing.T) {
})
// randomly rename.
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
srcPath := gdebug.TestDataPath("upload", "file2.txt")
@@ -95,7 +95,7 @@ func Test_Params_File_CustomName(t *testing.T) {
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
srcPath := gdebug.TestDataPath("upload", "file1.txt")
@@ -132,7 +132,7 @@ func Test_Params_File_Batch(t *testing.T) {
time.Sleep(100 * time.Millisecond)
// normal name
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
srcPath1 := gdebug.TestDataPath("upload", "file1.txt")
@@ -152,7 +152,7 @@ func Test_Params_File_Batch(t *testing.T) {
})
// randomly rename.
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
srcPath1 := gdebug.TestDataPath("upload", "file1.txt")
diff --git a/net/ghttp/ghttp_unit_param_json_test.go b/net/ghttp/ghttp_unit_param_json_test.go
index 9a194bcc0..596175b0e 100644
--- a/net/ghttp/ghttp_unit_param_json_test.go
+++ b/net/ghttp/ghttp_unit_param_json_test.go
@@ -51,7 +51,7 @@ func Test_Params_Json_Request(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/get", `{"id":1,"name":"john","password1":"123Abc!@#","password2":"123Abc!@#"}`), ``)
@@ -140,7 +140,7 @@ func Test_Params_Json_Response(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
map1 := make(map[string]interface{})
diff --git a/net/ghttp/ghttp_unit_param_page_test.go b/net/ghttp/ghttp_unit_param_page_test.go
index b9917ea7d..046f0b6ce 100644
--- a/net/ghttp/ghttp_unit_param_page_test.go
+++ b/net/ghttp/ghttp_unit_param_page_test.go
@@ -36,7 +36,7 @@ func Test_Params_Page(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/list"), `首页上一页123下一页尾页`)
diff --git a/net/ghttp/ghttp_unit_param_struct_test.go b/net/ghttp/ghttp_unit_param_struct_test.go
index 92114225e..4961ff4c4 100644
--- a/net/ghttp/ghttp_unit_param_struct_test.go
+++ b/net/ghttp/ghttp_unit_param_struct_test.go
@@ -322,7 +322,7 @@ func Test_Params_Parse_Attr_Pointer1(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.PostContent("/parse1", `{"id":1,"name":"john"}`), `1john`)
t.Assert(client.PostContent("/parse2", `{"id":1,"name":"john"}`), `1john`)
@@ -351,7 +351,7 @@ func Test_Params_Parse_Attr_Pointer2(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.PostContent("/parse"), `The Id field is required`)
t.Assert(client.PostContent("/parse?id=1"), `1`)
@@ -383,7 +383,7 @@ func Test_Params_Parse_Attr_Pointer2(t *testing.T) {
//
// time.Sleep(100 * time.Millisecond)
// gtest.C(t, func(t *gtest.T) {
-// client := ghttp.NewClient()
+// client := g.Client()
// client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
// t.Assert(client.PostContent("/parse", `{"id":1,"name":"john","scores":[[1,2,3]]}`), `1100`)
// })
@@ -446,7 +446,7 @@ func Test_Params_Struct(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/struct1", `id=1&name=john&password1=123&password2=456`), `1john123456`)
t.Assert(client.PostContent("/struct1", `id=1&name=john&password1=123&password2=456`), `1john123456`)
@@ -482,7 +482,7 @@ func Test_Params_Structs(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.PostContent(
"/parse1",
diff --git a/net/ghttp/ghttp_unit_param_test.go b/net/ghttp/ghttp_unit_param_test.go
index 6e7d468b4..f6a2dd1f1 100644
--- a/net/ghttp/ghttp_unit_param_test.go
+++ b/net/ghttp/ghttp_unit_param_test.go
@@ -298,7 +298,7 @@ func Test_Params_Basic(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
// GET
t.Assert(client.GetContent("/get", "array[]=1&array[]=2"), `["1","2"]`)
@@ -422,7 +422,7 @@ func Test_Params_Header(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
prefix := fmt.Sprintf("http://127.0.0.1:%d", p)
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(prefix)
t.Assert(client.Header(g.MapStrStr{"test": "123456"}).GetContent("/header"), "123456")
@@ -481,7 +481,7 @@ func Test_Params_Priority(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
prefix := fmt.Sprintf("http://127.0.0.1:%d", p)
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(prefix)
t.Assert(client.GetContent("/query?a=1", "a=100"), "100")
@@ -507,7 +507,7 @@ func Test_Params_GetRequestMap(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
prefix := fmt.Sprintf("http://127.0.0.1:%d", p)
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(prefix)
t.Assert(
@@ -543,7 +543,7 @@ func Test_Params_Modify(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
prefix := fmt.Sprintf("http://127.0.0.1:%d", p)
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(prefix)
t.Assert(
diff --git a/net/ghttp/ghttp_unit_param_xml_test.go b/net/ghttp/ghttp_unit_param_xml_test.go
index dbf58317c..bd6d2bfab 100644
--- a/net/ghttp/ghttp_unit_param_xml_test.go
+++ b/net/ghttp/ghttp_unit_param_xml_test.go
@@ -50,7 +50,7 @@ func Test_Params_Xml_Request(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
content1 := `1john123Abc!@#123Abc!@#`
diff --git a/net/ghttp/ghttp_unit_pprof_test.go b/net/ghttp/ghttp_unit_pprof_test.go
index ca22ef250..2b3c96b66 100644
--- a/net/ghttp/ghttp_unit_pprof_test.go
+++ b/net/ghttp/ghttp_unit_pprof_test.go
@@ -14,7 +14,6 @@ import (
"time"
"github.com/gogf/gf/frame/g"
- "github.com/gogf/gf/net/ghttp"
. "github.com/gogf/gf/test/gtest"
)
@@ -28,7 +27,7 @@ func TestServer_EnablePProf(t *testing.T) {
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
r, err := client.Get("/pprof/index")
diff --git a/net/ghttp/ghttp_unit_router_basic_test.go b/net/ghttp/ghttp_unit_router_basic_test.go
index ea6e5d624..89f033e7e 100644
--- a/net/ghttp/ghttp_unit_router_basic_test.go
+++ b/net/ghttp/ghttp_unit_router_basic_test.go
@@ -41,7 +41,7 @@ func Test_Router_Basic1(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/john"), "")
t.Assert(client.GetContent("/john/update"), "john")
@@ -66,7 +66,7 @@ func Test_Router_Basic2(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/data"), "data")
t.Assert(client.GetContent("/data.json"), "json")
@@ -92,7 +92,7 @@ func Test_Router_Value(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/data"), "data")
t.Assert(client.GetContent("/data.json"), "json")
@@ -117,7 +117,7 @@ func Test_Router_Method(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
resp1, err := client.Get("/get")
@@ -158,7 +158,7 @@ func Test_Router_ExtraChar(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/api/test"), "test")
@@ -193,7 +193,7 @@ func Test_Router_Status(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
resp1, err := client.Get("/200")
@@ -239,7 +239,7 @@ func Test_Router_CustomStatusHandler(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "hello")
@@ -265,7 +265,7 @@ func Test_Router_404(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "hello")
@@ -298,7 +298,7 @@ func Test_Router_Priority(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/admin"), "admin")
diff --git a/net/ghttp/ghttp_unit_router_controller_rest_test.go b/net/ghttp/ghttp_unit_router_controller_rest_test.go
index 552bc8904..fae4aff4c 100644
--- a/net/ghttp/ghttp_unit_router_controller_rest_test.go
+++ b/net/ghttp/ghttp_unit_router_controller_rest_test.go
@@ -63,7 +63,7 @@ func Test_Router_ControllerRest(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "1Controller Get2")
diff --git a/net/ghttp/ghttp_unit_router_controller_test.go b/net/ghttp/ghttp_unit_router_controller_test.go
index 60f4fea09..2c01a8876 100644
--- a/net/ghttp/ghttp_unit_router_controller_test.go
+++ b/net/ghttp/ghttp_unit_router_controller_test.go
@@ -55,7 +55,7 @@ func Test_Router_Controller1(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "1Controller Index2")
@@ -85,7 +85,7 @@ func Test_Router_Controller2(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "Not Found")
@@ -111,7 +111,7 @@ func Test_Router_ControllerMethod(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "Not Found")
diff --git a/net/ghttp/ghttp_unit_router_domain_basic_test.go b/net/ghttp/ghttp_unit_router_domain_basic_test.go
index a2a1d2208..eef7df82a 100644
--- a/net/ghttp/ghttp_unit_router_domain_basic_test.go
+++ b/net/ghttp/ghttp_unit_router_domain_basic_test.go
@@ -43,7 +43,7 @@ func Test_Router_DomainBasic(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/john"), "Not Found")
t.Assert(client.GetContent("/john/update"), "Not Found")
@@ -51,7 +51,7 @@ func Test_Router_DomainBasic(t *testing.T) {
t.Assert(client.GetContent("/user/list/100.html"), "Not Found")
})
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://localhost:%d", p))
t.Assert(client.GetContent("/john"), "")
t.Assert(client.GetContent("/john/update"), "john")
@@ -59,7 +59,7 @@ func Test_Router_DomainBasic(t *testing.T) {
t.Assert(client.GetContent("/user/list/100.html"), "100")
})
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://local:%d", p))
t.Assert(client.GetContent("/john"), "")
t.Assert(client.GetContent("/john/update"), "john")
@@ -85,7 +85,7 @@ func Test_Router_DomainMethod(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
resp1, err := client.Get("/get")
@@ -110,7 +110,7 @@ func Test_Router_DomainMethod(t *testing.T) {
})
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://localhost:%d", p))
resp1, err := client.Get("/get")
@@ -135,7 +135,7 @@ func Test_Router_DomainMethod(t *testing.T) {
})
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://local:%d", p))
resp1, err := client.Get("/get")
@@ -183,7 +183,7 @@ func Test_Router_DomainStatus(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
resp1, err := client.Get("/200")
@@ -207,7 +207,7 @@ func Test_Router_DomainStatus(t *testing.T) {
t.Assert(resp4.StatusCode, 404)
})
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://localhost:%d", p))
resp1, err := client.Get("/200")
@@ -231,7 +231,7 @@ func Test_Router_DomainStatus(t *testing.T) {
t.Assert(resp4.StatusCode, 500)
})
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://local:%d", p))
resp1, err := client.Get("/200")
@@ -273,21 +273,21 @@ func Test_Router_DomainCustomStatusHandler(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "Not Found")
t.Assert(client.GetContent("/ThisDoesNotExist"), "Not Found")
})
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://localhost:%d", p))
t.Assert(client.GetContent("/"), "hello")
t.Assert(client.GetContent("/ThisDoesNotExist"), "404 page")
})
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://local:%d", p))
t.Assert(client.GetContent("/"), "hello")
@@ -309,19 +309,19 @@ func Test_Router_Domain404(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "Not Found")
})
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://localhost:%d", p))
t.Assert(client.GetContent("/"), "hello")
})
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://local:%d", p))
t.Assert(client.GetContent("/"), "hello")
@@ -355,10 +355,10 @@ func Test_Router_DomainGroup(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client1 := ghttp.NewClient()
+ client1 := g.Client()
client1.SetPrefix(fmt.Sprintf("http://local:%d", p))
- client2 := ghttp.NewClient()
+ client2 := g.Client()
client2.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client1.GetContent("/app/t/list/2.html"), "t&2")
diff --git a/net/ghttp/ghttp_unit_router_domain_controller_rest_test.go b/net/ghttp/ghttp_unit_router_domain_controller_rest_test.go
index 585785ea1..f01c7abe0 100644
--- a/net/ghttp/ghttp_unit_router_domain_controller_rest_test.go
+++ b/net/ghttp/ghttp_unit_router_domain_controller_rest_test.go
@@ -71,7 +71,7 @@ func Test_Router_DomainControllerRest(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "Not Found")
@@ -89,7 +89,7 @@ func Test_Router_DomainControllerRest(t *testing.T) {
t.Assert(client.GetContent("/none-exist"), "Not Found")
})
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://localhost:%d", p))
t.Assert(client.GetContent("/"), "1Controller Get2")
@@ -107,7 +107,7 @@ func Test_Router_DomainControllerRest(t *testing.T) {
t.Assert(client.GetContent("/none-exist"), "Not Found")
})
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://local:%d", p))
t.Assert(client.GetContent("/"), "1Controller Get2")
diff --git a/net/ghttp/ghttp_unit_router_domain_controller_test.go b/net/ghttp/ghttp_unit_router_domain_controller_test.go
index 94161175c..e9d3f0191 100644
--- a/net/ghttp/ghttp_unit_router_domain_controller_test.go
+++ b/net/ghttp/ghttp_unit_router_domain_controller_test.go
@@ -53,7 +53,7 @@ func Test_Router_DomainController1(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "Not Found")
@@ -66,7 +66,7 @@ func Test_Router_DomainController1(t *testing.T) {
})
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://localhost:%d", p))
t.Assert(client.GetContent("/"), "1Controller Index2")
@@ -79,7 +79,7 @@ func Test_Router_DomainController1(t *testing.T) {
})
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://local:%d", p))
t.Assert(client.GetContent("/"), "1Controller Index2")
@@ -103,7 +103,7 @@ func Test_Router_DomainController2(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "Not Found")
@@ -117,7 +117,7 @@ func Test_Router_DomainController2(t *testing.T) {
})
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://localhost:%d", p))
t.Assert(client.GetContent("/"), "Not Found")
@@ -131,7 +131,7 @@ func Test_Router_DomainController2(t *testing.T) {
})
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://local:%d", p))
t.Assert(client.GetContent("/"), "Not Found")
@@ -156,7 +156,7 @@ func Test_Router_DomainControllerMethod(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "Not Found")
@@ -170,7 +170,7 @@ func Test_Router_DomainControllerMethod(t *testing.T) {
t.Assert(client.GetContent("/none-exist"), "Not Found")
})
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://localhost:%d", p))
t.Assert(client.GetContent("/"), "Not Found")
@@ -184,7 +184,7 @@ func Test_Router_DomainControllerMethod(t *testing.T) {
t.Assert(client.GetContent("/none-exist"), "Not Found")
})
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://local:%d", p))
t.Assert(client.GetContent("/"), "Not Found")
diff --git a/net/ghttp/ghttp_unit_router_domain_object_rest_test.go b/net/ghttp/ghttp_unit_router_domain_object_rest_test.go
index adc5a0ed8..5d4a5cb59 100644
--- a/net/ghttp/ghttp_unit_router_domain_object_rest_test.go
+++ b/net/ghttp/ghttp_unit_router_domain_object_rest_test.go
@@ -66,7 +66,7 @@ func Test_Router_DomainObjectRest(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "Not Found")
@@ -84,7 +84,7 @@ func Test_Router_DomainObjectRest(t *testing.T) {
t.Assert(client.GetContent("/none-exist"), "Not Found")
})
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://localhost:%d", p))
t.Assert(client.GetContent("/"), "1Object Get2")
@@ -102,7 +102,7 @@ func Test_Router_DomainObjectRest(t *testing.T) {
t.Assert(client.GetContent("/none-exist"), "Not Found")
})
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://local:%d", p))
t.Assert(client.GetContent("/"), "1Object Get2")
diff --git a/net/ghttp/ghttp_unit_router_domain_object_test.go b/net/ghttp/ghttp_unit_router_domain_object_test.go
index 8cf13749d..78131fcc6 100644
--- a/net/ghttp/ghttp_unit_router_domain_object_test.go
+++ b/net/ghttp/ghttp_unit_router_domain_object_test.go
@@ -49,7 +49,7 @@ func Test_Router_DomainObject1(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "Not Found")
@@ -61,7 +61,7 @@ func Test_Router_DomainObject1(t *testing.T) {
})
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://localhost:%d", p))
t.Assert(client.GetContent("/"), "1Object Index2")
@@ -74,7 +74,7 @@ func Test_Router_DomainObject1(t *testing.T) {
})
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://local:%d", p))
t.Assert(client.GetContent("/"), "1Object Index2")
@@ -98,7 +98,7 @@ func Test_Router_DomainObject2(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "Not Found")
@@ -111,7 +111,7 @@ func Test_Router_DomainObject2(t *testing.T) {
t.Assert(client.GetContent("/none-exist"), "Not Found")
})
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://localhost:%d", p))
t.Assert(client.GetContent("/"), "Not Found")
@@ -124,7 +124,7 @@ func Test_Router_DomainObject2(t *testing.T) {
t.Assert(client.GetContent("/none-exist"), "Not Found")
})
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://local:%d", p))
t.Assert(client.GetContent("/"), "Not Found")
@@ -149,7 +149,7 @@ func Test_Router_DomainObjectMethod(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "Not Found")
@@ -163,7 +163,7 @@ func Test_Router_DomainObjectMethod(t *testing.T) {
t.Assert(client.GetContent("/none-exist"), "Not Found")
})
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://localhost:%d", p))
t.Assert(client.GetContent("/"), "Not Found")
@@ -177,7 +177,7 @@ func Test_Router_DomainObjectMethod(t *testing.T) {
t.Assert(client.GetContent("/none-exist"), "Not Found")
})
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://local:%d", p))
t.Assert(client.GetContent("/"), "Not Found")
diff --git a/net/ghttp/ghttp_unit_router_exit_test.go b/net/ghttp/ghttp_unit_router_exit_test.go
index d12dc9946..3f2faaf8d 100644
--- a/net/ghttp/ghttp_unit_router_exit_test.go
+++ b/net/ghttp/ghttp_unit_router_exit_test.go
@@ -37,7 +37,7 @@ func Test_Router_Exit(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "123")
@@ -75,7 +75,7 @@ func Test_Router_ExitHook(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "Not Found")
@@ -113,7 +113,7 @@ func Test_Router_ExitAll(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "Not Found")
diff --git a/net/ghttp/ghttp_unit_router_group_group_test.go b/net/ghttp/ghttp_unit_router_group_group_test.go
index 23545dae5..3b351262f 100644
--- a/net/ghttp/ghttp_unit_router_group_group_test.go
+++ b/net/ghttp/ghttp_unit_router_group_group_test.go
@@ -63,7 +63,7 @@ func Test_Router_Group_Group(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "Not Found")
diff --git a/net/ghttp/ghttp_unit_router_group_hook_test.go b/net/ghttp/ghttp_unit_router_group_hook_test.go
index 99e8a2e14..98be6fe41 100644
--- a/net/ghttp/ghttp_unit_router_group_hook_test.go
+++ b/net/ghttp/ghttp_unit_router_group_hook_test.go
@@ -37,7 +37,7 @@ func Test_Router_Group_Hook1(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/api/handler"), "012")
t.Assert(client.PostContent("/api/handler"), "02")
@@ -48,14 +48,14 @@ func Test_Router_Group_Hook1(t *testing.T) {
func Test_Router_Group_Hook2(t *testing.T) {
p, _ := ports.PopRand()
s := g.Server(p)
- g := s.Group("/api")
- g.GET("/handler", func(r *ghttp.Request) {
+ group := s.Group("/api")
+ group.GET("/handler", func(r *ghttp.Request) {
r.Response.Write("1")
})
- g.GET("/*", func(r *ghttp.Request) {
+ group.GET("/*", func(r *ghttp.Request) {
r.Response.Write("0")
}, ghttp.HOOK_BEFORE_SERVE)
- g.GET("/*", func(r *ghttp.Request) {
+ group.GET("/*", func(r *ghttp.Request) {
r.Response.Write("2")
}, ghttp.HOOK_AFTER_SERVE)
@@ -66,7 +66,7 @@ func Test_Router_Group_Hook2(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/api/handler"), "012")
t.Assert(client.PostContent("/api/handler"), "Not Found")
@@ -97,7 +97,7 @@ func Test_Router_Group_Hook3(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/api/handler"), "012")
t.Assert(client.PostContent("/api/handler"), "012")
diff --git a/net/ghttp/ghttp_unit_router_group_rest_test.go b/net/ghttp/ghttp_unit_router_group_rest_test.go
index 2505fef90..f4ca999eb 100644
--- a/net/ghttp/ghttp_unit_router_group_rest_test.go
+++ b/net/ghttp/ghttp_unit_router_group_rest_test.go
@@ -100,13 +100,13 @@ func (o *GroupObjRest) Head(r *ghttp.Request) {
func Test_Router_GroupRest1(t *testing.T) {
p, _ := ports.PopRand()
s := g.Server(p)
- g := s.Group("/api")
+ group := s.Group("/api")
ctl := new(GroupCtlRest)
obj := new(GroupObjRest)
- g.REST("/ctl", ctl)
- g.REST("/obj", obj)
- g.REST("/{.struct}/{.method}", ctl)
- g.REST("/{.struct}/{.method}", obj)
+ group.REST("/ctl", ctl)
+ group.REST("/obj", obj)
+ group.REST("/{.struct}/{.method}", ctl)
+ group.REST("/{.struct}/{.method}", obj)
s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
@@ -114,7 +114,7 @@ func Test_Router_GroupRest1(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/api/ctl"), "1Controller Get2")
@@ -191,7 +191,7 @@ func Test_Router_GroupRest2(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/api/ctl"), "1Controller Get2")
diff --git a/net/ghttp/ghttp_unit_router_group_test.go b/net/ghttp/ghttp_unit_router_group_test.go
index ed567dce1..76763bbf1 100644
--- a/net/ghttp/ghttp_unit_router_group_test.go
+++ b/net/ghttp/ghttp_unit_router_group_test.go
@@ -91,7 +91,7 @@ func Test_Router_GroupBasic1(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/api/handler"), "Handler")
@@ -139,7 +139,7 @@ func Test_Router_GroupBasic2(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/api/handler"), "Handler")
@@ -175,7 +175,7 @@ func Test_Router_GroupBuildInVar(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/api/group-controller/index"), "1Controller Index2")
@@ -206,7 +206,7 @@ func Test_Router_Group_Mthods(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/ctl/show"), "1Controller Show2")
t.Assert(client.GetContent("/ctl/post"), "1Controller Post2")
@@ -241,9 +241,9 @@ func Test_Router_Group_MultiServer(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- c1 := ghttp.NewClient()
+ c1 := g.Client()
c1.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p1))
- c2 := ghttp.NewClient()
+ c2 := g.Client()
c2.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p2))
t.Assert(c1.PostContent("/post"), "post1")
t.Assert(c2.PostContent("/post"), "post2")
diff --git a/net/ghttp/ghttp_unit_router_hook_test.go b/net/ghttp/ghttp_unit_router_hook_test.go
index 6115284e7..8c391ff7c 100644
--- a/net/ghttp/ghttp_unit_router_hook_test.go
+++ b/net/ghttp/ghttp_unit_router_hook_test.go
@@ -35,7 +35,7 @@ func Test_Router_Hook_Basic(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "123")
@@ -76,7 +76,7 @@ func Test_Router_Hook_Fuzzy_Router(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/john"), "Not Found")
@@ -116,7 +116,7 @@ func Test_Router_Hook_Priority(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "Not Found")
@@ -150,7 +150,7 @@ func Test_Router_Hook_Multi(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "Not Found")
@@ -185,7 +185,7 @@ func Test_Router_Hook_ExitAll(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/test"), "test")
diff --git a/net/ghttp/ghttp_unit_router_names_test.go b/net/ghttp/ghttp_unit_router_names_test.go
index 54a68b37c..f51a2ee7a 100644
--- a/net/ghttp/ghttp_unit_router_names_test.go
+++ b/net/ghttp/ghttp_unit_router_names_test.go
@@ -34,7 +34,7 @@ func Test_NameToUri_FullName(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetBrowserMode(true)
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "Not Found")
@@ -55,7 +55,7 @@ func Test_NameToUri_AllLower(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetBrowserMode(true)
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "Not Found")
@@ -76,7 +76,7 @@ func Test_NameToUri_Camel(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetBrowserMode(true)
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "Not Found")
@@ -97,7 +97,7 @@ func Test_NameToUri_Default(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetBrowserMode(true)
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "Not Found")
diff --git a/net/ghttp/ghttp_unit_router_object_rest1_test.go b/net/ghttp/ghttp_unit_router_object_rest1_test.go
index 8788b8147..7c8ac17a3 100644
--- a/net/ghttp/ghttp_unit_router_object_rest1_test.go
+++ b/net/ghttp/ghttp_unit_router_object_rest1_test.go
@@ -66,7 +66,7 @@ func Test_Router_ObjectRest(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "1Object Get2")
diff --git a/net/ghttp/ghttp_unit_router_object_rest2_test.go b/net/ghttp/ghttp_unit_router_object_rest2_test.go
index 22c1e0499..343b44558 100644
--- a/net/ghttp/ghttp_unit_router_object_rest2_test.go
+++ b/net/ghttp/ghttp_unit_router_object_rest2_test.go
@@ -53,7 +53,7 @@ func Test_Router_ObjectRest_Id(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/object/99"), "1Object Get992")
diff --git a/net/ghttp/ghttp_unit_router_object_test.go b/net/ghttp/ghttp_unit_router_object_test.go
index 5d0562fed..b339f81ce 100644
--- a/net/ghttp/ghttp_unit_router_object_test.go
+++ b/net/ghttp/ghttp_unit_router_object_test.go
@@ -50,7 +50,7 @@ func Test_Router_Object1(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "1Object Index2")
@@ -80,7 +80,7 @@ func Test_Router_Object2(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "Not Found")
@@ -106,7 +106,7 @@ func Test_Router_ObjectMethod(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "Not Found")
diff --git a/net/ghttp/ghttp_unit_session_test.go b/net/ghttp/ghttp_unit_session_test.go
index acfb17785..f4b8c3d78 100644
--- a/net/ghttp/ghttp_unit_session_test.go
+++ b/net/ghttp/ghttp_unit_session_test.go
@@ -38,7 +38,7 @@ func Test_Session_Cookie(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetBrowserMode(true)
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
r1, e1 := client.Get("/set?k=key1&v=100")
@@ -85,7 +85,7 @@ func Test_Session_Header(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
response, e1 := client.Get("/set?k=key1&v=100")
if response != nil {
@@ -132,7 +132,7 @@ func Test_Session_StorageFile(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
response, e1 := client.Get("/set?k=key&v=100")
if response != nil {
@@ -145,7 +145,7 @@ func Test_Session_StorageFile(t *testing.T) {
})
time.Sleep(time.Second)
gtest.C(t, func(t *gtest.T) {
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
client.SetHeader(s.GetSessionIdName(), sessionId)
t.Assert(client.GetContent("/get?k=key"), "100")
diff --git a/net/ghttp/ghttp_unit_static_test.go b/net/ghttp/ghttp_unit_static_test.go
index d2ab5d720..5f8ce1244 100644
--- a/net/ghttp/ghttp_unit_static_test.go
+++ b/net/ghttp/ghttp_unit_static_test.go
@@ -17,7 +17,6 @@ import (
"github.com/gogf/gf/text/gstr"
"github.com/gogf/gf/frame/g"
- "github.com/gogf/gf/net/ghttp"
"github.com/gogf/gf/os/gfile"
"github.com/gogf/gf/test/gtest"
)
@@ -35,7 +34,7 @@ func Test_Static_ServerRoot(t *testing.T) {
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "index")
@@ -54,7 +53,7 @@ func Test_Static_ServerRoot(t *testing.T) {
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "index")
@@ -71,7 +70,7 @@ func Test_Static_ServerRoot_Security(t *testing.T) {
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "index")
@@ -95,7 +94,7 @@ func Test_Static_Folder_Forbidden(t *testing.T) {
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "Forbidden")
@@ -117,7 +116,7 @@ func Test_Static_IndexFolder(t *testing.T) {
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.AssertNE(client.GetContent("/"), "Forbidden")
@@ -140,7 +139,7 @@ func Test_Static_IndexFiles1(t *testing.T) {
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "index")
@@ -162,7 +161,7 @@ func Test_Static_IndexFiles2(t *testing.T) {
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "test")
@@ -186,7 +185,7 @@ func Test_Static_AddSearchPath1(t *testing.T) {
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "Forbidden")
@@ -210,7 +209,7 @@ func Test_Static_AddSearchPath2(t *testing.T) {
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "Forbidden")
@@ -234,7 +233,7 @@ func Test_Static_AddStaticPath(t *testing.T) {
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "Forbidden")
@@ -259,7 +258,7 @@ func Test_Static_AddStaticPath_Priority(t *testing.T) {
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "Forbidden")
@@ -286,7 +285,7 @@ func Test_Static_Rewrite(t *testing.T) {
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "Forbidden")
diff --git a/net/ghttp/ghttp_unit_template_test.go b/net/ghttp/ghttp_unit_template_test.go
index d18889d0e..781443af7 100644
--- a/net/ghttp/ghttp_unit_template_test.go
+++ b/net/ghttp/ghttp_unit_template_test.go
@@ -38,7 +38,7 @@ func Test_Template_Basic(t *testing.T) {
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "Name:john")
@@ -64,7 +64,7 @@ func Test_Template_Encode(t *testing.T) {
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "Name:john")
@@ -93,7 +93,7 @@ func Test_Template_Layout1(t *testing.T) {
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "Not Found")
@@ -129,7 +129,7 @@ func Test_Template_Layout2(t *testing.T) {
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), "Not Found")
@@ -158,7 +158,7 @@ func Test_Template_XSS(t *testing.T) {
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
- client := ghttp.NewClient()
+ client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent("/"), ghtml.Entities(c))
diff --git a/net/ghttp/ghttp_z_example_test.go b/net/ghttp/ghttp_z_example_test.go
index ef01b1754..6d651f8e7 100644
--- a/net/ghttp/ghttp_z_example_test.go
+++ b/net/ghttp/ghttp_z_example_test.go
@@ -58,7 +58,7 @@ func ExampleClientResponse_RawDump() {
// socks5 proxy server listening on `127.0.0.1:1080`
func ExampleClient_SetProxy() {
// connect to a http proxy server
- client := ghttp.NewClient()
+ client := g.Client()
client.SetProxy("http://127.0.0.1:1081")
client.SetTimeout(5 * time.Second) // it's suggested to set http client timeout
response, err := client.Get("https://api.ip.sb/ip")
@@ -108,7 +108,7 @@ func ExampleClient_SetProxy() {
// socks5 proxy server listening on `127.0.0.1:1080`
// for more details, please refer to ExampleClient_SetProxy
func ExampleClientChain_Proxy() {
- client := ghttp.NewClient()
+ client := g.Client()
response, err := client.Proxy("http://127.0.0.1:1081").Get("https://api.ip.sb/ip")
if err != nil {
// err is not nil when your proxy server is down.
@@ -117,7 +117,7 @@ func ExampleClientChain_Proxy() {
}
fmt.Println(response.RawResponse())
- client2 := ghttp.NewClient()
+ client2 := g.Client()
response, err = client2.Proxy("socks5://127.0.0.1:1080").Get("https://api.ip.sb/ip")
if err != nil {
// err is not nil when your proxy server is down.