mirror of
https://codeberg.org/VnPower/PixivFE
synced 2024-12-06 19:16:23 +01:00
proxy_checker: simplify CRC32 calc
This commit is contained in:
@@ -6,7 +6,6 @@ package proxy_checker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"hash/crc32"
|
||||
"io"
|
||||
@@ -102,20 +101,14 @@ func testProxy(ctx context.Context, auditor *audit.Auditor, proxyBaseURL string)
|
||||
return false, resp
|
||||
}
|
||||
|
||||
// Copy response body and compare CRC32 checksum with expected value
|
||||
// Calculate CRC32 checksum of response body
|
||||
hash := crc32.NewIEEE()
|
||||
if _, err := io.Copy(hash, resp.Body); err != nil {
|
||||
auditor.SugaredLogger.Errorf("Error reading response body from image proxy %s: %v", proxyBaseURL, err)
|
||||
return false, resp
|
||||
}
|
||||
|
||||
checksum := hash.Sum32()
|
||||
checksumHex := hex.EncodeToString([]byte{
|
||||
byte(checksum >> 24),
|
||||
byte(checksum >> 16),
|
||||
byte(checksum >> 8),
|
||||
byte(checksum),
|
||||
})
|
||||
checksumHex := fmt.Sprintf("%08x", hash.Sum32())
|
||||
|
||||
if checksumHex != testImageCRC32 {
|
||||
auditor.SugaredLogger.Warnf("CRC32 mismatch for image proxy %s. Expected: %s, Got: %s", proxyBaseURL, testImageCRC32, checksumHex)
|
||||
|
||||
Reference in New Issue
Block a user