fix(externalIpProvider/plain): when reading response body
All checks were successful
CI / test (pull_request) Successful in 45s
All checks were successful
CI / test (pull_request) Successful in 45s
This commit is contained in:
@@ -2,6 +2,7 @@ package externalIpProvider
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -40,12 +41,15 @@ func (p *ExternalIpProviderImplPlain) GetExternalIp() (net.IP, error) {
|
||||
}
|
||||
|
||||
if res.StatusCode != 200 {
|
||||
res.Body.Close()
|
||||
return nil, errors.New("unexpected status code")
|
||||
}
|
||||
|
||||
responseBody := make([]byte, res.ContentLength)
|
||||
res.Body.Read(responseBody)
|
||||
defer res.Body.Close()
|
||||
responseBody, err := io.ReadAll(res.Body)
|
||||
res.Body.Close()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
parsedIp := net.ParseIP(string(responseBody))
|
||||
if parsedIp == nil {
|
||||
|
||||
Reference in New Issue
Block a user