Skip to content

Commit

Permalink
fix: Fix headers contentType behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
Toktar committed Jul 7, 2022
1 parent c147716 commit 29e50ab
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
6 changes: 2 additions & 4 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,9 @@ func serve() {
accept := strings.Split(c.Request().Header.Get(echo.HeaderAccept), ";")[0]
log.Trace().Msgf("Accept: %s", accept)

var requestedContentType types.ContentType
if strings.Contains(accept, string(types.JSONLD)) {
requestedContentType := types.ContentType(accept)
if accept == "*/*" {
requestedContentType = types.DIDJSONLD
} else {
requestedContentType = types.DIDJSON
}
log.Debug().Msgf("Requested content type: %s", requestedContentType)

Expand Down
7 changes: 6 additions & 1 deletion services/request_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
// jsonpb Marshaller is deprecated, but is needed because there's only one way to proto
// marshal in combination with our proto generator version
"encoding/json"
"fmt"

"github.com/rs/zerolog/log"

Expand Down Expand Up @@ -123,8 +124,12 @@ func (rs RequestService) Resolve(did string, resolutionOptions types.ResolutionO
return types.DidResolution{ResolutionMetadata: didResolutionMetadata}, nil
}

if didResolutionMetadata.ContentType == types.DIDJSONLD {
if didResolutionMetadata.ContentType == types.DIDJSONLD || didResolutionMetadata.ContentType == types.JSONLD {
didDoc.Context = append(didDoc.Context, types.DIDSchemaJSONLD)
} else if didResolutionMetadata.ContentType == types.DIDJSON {
didDoc.Context = []string{}
} else {
return types.DidResolution{}, fmt.Errorf("content type %s is not supported", didResolutionMetadata.ContentType)
}
return types.DidResolution{Did: didDoc, Metadata: metadata, ResolutionMetadata: didResolutionMetadata}, nil
}
Expand Down
4 changes: 3 additions & 1 deletion services/request_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@ func TestResolve(t *testing.T) {
MethodSpecificId: subtest.identifier,
Method: subtest.method,
}
if (subtest.resolutionType == types.DIDJSONLD || subtest.resolutionType == types.JSONLD) && subtest.expectedError == "" {
if (subtest.resolutionType == "" || subtest.resolutionType == types.DIDJSONLD) && subtest.expectedError == "" {
subtest.expectedDID.Context = []string{types.DIDSchemaJSONLD}
} else {
subtest.expectedDID.Context = nil
}

resolutionResult, err := requestService.Resolve(id, types.ResolutionOption{Accept: subtest.resolutionType})
Expand Down

0 comments on commit 29e50ab

Please sign in to comment.