Skip to content

Commit

Permalink
Fix LookupWellKnown to read full response (#441)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
richvdh authored Nov 6, 2024
1 parent 6c4c6f7 commit dbd5f31
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions fclient/well_known.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,10 @@ func LookupWellKnown(ctx context.Context, serverNameType spec.ServerName) (*Well
// by checking Content-Length, but it's possible that header will be
// missing. Better to be safe than sorry by reading no more than the
// WellKnownMaxSize in any case.
bodyBuffer := make([]byte, WellKnownMaxSize)
limitedReader := &io.LimitedReader{
R: resp.Body,
N: WellKnownMaxSize,
}
n, err := limitedReader.Read(bodyBuffer)
if err != nil && err != io.EOF {
body, err := io.ReadAll(&io.LimitedReader{R: resp.Body, N: WellKnownMaxSize})
if err != nil {
return nil, err
}
body := bodyBuffer[:n]

// Convert result to JSON
wellKnownResponse := &WellKnownResult{
Expand Down

0 comments on commit dbd5f31

Please sign in to comment.