Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions core/http/src/main/java/org/trellisldp/http/impl/GetHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -362,8 +368,8 @@ private CompletionStage<ResponseBuilder> 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())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down