Skip to content

Commit

Permalink
fix: unable to return results #51 #52
Browse files Browse the repository at this point in the history
  • Loading branch information
missuo committed Jun 30, 2023
1 parent 4cbfd21 commit 8b8b0af
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
)

require (
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/bytedance/sonic v1.9.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/abadojack/whatlanggo v1.0.1 h1:19N6YogDnf71CTHm3Mp2qhYfkRdyvbgwWdd2EPxJRG4=
github.com/abadojack/whatlanggo v1.0.1/go.mod h1:66WiQbSbJBIlOZMsvbKe5m6pzQovxCH9B/K8tQB2uoc=
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s=
github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U=
Expand Down
19 changes: 15 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"time"

"github.com/abadojack/whatlanggo"
"github.com/andybalholm/brotli"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/tidwall/gjson"
Expand Down Expand Up @@ -192,9 +193,9 @@ func main() {
request.Header.Set("Accept-Language", "en-US,en;q=0.9")
request.Header.Set("Accept-Encoding", "gzip, deflate, br")
request.Header.Set("x-app-device", "iPhone13,2")
request.Header.Set("User-Agent", "DeepL-iOS/2.6.0 iOS 16.3.0 (iPhone13,2)")
request.Header.Set("x-app-build", "353933")
request.Header.Set("x-app-version", "2.6")
request.Header.Set("User-Agent", "DeepL-iOS/2.9.1 iOS 16.3.0 (iPhone13,2)")
request.Header.Set("x-app-build", "510265")
request.Header.Set("x-app-version", "2.9.1")
request.Header.Set("Connection", "keep-alive")

client := &http.Client{}
Expand All @@ -205,7 +206,17 @@ func main() {
}
defer resp.Body.Close()

body, _ := io.ReadAll(resp.Body)
var bodyReader io.Reader
switch resp.Header.Get("Content-Encoding") {
case "br":
bodyReader = brotli.NewReader(resp.Body)
default:
bodyReader = resp.Body
}

body, err := io.ReadAll(bodyReader)

// body, _ := io.ReadAll(resp.Body)
res := gjson.ParseBytes(body)

// display response
Expand Down

0 comments on commit 8b8b0af

Please sign in to comment.