diff options
author | Keuin <[email protected]> | 2023-07-29 19:43:27 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2023-07-29 20:21:17 +0800 |
commit | 9b5c3913989754370bd7d03ac8cf2e32a6172afb (patch) | |
tree | 9e2caca8feb9ca5a9c14a96424d23e20db4314bc /bilibili/request.go | |
parent | a153bf02d1cf05f020d263e9670a76ae99cfeb02 (diff) |
Simulate real web app cookies & WebSocket fields
Diffstat (limited to 'bilibili/request.go')
-rw-r--r-- | bilibili/request.go | 14 |
1 files changed, 12 insertions, 2 deletions
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\"", |