Skip to content

Commit

Permalink
Change headers logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Toktar committed Jul 15, 2022
1 parent e3a35d7 commit 14165d2
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
8 changes: 6 additions & 2 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,15 @@ func serve() {
didUrl := c.Param("did")
log.Debug().Msgf("DID: %s", didUrl)

accept := strings.Split(c.Request().Header.Get(echo.HeaderAccept), ";")[0]
acceptSettings := strings.Split(c.Request().Header.Get(echo.HeaderAccept), ";")
accept := acceptSettings[0]
if len(acceptSettings) > 1 && strings.Contains(acceptSettings[1], "profile=") {
accept += ";" + acceptSettings[1]
}
log.Trace().Msgf("Accept: %s", accept)

requestedContentType := types.ContentType(accept)
if accept == "*/*" {
if accept == "*/*" || accept == string(types.JSONLD) {
requestedContentType = types.DIDJSONLD
} else if strings.Contains(accept, string(types.HTML)) {
requestedContentType = types.HTML
Expand Down
2 changes: 1 addition & 1 deletion docker/.env
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ REDIRECTED_PORT="80"
LOCAL_REDIRECT_FROM=localhost:80

# Address with port of external Cheqd-DID-Resolver.
EXTERNAL_REDIRECT_TO=https://did-resolver.cheqd.dev
EXTERNAL_REDIRECT_TO=https://resolver.cheqd.net


CHEQD_RESOLVER_HOME_DIR="/home/cheqd-resolver"
3 changes: 2 additions & 1 deletion services/request_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
// marshal in combination with our proto generator version
"encoding/json"
"fmt"
"strings"

"github.com/rs/zerolog/log"

Expand Down Expand Up @@ -130,7 +131,7 @@ func (rs RequestService) Resolve(did string, resolutionOptions types.ResolutionO
return types.DidResolution{ResolutionMetadata: didResolutionMetadata}, nil
}

if didResolutionMetadata.ContentType == types.DIDJSONLD || didResolutionMetadata.ContentType == types.JSONLD {
if didResolutionMetadata.ContentType == types.DIDJSONLD || strings.Contains(string(didResolutionMetadata.ContentType), string(types.JSONLD)) {
didDoc.Context = append(didDoc.Context, types.DIDSchemaJSONLD)
} else if didResolutionMetadata.ContentType == types.DIDJSON || didResolutionMetadata.ContentType == types.HTML {
didDoc.Context = []string{}
Expand Down
1 change: 1 addition & 0 deletions tests/pytest/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
DIDJSON = "application/did+json"
DIDLDJSON = "application/did+ld+json"
LDJSON = "application/ld+json"
LDJSONProfile = LDJSON + ";profile=\"https://w3id.org/did-resolution\""
HTML = "text/html"

IMPLICIT_TIMEOUT = 40
Expand Down
13 changes: 8 additions & 5 deletions tests/pytest/test_resolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from helpers import run, TESTNET_DID, MAINNET_DID, TESTNET_FRAGMENT, MAINNET_FRAGMENT, \
FAKE_TESTNET_DID, FAKE_MAINNET_DID, FAKE_TESTNET_FRAGMENT, FAKE_MAINNET_FRAGMENT, RESOLVER_URL, PATH, \
LDJSON, DIDJSON, DIDLDJSON, HTML, FAKE_TESTNET_RESOURCE
LDJSON, DIDJSON, DIDLDJSON, HTML, FAKE_TESTNET_RESOURCE, LDJSONProfile


@pytest.mark.parametrize(
Expand Down Expand Up @@ -40,11 +40,14 @@ def test_resolution(did_url, expected_output):
@pytest.mark.parametrize(
"accept, expected_header, expected_body",
[
(LDJSON, LDJSON, r"(.*?)didResolutionMetadata(.*?)application/ld\+json"
r"(.*?)didDocument(.*?)@context(.*?)didDocumentMetadata"),
(DIDLDJSON, DIDLDJSON, "(.*?)didResolutionMetadata(.*?)application/did\+ld\+json"
(LDJSONProfile, LDJSONProfile,
r"(.*?)didResolutionMetadata(.*?)application/ld\+json"
r"(.*?)didDocument(.*?)@context(.*?)didDocumentMetadata"),
(LDJSON, DIDLDJSON, r"(.*?)didResolutionMetadata(.*?)application/did\+ld\+json"
r"(.*?)didDocument(.*?)@context(.*?)didDocumentMetadata"),
(DIDLDJSON, DIDLDJSON, r"(.*?)didResolutionMetadata(.*?)application/did\+ld\+json"
"(.*?)didDocument(.*?)@context(.*?)didDocumentMetadata"),
("", DIDLDJSON, "(.*?)didResolutionMetadata(.*?)application/did\+ld\+json"
("", DIDLDJSON, r"(.*?)didResolutionMetadata(.*?)application/did\+ld\+json"
"(.*?)didDocument(.*?)@context(.*?)didDocumentMetadata"),
(DIDJSON, DIDJSON, r"(.*?)didResolutionMetadata(.*?)application/did\+json"
r"(.*?)didDocument(.*?)(?!`@context`)(.*?)didDocumentMetadata"),
Expand Down

0 comments on commit 14165d2

Please sign in to comment.