aboutsummaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
authorGravatar Yong Tang <yong.tang.github@outlook.com> 2022-04-04 12:02:08 -0700
committerGravatar GitHub <noreply@github.com> 2022-04-04 15:02:08 -0400
commitc8844a8555b2b4206965b8e42678aacead782ae1 (patch)
treefb5694993a6fd50c6c6455bc6ce29394fe28485d /plugin
parent17fca596286287026b93d0691264bc3521457543 (diff)
downloadcoredns-c8844a8555b2b4206965b8e42678aacead782ae1.tar.gz
coredns-c8844a8555b2b4206965b8e42678aacead782ae1.tar.zst
coredns-c8844a8555b2b4206965b8e42678aacead782ae1.zip
Replace io.LimitReader with http.MaxBytesReader (#5241)
Previously we use io.LimitReader to limit the number of bytes from http request. However, there is a subtle difference between io.LimitReader and io.ReadAll as io.LimitReader will return a Reader, not a ReadCloser. As such the behavior will actually be difference in case of error handling (and when to close). This PR changes io.LimitReader to http.MaxBytesReader so that the behavior can be preserved (except the number of bytes). See https://stackoverflow.com/a/52699702 Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
Diffstat (limited to 'plugin')
-rw-r--r--plugin/pkg/doh/doh.go2
1 files changed, 1 insertions, 1 deletions
diff --git a/plugin/pkg/doh/doh.go b/plugin/pkg/doh/doh.go
index 575ae5369..9d5305b34 100644
--- a/plugin/pkg/doh/doh.go
+++ b/plugin/pkg/doh/doh.go
@@ -92,7 +92,7 @@ func requestToMsgGet(req *http.Request) (*dns.Msg, error) {
}
func toMsg(r io.ReadCloser) (*dns.Msg, error) {
- buf, err := io.ReadAll(io.LimitReader(r, 65536))
+ buf, err := io.ReadAll(http.MaxBytesReader(nil, r, 65536))
if err != nil {
return nil, err
}