Skip to content

Add automatic content hash for uploads#385

Merged
AndreyVMarkelov merged 1 commit into
mainfrom
feature/auto-content-hash
Jul 9, 2026
Merged

Add automatic content hash for uploads#385
AndreyVMarkelov merged 1 commit into
mainfrom
feature/auto-content-hash

Conversation

@AndreyVMarkelov

Copy link
Copy Markdown
Contributor

Computes and sends a Dropbox content_hash for seekable upload streams so the server verifies upload integrity and rejects corrupted uploads. Applies to all upload routes whose request carries a ContentHash (direct upload and upload sessions).

Behavior

  • On by default via DropboxClientConfig.AutoContentHash.
  • Opt out per-client (AutoContentHash = false) or per-upload (ContentHasher.WithoutAutoContentHash(stream)).
  • Non-seekable streams and manually supplied content hashes are left untouched.
  • Cost: seekable uploads are read twice (once to hash, once to send). Documented in the README.

Implementation

  • ContentHasher: public helper for the Dropbox block-SHA256 content hash (sync + async) and the opt-out wrapper.
  • Handler hashes the body, restores the stream position, and sets the hash on a cloned request. Retry now rewinds to the original upload position instead of 0.
  • Property access is resolved once per request type and cached.

Tests

  • Unit tests for the hasher (known vectors, block boundary, async) and upload wiring (auto, manual-wins, opt-out, non-seekable, position preservation, config disable).
  • Live e2e tests: direct upload round-trip and a chunked upload session, asserting the server-returned content hash matches and content round-trips.

Compute and send a Dropbox content_hash for seekable upload streams so the
server verifies upload integrity and rejects corrupted uploads. Applies to
all upload routes whose request carries a ContentHash (direct upload and
upload sessions).

- ContentHasher: public helper computing the Dropbox block-SHA256 content
  hash (sync + async), plus WithoutAutoContentHash to opt a stream out.
- Handler: hash the body before sending, restore the stream position, and
  set the hash on a cloned request; retry now rewinds to the original
  upload position rather than 0.
- Property access is resolved once per request type and cached.
- Config: DropboxClientConfig.AutoContentHash, on by default; opt out
  per-client or per-upload. Non-seekable streams and manually supplied
  hashes are left untouched.
- Tests: unit tests for the hasher and upload wiring, and live e2e tests
  covering direct upload round-trip and a chunked upload session.
- README: document the behavior, the 2x read cost, and opt-out.
@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 71.11111% with 65 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.60%. Comparing base (0e0c773) to head (e1c7503).

Files with missing lines Patch % Lines
dropbox-sdk-dotnet/Dropbox.Api/ContentHasher.cs 73.80% 30 Missing and 3 partials ⚠️
...ox-sdk-dotnet/Dropbox.Api/DropboxRequestHandler.cs 67.34% 26 Missing and 6 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #385      +/-   ##
==========================================
+ Coverage   59.38%   61.60%   +2.22%     
==========================================
  Files          16       17       +1     
  Lines        1433     1654     +221     
  Branches      136      155      +19     
==========================================
+ Hits          851     1019     +168     
- Misses        520      565      +45     
- Partials       62       70       +8     
Flag Coverage Δ
integration 57.19% <62.22%> (+1.22%) ⬆️
unit 33.91% <70.22%> (+23.58%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@AndreyVMarkelov AndreyVMarkelov merged commit 3cc79e1 into main Jul 9, 2026
21 of 22 checks passed
@AndreyVMarkelov AndreyVMarkelov deleted the feature/auto-content-hash branch July 9, 2026 17:26
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.

2 participants