Skip to content

Commit

Permalink
Merge pull request #117 from /issues/98
Browse files Browse the repository at this point in the history
Issues/98
  • Loading branch information
scossu committed Sep 5, 2019
2 parents 029db9b + 1b60061 commit f0c7e53
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
36 changes: 20 additions & 16 deletions lakesuperior/endpoints/ldp.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,26 +186,30 @@ def get_resource(uid, out_fmt=None):
rdf_mimetype = DEFAULT_RDF_MIMETYPE
ggr = g.tbox.globalize_imr(rsrc.out_graph)
ggr.namespace_manager = nsm
return _negotiate_content(
rsp = _negotiate_content(
ggr, rdf_mimetype, out_headers, uid=uid, uri=uri)
if isinstance(rsrc, LdpNr):
rsp.headers.add(
'Link', f'<{g.tbox.uid_to_uri(uid)}>', rel='describes')

return rsp

# Datastream.
if not getattr(rsrc, 'local_path', False):
return ('{} has no binary content.'.format(rsrc.uid), 404)

logger.debug('Streaming out binary content.')
if request.range and request.range.units == 'bytes':
# Stream partial response.
# This is only true if the header is well-formed. Thanks, Werkzeug.
rsp = _parse_range_header(
request.range.ranges, rsrc, out_headers
)
else:
if not getattr(rsrc, 'local_path', False):
return ('{} has no binary content.'.format(rsrc.uid), 404)

logger.debug('Streaming out binary content.')
if request.range and request.range.units == 'bytes':
# Stream partial response.
# This is only true if the header is well-formed. Thanks, Werkzeug.
rsp = _parse_range_header(
request.range.ranges, rsrc, out_headers
)
else:
rsp = make_response(send_file(
rsrc.local_path, as_attachment=True,
attachment_filename=rsrc.filename,
mimetype=rsrc.mimetype), 200, out_headers)
rsp = make_response(send_file(
rsrc.local_path, as_attachment=True,
attachment_filename=rsrc.filename,
mimetype=rsrc.mimetype), 200, out_headers)

# This seems necessary to prevent Flask from setting an
# additional ETag.
Expand Down
12 changes: 12 additions & 0 deletions tests/3_endpoints/test_3_0_ldp.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,18 @@ def test_get_ldp_nr(self, rnd_img):
assert isomorphic(gr1, gr2)


def test_metadata_describe_header(self):
"""
Verify that a "describe" Link header is presented for LDP-NR metadata.
"""
uid = f'/{uuid4()}'
self.client.put(f'/ldp{uid}', data=b'ciao')

md_rsp = self.client.get(f'/ldp{uid}/fcr:metadata')
assert (
f'<{g.tbox.uid_to_uri(uid)}>; rel=describes'
in md_rsp.headers.get_all('Link'))


def test_put_mismatched_ldp_rs(self, rnd_img):
"""
Expand Down

0 comments on commit f0c7e53

Please sign in to comment.