Skip to content

Commit dbd5f31

Browse files
authored
Fix LookupWellKnown to read full response (#441)
Fix a bug in `LookupWellKnown` which would cause it only to read part of the HTTP response body if it spanned multiple TCP segments. Fixes: #440
1 parent 6c4c6f7 commit dbd5f31

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

fclient/well_known.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,10 @@ func LookupWellKnown(ctx context.Context, serverNameType spec.ServerName) (*Well
102102
// by checking Content-Length, but it's possible that header will be
103103
// missing. Better to be safe than sorry by reading no more than the
104104
// WellKnownMaxSize in any case.
105-
bodyBuffer := make([]byte, WellKnownMaxSize)
106-
limitedReader := &io.LimitedReader{
107-
R: resp.Body,
108-
N: WellKnownMaxSize,
109-
}
110-
n, err := limitedReader.Read(bodyBuffer)
111-
if err != nil && err != io.EOF {
105+
body, err := io.ReadAll(&io.LimitedReader{R: resp.Body, N: WellKnownMaxSize})
106+
if err != nil {
112107
return nil, err
113108
}
114-
body := bodyBuffer[:n]
115109

116110
// Convert result to JSON
117111
wellKnownResponse := &WellKnownResult{

0 commit comments

Comments
 (0)