Skip to content

Commit

Permalink
simple http client for web did
Browse files Browse the repository at this point in the history
  • Loading branch information
brianolson committed Nov 13, 2024
1 parent 6e3c2e3 commit 1f22a51
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion did/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,26 @@ import (
"fmt"
"net/http"
"strings"
"time"
"unicode"

"github.com/whyrusleeping/go-did"
"go.opentelemetry.io/otel"
)

var webDidDefaultTimeout = 5 * time.Second

type WebResolver struct {
Insecure bool
// TODO: cache? maybe at a different layer

client http.Client
}

func (wr *WebResolver) GetDocument(ctx context.Context, didstr string) (*Document, error) {
if wr.client.Timeout == 0 {
wr.client.Timeout = webDidDefaultTimeout
}
ctx, span := otel.Tracer("did").Start(ctx, "didWebGetDocument")
defer span.End()

Expand All @@ -36,7 +44,7 @@ func (wr *WebResolver) GetDocument(ctx context.Context, didstr string) (*Documen
proto = "http"
}

resp, err := http.Get(proto + "://" + val + "/.well-known/did.json")
resp, err := wr.client.Get(proto + "://" + val + "/.well-known/did.json")
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 1f22a51

Please sign in to comment.