use of javax.ws.rs.core.HttpHeaders.VARY in project trellis by trellis-ldp.
the class GetHandler method getRepresentation.
/**
* Build the representation for the given resource.
*
* @param builder the response builder
* @return the response builder
*/
public CompletionStage<ResponseBuilder> getRepresentation(final ResponseBuilder builder) {
// Add NonRDFSource-related "describe*" link headers, provided this isn't an extension resource
getResource().getBinaryMetadata().filter(ds -> getExtensionGraphName() == null).ifPresent(ds -> {
final String base = getBaseBinaryIdentifier();
final String description = base + (base.contains("?") ? "&" : "?") + "ext=description";
if (syntax != null) {
builder.link(description, "canonical").link(base, "describes").link(base + "#description", "alternate");
} else {
builder.link(base, "canonical").link(description, "describedby").type(ds.getMimeType().orElse(APPLICATION_OCTET_STREAM));
}
});
// Add a "self" link header
builder.link(getSelfIdentifier(), "self");
// NonRDFSources responses
if (getResource().getBinaryMetadata().isPresent() && syntax == null) {
return getLdpNr(builder.header(VARY, buildVaryHeader(false)));
}
// RDFSource responses
final IRI profile = getProfile(getRequest().getAcceptableMediaTypes(), syntax);
return completedFuture(getLdpRs(builder.header(VARY, buildVaryHeader(true)), syntax, profile));
}
Aggregations