Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update REST API for specifying checksums #960

Closed
wants to merge 10 commits into from

Conversation

Rarian
Copy link
Contributor

@Rarian Rarian commented Dec 1, 2015

Initially clients could specify checksums for uploaded binary content
via a custom checksum query parameter, instead of this non-standard
approach, we want to refactor to follow RFC-3230 4.3.2.

  • Adds Warning header to announce deprecation of checksum
  • Adds support for Digest header as per RFC-3230
  • Adds utility function for parsing Digest headers
  • Adds integration tests for checksum match and mismatch
  • Adds documentation for deprecation of checksum
  • Adds TODO hints for removal of deprecated code

Resolves: https://jira.duraspace.org/browse/FCREPO-1468

Initially clients could specify checksums for uploaded binary content
via a custom `checksum` query parameter, instead of this non-standard
approach, we want to refactor to follow RFC-3230 4.3.2.

* Adds 'Warning' header to announce deprecation of `checksum`
* Adds support for 'Digest' header as per RFC-3230
* Adds utility function for parsing Digest headers
* Adds integration tests for checksum match and mismatch

Resolves: https://jira.duraspace.org/browse/FCREPO-1468
* Create a resource at a specified path, or replace triples with provided RDF.
* @param requestContentType the request content type
* @param requestBodyStream the request body stream
* @param checksumDeprecated the deprecated checksum value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a better comment. Why deprecated? How to avoid it? What to prefer?

Testing of checksums of binary uploads should have utilized the
`getStatus(final HttpUriRequest req)` instead of executing the request
in a try block explicitly.
parseDigestHeader was looping through every submitted hash in
the Digest header and only taking action on the sha1.  Until we have
interest in additional hashes we can simple use lambdas to pull just the
sha1 header if it exists.
Reasoning behind deprecation of the checksum query parameter in favour
of the Digest header existed only in the git commit log and JIRA ticket,
without being present in the code.

* Documents deprecation
* Adds TODO to remove deprecated code
*/
private String parseDigestHeader(final String digest) {
final Map<String,String> digestPairs = RFC3230_SPLITTER.split(nullToEmpty(digest));
final String hash = digestPairs.entrySet().stream()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just use findFirst here, to acquire an Optional<String>. Then below, use Optional::orElse to create your defaulting behavior. There's no need to create then check for the blank string.

Instead of generating a potentially empty string value for the hash
variable in parseDigestHeader, we can utilize Optional<String> to
obliviate the need for an StringUtils.isBlank() in favour of using
Optional::orElse.
.filter(s -> s.getKey().toLowerCase().equals("sha1"))
.map(Map.Entry::getValue)
.findFirst();
return hash.map("urn:sha1:"::concat).orElse("");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can even go further and simply .map(...).orElse("") off of the .findFirst() line:

.findFirst()
.map("urn:sha1:"::concat)
.orElse("");

Then you don't even need to define the hash value or import Optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I... should have seen that.

Rarian and others added 5 commits December 2, 2015 11:23
Chainable functions... are chainable.
Add reference to TODO ticket
We were not properly handling invalid digest headers so when receiving a
value in the digest header that did not match RFC-3230 we were
incorrectly returning a 500 Internal Server Error, rather than the
correct 400 Bad Request.

* Handle invalid Digest Headers
* Extend integration tests to ensure proper handling of malformed header
@awoods
Copy link

awoods commented Dec 6, 2015

Resolved with: 4aefe3e

@awoods awoods closed this Dec 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants