Skip to content

Commit

Permalink
feat: Limit read http response size (#903)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeessy2 authored Nov 4, 2023
1 parent b0c050c commit 857f2a6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ func (conf *DnsConfig) getIpv4AddrFromUrl() string {
continue
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
lr := io.LimitReader(resp.Body, 1024000)
body, err := io.ReadAll(lr)
if err != nil {
log.Println("读取IPv4结果失败! 接口: ", url)
continue
Expand Down Expand Up @@ -327,7 +328,8 @@ func (conf *DnsConfig) getIpv6AddrFromUrl() string {
}

defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
lr := io.LimitReader(resp.Body, 1024000)
body, err := io.ReadAll(lr)
if err != nil {
log.Println("读取IPv6结果失败! 接口: ", url)
continue
Expand Down
3 changes: 2 additions & 1 deletion util/http_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ func GetHTTPResponseOrg(resp *http.Response, url string, err error) ([]byte, err
}

defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
lr := io.LimitReader(resp.Body, 1024000)
body, err := io.ReadAll(lr)

if err != nil {
log.Printf("请求接口%s失败! ERROR: %s\n", url, err)
Expand Down

0 comments on commit 857f2a6

Please sign in to comment.