diff --git a/core/http/src/main/java/org/trellisldp/http/impl/GetHandler.java b/core/http/src/main/java/org/trellisldp/http/impl/GetHandler.java index 288356066..2705ea28f 100644 --- a/core/http/src/main/java/org/trellisldp/http/impl/GetHandler.java +++ b/core/http/src/main/java/org/trellisldp/http/impl/GetHandler.java @@ -75,6 +75,7 @@ import java.util.stream.Stream; import javax.ws.rs.ClientErrorException; +import javax.ws.rs.NotAcceptableException; import javax.ws.rs.NotFoundException; import javax.ws.rs.RedirectionException; import javax.ws.rs.core.EntityTag; @@ -147,11 +148,16 @@ public ResponseBuilder initialize(final Resource resource) { LOGGER.debug("Acceptable media types: {}", getRequest().getAcceptableMediaTypes()); - if (!LDP.NonRDFSource.equals(resource.getInteractionModel()) || getRequest().getExt() != null) { - this.syntax = getSyntax(getServices().getIOService(), - getRequest().getAcceptableMediaTypes(), resource.getBinaryMetadata() - .filter(b -> !DESCRIPTION.equals(getRequest().getExt())) - .map(b -> b.getMimeType().orElse(APPLICATION_OCTET_STREAM)).orElse(null)); + // Get the requested syntax + this.syntax = getSyntax(getServices().getIOService(), + getRequest().getAcceptableMediaTypes(), resource.getBinaryMetadata() + .filter(b -> !DESCRIPTION.equals(getRequest().getExt())) + .map(b -> b.getMimeType().orElse(APPLICATION_OCTET_STREAM)).orElse(null)); + + // For LDP-NRs, if there is a negotiated RDF syntax, throw a 406 error + if (LDP.NonRDFSource.equals(resource.getInteractionModel()) && getRequest().getExt() == null && + this.syntax != null) { + throw new NotAcceptableException(); } final IRI ext = getExtensionGraphName(); @@ -362,8 +368,8 @@ private CompletionStage getLdpNr(final ResponseBuilder builder) final IRI dsid = getResource().getBinaryMetadata().map(BinaryMetadata::getIdentifier).orElse(null); // Add standard headers - builder.header(ACCEPT_RANGES, "bytes").tag(etag) - .header(ALLOW, isMemento ? join(",", GET, HEAD, OPTIONS) : join(",", GET, HEAD, OPTIONS, PUT, DELETE)); + builder.header(ACCEPT_RANGES, "bytes").tag(etag); + addAllowHeaders(builder); // Short circuit HEAD requests if (HEAD.equals(getRequest().getMethod())) { diff --git a/core/http/src/test/java/org/trellisldp/http/AbstractTrellisHttpResourceTest.java b/core/http/src/test/java/org/trellisldp/http/AbstractTrellisHttpResourceTest.java index 05efe9e83..8a00c7d43 100644 --- a/core/http/src/test/java/org/trellisldp/http/AbstractTrellisHttpResourceTest.java +++ b/core/http/src/test/java/org/trellisldp/http/AbstractTrellisHttpResourceTest.java @@ -431,6 +431,13 @@ void testGetBinary() throws IOException { } } + @Test + void testGetBinaryBadConneg() throws IOException { + try (final Response res = target(BINARY_PATH).request().header(ACCEPT, "text/turtle").get()) { + assertEquals(SC_NOT_ACCEPTABLE, res.getStatus(), ERR_RESPONSE_CODE); + } + } + @Test void testGetBinaryHeaders() { try (final Response res = target(BINARY_PATH).request().head()) {