diff --git a/verifiers/did-plc/plc.go b/verifiers/did-plc/plc.go index d8c6d31..6b0fae5 100644 --- a/verifiers/did-plc/plc.go +++ b/verifiers/did-plc/plc.go @@ -78,11 +78,18 @@ func (d DidPlc) Document(opts ...did.ResolutionOption) (did.Document, error) { if err != nil { return nil, err } + req.Header.Set("Accept", "application/json") + req.Header.Set("User-Agent", "go-did-it") res, err := params.HttpClient().Do(req) if err != nil { return nil, fmt.Errorf("%w: %w", did.ErrResolutionFailure, err) } + defer res.Body.Close() + + if res.StatusCode != http.StatusOK { + return nil, fmt.Errorf("%w: HTTP %d", did.ErrResolutionFailure, res.StatusCode) + } var aux struct { Did string `json:"did"` @@ -95,8 +102,9 @@ func (d DidPlc) Document(opts ...did.ResolutionOption) (did.Document, error) { } `json:"services"` } - // limit at 1MB - err = json.NewDecoder(io.LimitReader(res.Body, 1<<20)).Decode(&aux) + // limit at 1MB to avoid abuse + limiter := io.LimitReader(res.Body, 1<<20) + err = json.NewDecoder(limiter).Decode(&aux) if err != nil { return nil, fmt.Errorf("%w: %w", did.ErrResolutionFailure, err) }