change ghttp.NewClient to g.Client

This commit is contained in:
Jack
2020-11-25 16:40:45 +08:00
parent 33292f54e0
commit 0bc8944a08
38 changed files with 180 additions and 182 deletions

View File

@ -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()

View File

@ -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{

View File

@ -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`)

View File

@ -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")

View File

@ -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")

View File

@ -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")

View File

@ -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)

View File

@ -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")

View File

@ -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")

View File

@ -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")

View File

@ -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{})

View File

@ -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"), `<span class="GPageSpan">首页</span><span class="GPageSpan">上一页</span><span class="GPageSpan">1</span><a class="GPageLink" href="/list?page=2" title="2">2</a><a class="GPageLink" href="/list?page=3" title="3">3</a><a class="GPageLink" href="/list?page=2" title="">下一页</a><a class="GPageLink" href="/list?page=3" title="">尾页</a>`)

View File

@ -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",

View File

@ -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(

View File

@ -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 := `<doc><id>1</id><name>john</name><password1>123Abc!@#</password1><password2>123Abc!@#</password2></doc>`

View File

@ -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")

View File

@ -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")

View File

@ -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")

View File

@ -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")

View File

@ -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")

View File

@ -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")

View File

@ -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")

View File

@ -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")

View File

@ -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")

View File

@ -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")

View File

@ -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")

View File

@ -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")

View File

@ -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")

View File

@ -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")

View File

@ -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")

View File

@ -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")

View File

@ -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")

View File

@ -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")

View File

@ -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")

View File

@ -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")

View File

@ -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")

View File

@ -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))

View File

@ -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.