Disable retry and set timeout to 14s for CF timeout of 15s. Add accept-encoding for compression.
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 9s
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 9s
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"sort"
|
||||
"time"
|
||||
)
|
||||
|
||||
// GetScoreByPlayerID GET /score/:player_id
|
||||
@@ -77,9 +78,9 @@ func GetPlayerScore(playerName string) (float32, int) {
|
||||
|
||||
func GetPlayerScoreNew(playerName string) (float32, int) {
|
||||
playerData, statusCode := getPlayerData(playerName)
|
||||
if statusCode == 408 { // retry once
|
||||
playerData, statusCode = getPlayerData(playerName)
|
||||
}
|
||||
//if statusCode == 408 { // retry once
|
||||
// playerData, statusCode = getPlayerData(playerName)
|
||||
//}
|
||||
if statusCode != 200 {
|
||||
return -1, statusCode
|
||||
}
|
||||
@@ -87,7 +88,9 @@ func GetPlayerScoreNew(playerName string) (float32, int) {
|
||||
}
|
||||
|
||||
func getPlayerData(playerName string) (*models.TrackerDataJSON, int) {
|
||||
c := http.Client{}
|
||||
c := http.Client{
|
||||
Timeout: 14 * time.Second, // Cloudflare timeout is 15s
|
||||
}
|
||||
|
||||
reqUri := "https://api.gametools.network/bf2042/stats/?raw=false&format_values=false&name=" + playerName + "&platform=pc"
|
||||
req, err := http.NewRequest("GET", reqUri, nil)
|
||||
@@ -97,6 +100,7 @@ func getPlayerData(playerName string) (*models.TrackerDataJSON, int) {
|
||||
}
|
||||
|
||||
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36")
|
||||
req.Header.Set("Accept-Encoding", "gzip, deflate, br")
|
||||
|
||||
res, err := c.Do(req)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user