Skip to content

Commit

Permalink
Not reuse fasthttp client
Browse files Browse the repository at this point in the history
  • Loading branch information
Wikidepia committed Jun 15, 2024
1 parent 3dbe056 commit 41f407d
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions handlers/data/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func getData(postID string) (gjson.Result, error) {

// Scrape from GraphQL API
if videoBlocked || len(username) == 0 {
gqlValue, err := parseGQLData(postID, req, res)
gqlValue, err := parseGQLData(postID)
if err != nil {
log.Error().Str("postID", postID).Err(err).Msg("Failed to parse data from parseGQLData")
return gjsonNil, err
Expand Down Expand Up @@ -306,9 +306,8 @@ func parseEmbedHTML(embedHTML []byte) (string, error) {
}`, nil
}

func parseGQLData(postID string, req *fasthttp.Request, res *fasthttp.Response) ([]byte, error) {
req.Reset()
res.Reset()
func parseGQLData(postID string) ([]byte, error) {
req, res := fasthttp.AcquireRequest(), fasthttp.AcquireResponse()

req.Header.SetMethod("POST")
req.Header.Set("accept", "*/*")
Expand Down Expand Up @@ -364,5 +363,9 @@ func parseGQLData(postID string, req *fasthttp.Request, res *fasthttp.Response)
if err := client.DoTimeout(req, res, timeout); err != nil {
return nil, err
}
return res.Body(), nil

var newBytes []byte
// Copy body to newBytes
newBytes = append(newBytes, res.Body()...)
return newBytes, nil
}

0 comments on commit 41f407d

Please sign in to comment.