Skip to content

Commit

Permalink
feat: Better support for DID document media types
Browse files Browse the repository at this point in the history
  • Loading branch information
peacekeeper committed Jan 23, 2025
1 parent f77aeb7 commit 33432f3
Showing 1 changed file with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package uniresolver.web.servlet;

import com.fasterxml.jackson.databind.ObjectMapper;
import foundation.identity.did.representations.Representations;
import foundation.identity.did.representations.production.RepresentationProducer;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
Expand Down Expand Up @@ -167,15 +169,32 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t

// determine representation media type

if (result.getContentType() != null && MediaTypeUtil.isMediaTypeAcceptable(httpAcceptMediaType, result.getContentType())) {
if (log.isDebugEnabled()) log.debug("Supporting HTTP media type " + httpAcceptMediaType + " via content type " + result.getContentType());
byte[] httpBody = result.getFunctionContent();
ServletUtil.sendResponse(
response,
httpStatusCode,
result.getContentType(),
httpBody);
return;
if (result instanceof ResolveResult resolveResult) {
for (RepresentationProducer representationProducer : Representations.representationProducers) {
if (MediaTypeUtil.isMediaTypeAcceptable(httpAcceptMediaType, representationProducer.getMediaType())) {
if (log.isDebugEnabled()) log.debug("Supporting HTTP media type " + httpAcceptMediaType + " via DID document media type " + representationProducer.getMediaType() + " and resolved DID document media type " + representationProducer.getMediaType());
byte[] httpBody = representationProducer.produce(resolveResult.getDidDocument());
ServletUtil.sendResponse(
response,
httpStatusCode,
representationProducer.getMediaType(),
httpBody);
return;
}
}
}

if (result instanceof DereferenceResult dereferenceResult) {
if (result.getContentType() != null && MediaTypeUtil.isMediaTypeAcceptable(httpAcceptMediaType, result.getContentType())) {
if (log.isDebugEnabled()) log.debug("Supporting HTTP media type " + httpAcceptMediaType + " via content media type " + result.getContentType());
byte[] httpBody = result.getFunctionContent();
ServletUtil.sendResponse(
response,
httpStatusCode,
result.getContentType(),
httpBody);
return;
}
}

// continue
Expand Down

0 comments on commit 33432f3

Please sign in to comment.