From 9b5c3913989754370bd7d03ac8cf2e32a6172afb Mon Sep 17 00:00:00 2001 From: Keuin Date: Sat, 29 Jul 2023 19:43:27 +0800 Subject: Simulate real web app cookies & WebSocket fields --- bilibili/request.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'bilibili/request.go') diff --git a/bilibili/request.go b/bilibili/request.go index 11ff995..613530c 100644 --- a/bilibili/request.go +++ b/bilibili/request.go @@ -29,8 +29,8 @@ func (b *Bilibili) newGet(url string) (req *http.Request, err error) { return b.newRequest("GET", url, strings.NewReader("")) } -// callGet make a GET request and parse response as a JSON document with given model. -func callGet[T types.BaseResponse[V], V any](b *Bilibili, url string) (resp T, err error) { +// callGetRaw make a GET request and returns the raw response body. +func callGetRaw(b *Bilibili, url string) (resp *http.Response, respBody []byte, err error) { req, err := b.newGet(url) if err != nil { b.logger.Error("Cannot create HTTP request instance on API %v: %v", url, err) @@ -56,6 +56,16 @@ func callGet[T types.BaseResponse[V], V any](b *Bilibili, url string) (resp T, e return } + return r, data, err +} + +// callGet make a GET request and parse response as a JSON document with given model. +func callGet[T BaseResponse[V], V any](b Bilibili, url string) (resp T, err error) { + r, data, err := callGetRaw(b, url) + if err != nil { + return + } + err = json.Unmarshal(data, &resp) if err != nil { b.logger.Error("Invalid JSON body of HTTP response on API %v: %v. Text: \"%v\"", -- cgit v1.2.3