Skip to content

Commit

Permalink
Merge pull request #724 from trellis-ldp/feature/acl-link-headers
Browse files Browse the repository at this point in the history
Include acl link headers in responses to ACL resources
  • Loading branch information
acoburn authored Mar 7, 2020
2 parents 6ab7251 + b92b107 commit 79d9eb4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,12 @@ public void filter(final ContainerRequestContext ctx) {

@Override
public void filter(final ContainerRequestContext req, final ContainerResponseContext res) {
if (SUCCESSFUL.equals(res.getStatusInfo().getFamily()) && !DELETE.equals(req.getMethod())
&& !req.getUriInfo().getQueryParameters().getOrDefault(HttpConstants.EXT, emptyList())
.contains(HttpConstants.ACL)) {
if (SUCCESSFUL.equals(res.getStatusInfo().getFamily()) && !DELETE.equals(req.getMethod())) {
final boolean isAcl = req.getUriInfo().getQueryParameters()
.getOrDefault(HttpConstants.EXT, emptyList()).contains(HttpConstants.ACL);
final String rel = isAcl ? HttpConstants.ACL + " self" : HttpConstants.ACL;
res.getHeaders().add(LINK, fromUri(getRequestUri(req).queryParam(HttpConstants.EXT, HttpConstants.ACL)
.build()).rel(HttpConstants.ACL).build());
.build()).rel(rel).build());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,13 @@ void testFilterResponseWebac2() {

assertTrue(headers.isEmpty());
filter.filter(mockContext, mockResponseContext);
assertTrue(headers.isEmpty());

final Link link = (Link) headers.getFirst("Link");
assertNotNull(link);
assertTrue(link.getRels().contains("acl"));
assertTrue(link.getRels().contains("self"));
assertEquals("http://localhost/?ext=acl", link.getUri().toString());

}

@Test
Expand Down

0 comments on commit 79d9eb4

Please sign in to comment.