github.com/sohaha/zlsgo@v1.7.13-0.20240501141223-10dd1a906f76/zhttp/http_test.go (about)

     1  package zhttp
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"io/ioutil"
     7  	"net/http"
     8  	"net/http/httptest"
     9  	"net/url"
    10  	"strings"
    11  	"testing"
    12  	"time"
    13  
    14  	zls "github.com/sohaha/zlsgo"
    15  	"github.com/sohaha/zlsgo/zfile"
    16  	"github.com/sohaha/zlsgo/znet"
    17  	"github.com/sohaha/zlsgo/ztype"
    18  )
    19  
    20  var (
    21  	r *znet.Engine
    22  )
    23  
    24  type Result struct {
    25  	Num, Ans int
    26  }
    27  
    28  type Cal int
    29  
    30  func (cal *Cal) Square(num int, result *Result) error {
    31  	result.Num = num
    32  	result.Ans = num * num
    33  	return nil
    34  }
    35  
    36  func TestMain(m *testing.M) {
    37  	r = znet.New("zhttp-test")
    38  	r.SetAddr("3788")
    39  	r.Log.Discard()
    40  	r.POST("/upload", func(c *znet.Context) {
    41  		file, err := c.FormFile("file")
    42  		if err == nil {
    43  			_ = c.SaveUploadedFile(file, "./package.json")
    44  			c.String(200, "上传成功")
    45  		}
    46  	})
    47  
    48  	r.Any("/sse", func(c *znet.Context) {
    49  		if !c.IsSSE() {
    50  			return
    51  		}
    52  		sse := znet.NewSSE(c, func(lastID string, opts *znet.SSEOption) {
    53  			opts.RetryTime = 500
    54  			opts.HeartbeatsTime = 500
    55  		})
    56  		if sse.LastEventID() != "" {
    57  			return
    58  		}
    59  		go func() {
    60  			for i := 0; i < 2; i++ {
    61  				_ = sse.Send(ztype.ToString(i), ztype.ToString(i), "system")
    62  			}
    63  			time.Sleep(time.Second)
    64  			sse.Stop()
    65  		}()
    66  		sse.Push()
    67  	})
    68  
    69  	r.Any("/__rpc", znet.JSONRPC(map[string]interface{}{
    70  		"Cal": new(Cal),
    71  	}, func(o *znet.JSONRPCOption) {
    72  		o.Debug = true
    73  	}))
    74  
    75  	go func() {
    76  		r.SetAddr(":18181")
    77  		znet.Run()
    78  	}()
    79  	time.Sleep(time.Second / 2)
    80  	m.Run()
    81  }
    82  
    83  func TestHttp(T *testing.T) {
    84  	t := zls.NewTest(T)
    85  	var (
    86  		res          *Res
    87  		err          error
    88  		data         string
    89  		expectedText string
    90  	)
    91  
    92  	forMethod(t)
    93  
    94  	// test post
    95  	expectedText = "ok"
    96  	urlValues := url.Values{"ok": []string{"666"}}
    97  	res, err = newMethod("Post", func(w http.ResponseWriter, r *http.Request) {
    98  		_ = r.ParseForm()
    99  		id, ok := r.PostForm["id"]
   100  		if !ok {
   101  			t.Fatal("err")
   102  		}
   103  		_, _ = w.Write([]byte(expectedText + id[0]))
   104  	}, urlValues, Param{
   105  		"id":  "123",
   106  		"id2": "123",
   107  	}, QueryParam{
   108  		"id3": 333,
   109  		"id6": 666,
   110  	})
   111  	if err != nil {
   112  		t.Fatal(err)
   113  	}
   114  	data = res.String()
   115  	t.Equal(expectedText+"123", data)
   116  
   117  	// test post application/x-www-form-urlencoded
   118  	expectedText = "ok"
   119  	res, err = newMethod("Post", func(w http.ResponseWriter, r *http.Request) {
   120  		query := r.URL.Query()
   121  		id, ok := query["id"]
   122  		if !ok {
   123  			t.Fatal("err")
   124  		}
   125  		_, _ = w.Write([]byte(expectedText + id[0]))
   126  	}, QueryParam{
   127  		"id": "123",
   128  	})
   129  	if err != nil {
   130  		t.Fatal(err)
   131  	}
   132  	data = res.String()
   133  	t.Equal(expectedText+"123", data)
   134  	t.Log(res.GetCookie())
   135  }
   136  
   137  func TestJONS(tt *testing.T) {
   138  	t := zls.NewTest(tt)
   139  	jsonData := `{"name":"is json"}`
   140  	v := BodyJSON(jsonData)
   141  	_, _ = newMethod("POST", func(w http.ResponseWriter, r *http.Request) {
   142  		tt.Log(v)
   143  		body, err := ioutil.ReadAll(r.Body)
   144  		t.EqualExit(nil, err)
   145  		t.EqualExit(jsonData, string(body))
   146  		t.EqualExit("application/json; charset=UTF-8", r.Header.Get("Content-Type"))
   147  	}, v, Header{"name": "ok"})
   148  }
   149  
   150  func TestRetry(tt *testing.T) {
   151  	t := zls.NewTest(tt)
   152  	h := New()
   153  	i := 0
   154  	_, err := DoRetry(30, time.Second/10, func() (*Res, error) {
   155  		t := time.Duration(100*2*i+1) * time.Millisecond
   156  		h.SetTimeout(t)
   157  		tt.Log("Retry", i, t)
   158  		res, err := h.Get("https://unpkg.com/")
   159  		i++
   160  
   161  		return res, err
   162  	})
   163  
   164  	t.Log(i, err)
   165  }
   166  
   167  func TestToHTML(tt *testing.T) {
   168  	t := zls.NewTest(tt)
   169  	res, err := Get("https://unpkg.com/")
   170  	if err != nil {
   171  		t.Fatal(err)
   172  		return
   173  	}
   174  	t.EqualTrue(res.HTML().Select("title").Text() != "")
   175  }
   176  
   177  func TestGetMethod(tt *testing.T) {
   178  	t := zls.NewTest(tt)
   179  	jsonData := struct {
   180  		Code int `json:"code"`
   181  	}{}
   182  	data := ""
   183  	values := [...]string{
   184  		"text",
   185  		"{\"code\":201}",
   186  	}
   187  	EnableCookie(false)
   188  	for i, v := range values {
   189  		cookie := &http.Cookie{
   190  			Name:     "c",
   191  			Value:    "ok" + fmt.Sprint(i),
   192  			Path:     "/",
   193  			HttpOnly: true,
   194  			MaxAge:   0,
   195  		}
   196  		res, err := newMethod("GET", func(w http.ResponseWriter, _ *http.Request) {
   197  			tt.Log(v)
   198  			w.Header().Add("Set-Cookie", cookie.String())
   199  			_, _ = w.Write([]byte(v))
   200  		}, v)
   201  		tt.Log("get ok", i, err)
   202  		t.EqualExit(nil, err)
   203  		tt.Log(res.String())
   204  		if err = res.ToJSON(&jsonData); err == nil {
   205  			t.Equal(201, jsonData.Code)
   206  		}
   207  
   208  		j := res.JSONs()
   209  		tt.Log(j.String())
   210  		if j.IsObject() {
   211  			t.EqualExit(201, j.Get("code").Int())
   212  			t.EqualExit(201, res.JSON("code").Int())
   213  		}
   214  		if data, err = res.ToString(); err == nil {
   215  			t.Equal(v, data)
   216  		}
   217  		t.Equal("GET", res.Request().Method)
   218  		tt.Log(res.GetCookie())
   219  		tt.Log(res.String(), "\n")
   220  	}
   221  	EnableCookie(true)
   222  }
   223  
   224  func forMethod(t *zls.TestUtil) {
   225  	values := [...]string{"Get", "Put", "Head", "Options", "Delete", "Patch", "Trace", "Connect"}
   226  	for _, v := range values {
   227  		_, err := newMethod(v, func(_ http.ResponseWriter, _ *http.Request) {
   228  		})
   229  		if err != nil {
   230  			t.Fatal(v, err)
   231  		}
   232  	}
   233  }
   234  
   235  func newMethod(method string, handler func(_ http.ResponseWriter, _ *http.Request), param ...interface{}) (res *Res, err error) {
   236  	ts := httptest.NewServer(http.HandlerFunc(handler))
   237  	curl := ts.URL
   238  	switch method {
   239  	case "Get":
   240  		res, err = Get(curl, param...)
   241  	case "Post":
   242  		res, err = Post(curl, param...)
   243  	case "Put":
   244  		res, err = Put(curl, param...)
   245  	case "Head":
   246  		res, err = Head(curl, param...)
   247  	case "Options":
   248  		res, err = Options(curl, param...)
   249  	case "Delete":
   250  		res, err = Delete(curl, param...)
   251  	case "Patch":
   252  		res, err = Patch(curl, param...)
   253  	case "Connect":
   254  		res, err = Connect(curl, param...)
   255  	case "Trace":
   256  		res, err = Trace(curl, param...)
   257  	default:
   258  		method = strings.Title(method)
   259  		res, err = Do(method, curl, param...)
   260  		if err == nil {
   261  			fmt.Println(res.Dump())
   262  		}
   263  	}
   264  	return
   265  }
   266  
   267  func TestRes(t *testing.T) {
   268  	tt := zls.NewTest(t)
   269  	u := "https://unpkg.com/"
   270  	// res, err := Get("https://www.npmjs.com/package/zls-vue-spa/")
   271  	res, err := Get(u)
   272  	t.Log(u, err)
   273  	tt.EqualExit(true, err == nil)
   274  	t.Log(res.Body())
   275  	t.Log(res.String())
   276  	t.Log(res.Body())
   277  	respBody, _ := ioutil.ReadAll(res.Body())
   278  	t.Log(string(respBody))
   279  	t.Log(res.Dump())
   280  }
   281  
   282  func TestHttpProxy(t *testing.T) {
   283  	tt := zls.NewTest(t)
   284  	err := SetProxy(func(r *http.Request) (*url.URL, error) {
   285  		if strings.Contains(r.URL.String(), "qq.com") {
   286  			tt.Log(r.URL.String(), "SetProxy get", "http://127.0.0.1:6666")
   287  			return url.Parse("http://127.0.0.1:6666")
   288  		} else {
   289  			tt.Log(r.URL.String(), "Not SetProxy")
   290  		}
   291  		return nil, nil
   292  	})
   293  	var res *Res
   294  	if err != nil {
   295  		tt.Fatal(err)
   296  	}
   297  
   298  	SetTimeout(10 * time.Second)
   299  
   300  	res, err = Get("http://www.qq.com")
   301  	if err == nil {
   302  		tt.Log(res.Response().Status)
   303  	} else {
   304  		tt.Log(err)
   305  	}
   306  	tt.Equal(true, err != nil)
   307  
   308  	res, err = Get("https://unpkg.com/zls-vue-spa@1.1.29/package.json")
   309  	if err == nil {
   310  		tt.Log(res.Response().Status)
   311  	} else {
   312  		tt.Log(err)
   313  	}
   314  	tt.Equal(false, err != nil)
   315  }
   316  
   317  func TestHttpProxyUrl(tt *testing.T) {
   318  	t := zls.NewTest(tt)
   319  	_ = SetTransport(func(transport *http.Transport) {})
   320  	err := SetProxyUrl()
   321  	t.EqualTrue(err != nil)
   322  	err = SetProxyUrl("http://127.0.0.1:66661", "http://127.0.0.1:77771")
   323  	t.EqualNil(err)
   324  
   325  	SetTimeout(1 * time.Second)
   326  	_, err = newMethod("GET", func(w http.ResponseWriter, _ *http.Request) {
   327  	})
   328  	tt.Log(err)
   329  	t.Equal(true, err != nil)
   330  }
   331  
   332  func TestFile(t *testing.T) {
   333  	tt := zls.NewTest(t)
   334  	_ = RemoveProxy()
   335  	SetTimeout(20 * time.Second)
   336  	downloadProgress := func(current, total int64) {
   337  		t.Log("downloadProgress", current, total)
   338  	}
   339  	res, err := Get("https://unpkg.com/zls-vue-spa@1.1.29/package.json", downloadProgress)
   340  	tt.EqualNil(err)
   341  	if err == nil {
   342  		err = res.ToFile(`../zhttp\test\package.json`)
   343  		tt.EqualNil(err)
   344  		t.Log(len(res.String()))
   345  		err = res.ToFile(`../zhttp\test\package2.json`)
   346  		tt.Log(err)
   347  		tt.EqualNil(err)
   348  	}
   349  	defer zfile.Rmdir("./test/")
   350  	defer zfile.Rmdir("./package.json")
   351  
   352  	std.CheckRedirect()
   353  	time.Sleep(time.Second)
   354  
   355  	v := url.Values{
   356  		"name": []string{"isTest"},
   357  	}
   358  	q := Param{"q": "yes"}
   359  
   360  	h := Header{
   361  		"type": "upload",
   362  	}
   363  	res, err = Post("http://127.0.0.1:18181/upload", h, UploadProgress(func(current, total int64) {
   364  		t.Log(current, total)
   365  	}), Host("127.0.0.1:18181"), v, q, File("test\\package.json", "file"))
   366  	if err != nil {
   367  		tt.EqualNil(err)
   368  		return
   369  	}
   370  	tt.Equal("上传成功", res.String())
   371  	tt.EqualTrue(zfile.FileSizeUint("./package.json") > 120)
   372  	zfile.Rmdir("./package.json")
   373  
   374  	_ = SetTransport(func(transport *http.Transport) {
   375  		transport.MaxIdleConnsPerHost = 100
   376  	})
   377  
   378  	DisableChunke()
   379  	res, err = Post("http://127.0.0.1:18181/upload", h, CustomReq(func(req *http.Request) {
   380  
   381  	}), UploadProgress(func(current, total int64) {
   382  		t.Log(current, total)
   383  	}), v, q, context.Background(), File("./test//package2.json", "file"))
   384  	tt.EqualNil(err)
   385  	tt.Equal("上传成功", res.String())
   386  	zfile.Rmdir("./package2.json")
   387  }
   388  
   389  func TestRandomUserAgent(T *testing.T) {
   390  	tt := zls.NewTest(T)
   391  	for i := 0; i < 10; i++ {
   392  		tt.Log(RandomUserAgent())
   393  	}
   394  	SetUserAgent(func() string {
   395  		return ""
   396  	})
   397  }
   398  
   399  func TestGetCode(t *testing.T) {
   400  	tt := zls.NewTest(t)
   401  	EnableInsecureTLS(true)
   402  	r, _ := Get("https://xxxaaa--xxx.jsdelivr.net/")
   403  	tt.EqualExit(0, r.StatusCode())
   404  
   405  	c := newClient()
   406  	SetClient(c)
   407  	r, err := Get("https://unpkg.com/zls-vue-spa@1.1.29/package.json")
   408  	if err != nil {
   409  		t.Fatal(err)
   410  	}
   411  	tt.EqualExit(200, r.StatusCode())
   412  	t.Log(r.String())
   413  	t.Log(r.StatusCode())
   414  	r.Dump()
   415  }
   416  
   417  func TestConvertCookie(tt *testing.T) {
   418  	t := zls.NewTest(tt)
   419  	cookie := ConvertCookie(
   420  		" langx=zh-cn; lang code= zh-cn; sid=3c14598d6f2bce696a73a7649ab3df0df23c13c1; ")
   421  	for _, c := range cookie {
   422  		switch c.Name {
   423  		case "langx":
   424  			t.Equal("zh-cn", c.Value)
   425  		case "lang code":
   426  			t.Equal(" zh-cn", c.Value)
   427  		case "sid":
   428  			t.Equal("3c14598d6f2bce696a73a7649ab3df0df23c13c1", c.Value)
   429  		default:
   430  			tt.Fatal("no match", c.Name, c.Value)
   431  		}
   432  	}
   433  }
   434  
   435  func TestTlsCertificate(tt *testing.T) {
   436  	t := zls.NewTest(tt)
   437  
   438  	key := zfile.RealPath("localhost.key")
   439  	crt := zfile.RealPath("localhost.crt")
   440  	defer func() {
   441  		zfile.Rmdir(key)
   442  		zfile.Rmdir(crt)
   443  	}()
   444  	_ = zfile.WriteFile(crt, []byte("-----BEGIN CERTIFICATE-----\nMIIFODCCAyCgAwIBAgIUSwmVV6hatwktLUBtLCdTw0rZ5+UwDQYJKoZIhvcNAQEL\nBQAwFDESMBAGA1UEAwwJbG9jYWxob3N0MB4XDTIxMDMyOTA2NTc0M1oXDTMxMDMy\nNzA2NTc0M1owFDESMBAGA1UEAwwJbG9jYWxob3N0MIICIjANBgkqhkiG9w0BAQEF\nAAOCAg8AMIICCgKCAgEAv9FDHTRyLaNBwr7IzdvVHEBHEWsGvYoGiBDZBwnYlyDo\nl1O+zs9HdvUoMx9yJinojxY8nok0yN+2uMVTke+Si1h/Qh1dELmI9qKenOrCVtoc\nxz7KE3TVUua+Bnezx199PmIf35ZYp5jXCU4ceHA0hNXL63qedqVlDVVCl/cHgFMK\n2+dyRF0SjwGsLIguWQPHAB5+N1HbSU0QsJztL4swFr87Fm2k96Q1od3pJHiwBYX0\ntP2mzbIzRpRRyWZ8r57T+ECAGX01A2x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q5OwSNPx+fLz6tTVdz1V\nh3ISgoDmFvCVdobW+r54crX0HIgyX5qNA/16VeRaI17kSXjG3rt4tqEMmFw0hz53\ntVYIr23QvlhaPxVoGJZpD3Ihkh+8yv0KYrG3Zii6Q7t1KuwSNkATcRLEE+sNNI0C\nrrwRcyTWHyfezpHWDARFpaFbN+8yA3KiSrwVu/AQJtGdaFYoRTZfATWozXPQkTGl\nMbnIaC/twCZhtfhJFDA91z+B27JMDSSSvUJu3C7B34U6OOOaFTrfpaKcbV0=\n-----END CERTIFICATE-----\n"))
   445  	_ = zfile.WriteFile(key, []byte("-----BEGIN PRIVATE KEY-----\nMIIJQwIBADANBgkqhkiG9w0BAQEFAASCCS0wggkpAgEAAoICAQC/0UMdNHIto0HC\nvsjN29UcQEcRawa9igaIENkHCdiXIOiXU77Oz0d29SgzH3ImKeiPFjyeiTTI37a4\nxVOR75KLWH9CHV0QuYj2op6c6sJW2hzHPsoTdNVS5r4Gd7PHX30+Yh/fllinmNcJ\nThx4cDSE1cvrep52pWUNVUKX9weAUwrb53JEXRKPAawsiC5ZA8cAHn43UdtJTRCw\nnO0vizAWvzsWbaT3pDWh3ekkeLAFhfS0/abNsjNGlFHJZnyvntP4QIAZfTUDbFTk\nhULqBeVYdlM57//Wp/z1d/dEiTZFmK+hJmDxQb7ercn6elX6e+XNxLss+FsKad7m\n4ZMoj3q0+eaR7Zy/TRPmrv5PcQO12F04i9vezycz6CCKH9bY83unxX6G8gfQGUZq\nDOK0prn1kCLBHrOmrUiuABwgV+UTTWOsbF+0ikgyY+0Hi4P769ofFn3oFm9W5xNO\njelHFm5DvKUzKHtkccBU0latW1KTTay8MiO7jdILVRP2na8q25l/2sScfLfiW7Mg\nkYqZVcEoXwUxkx3u7lLsd6dCqbNAdp4O+D24BJTSU+3q0V+zh4M6FBWZfkJxR6mM\n8KOdbMnm7zVQcagfHtdlhv5pMxZI7jT8OG+MiASS20WtDqOvvs5LXiu98hSIyfuP\nxxL/hHhSthnxsGFsI3CN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EBAJokL8GXzxhZ2WPtTol8TvUMzjciARTex/ONfvI4xV1O8nUDcarTEKrp\nL+/jAF8DsdnKQYaxmaTO8AXivVsESytZNyWJARiD1EcJb7HEsVv7Va0CZ9gJ8phH\n0KY5uTt8z/O+KO6NAhPBHLtDFd8mTMpEaMuIEqZUBKsOD6GOMUJrCmz8bcX8Q6tK\nh9+EC45ibIH8mAvAXBQoAh35QjFVK73nXuCnSh+Hwk/CaYSd4F2ctG1/LMli9V5c\n0ppF7bEsU2t5ZrmbgJt8OfetyevrmhYcx5FOzc+7Tb6Poa51YiGDVS9HprzlAH6e\ncZkVyZKPdYIMs055zvaLFALMaf3gWiA=\n-----END PRIVATE KEY-----\n"))
   446  	err := TlsCertificate(Certificate{
   447  		CertFile: crt,
   448  		KeyFile:  key,
   449  	})
   450  	t.EqualNil(err)
   451  	r, err := Get("https://wx.qq.com")
   452  	t.EqualNil(err)
   453  	tt.Log(r.HTML().Find("title").Text(true))
   454  }