frontend: limit fetched response size to 64KB (#39)

This commit is contained in:
Yuhui Xu
2021-09-02 20:21:28 -05:00
committed by GitHub
parent 1a3c618522
commit a64d839e2c
2 changed files with 15 additions and 7 deletions

View File

@@ -1,7 +1,7 @@
package main
import (
"io/ioutil"
"io"
"net/http"
"net/url"
"strconv"
@@ -53,8 +53,14 @@ func batchRequest(servers []string, endpoint string, command string) []string {
ch <- channelData{i, "request failed: " + err.Error() + "\n"}
return
}
text, _ := ioutil.ReadAll(response.Body)
ch <- channelData{i, string(text)}
buf := make([]byte, 65536)
_, err = io.ReadFull(response.Body, buf)
if err != nil && err != io.ErrUnexpectedEOF {
ch <- channelData{i, err.Error()}
} else {
ch <- channelData{i, string(buf)}
}
}(url, i)
}
}