mirror of
https://github.com/ap-pauloafonso/ratio-spoof.git
synced 2026-04-20 08:02:07 +00:00
fix gzip reader with already flushed buffer
This commit is contained in:
parent
3e52da8f14
commit
16be853e07
1 changed files with 9 additions and 8 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package ratiospoof
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"crypto/sha1"
|
||||
"errors"
|
||||
|
|
@ -413,23 +414,23 @@ func (R *ratioSPoofState) tryMakeRequest(query string) trackerResponse {
|
|||
}
|
||||
resp, err := R.httpClient.Do(req)
|
||||
if err == nil {
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
bytes, _ := ioutil.ReadAll(resp.Body)
|
||||
mimeType := http.DetectContentType(bytes)
|
||||
bytesR, _ := ioutil.ReadAll(resp.Body)
|
||||
mimeType := http.DetectContentType(bytesR)
|
||||
if mimeType == "application/x-gzip" {
|
||||
gzipReader, _ := gzip.NewReader(resp.Body)
|
||||
defer gzipReader.Close()
|
||||
bytes, _ = ioutil.ReadAll(gzipReader)
|
||||
gzipReader, _ := gzip.NewReader(bytes.NewReader(bytesR))
|
||||
bytesR, _ = ioutil.ReadAll(gzipReader)
|
||||
gzipReader.Close()
|
||||
}
|
||||
R.lastTackerResponse = string(bytes)
|
||||
decodedResp := beencode.Decode(bytes)
|
||||
R.lastTackerResponse = string(bytesR)
|
||||
decodedResp := beencode.Decode(bytesR)
|
||||
if idx != 0 {
|
||||
R.torrentInfo.trackerInfo.SwapFirst(idx)
|
||||
}
|
||||
ret := extractTrackerResponse(decodedResp)
|
||||
return ret
|
||||
}
|
||||
resp.Body.Close()
|
||||
}
|
||||
}
|
||||
panic("Connection error with the tracker")
|
||||
|
|
|
|||
Loading…
Reference in a new issue