feat(fingerprint): support caller-supplied fingerprint ID via x-fingerprint-id header#164
Merged
Merged
Conversation
…rprint-id header Add an optional x-fingerprint-id request header to POST /data/fingerprint. Behaviour: - Header absent, hash not found -> generate ID, insert, return (existing flow unchanged) - Header absent, hash found -> return stored ID - Header present (valid), hash not found -> insert using caller-supplied ID, return it - Header present (valid), hash found -> return stored ID, header ignored - Header present (invalid) -> 422 ValidationError before any DB call Header format: exactly 20 alphanumeric characters (0-9 a-z A-Z). Changes: - src/storage/consts.rs: add X_FINGERPRINT_ID header constant - src/custom_extractors.rs: add OptionalFingerprintId extractor with validation; extract validate_fingerprint_id() for unit-testability; add 11 unit tests - src/storage.rs: add optional fingerprint_id param to FingerprintInterface trait - src/storage/db.rs: use caller-supplied ID on insert; harden concurrent insert race (UniqueViolation now re-reads and returns winner row instead of erroring) - src/storage/caching/fingerprint.rs: forward new param through caching wrapper - src/routes/data.rs: consume OptionalFingerprintId extractor in handler
GauravRawat369
approved these changes
Jun 2, 2026
su-shivanshmathur
pushed a commit
that referenced
this pull request
Jun 16, 2026
…erprint-id` header (#164)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add an optional x-fingerprint-id request header to POST /data/fingerprint.
Behaviour:
Header format: exactly 20 alphanumeric characters (0-9 a-z A-Z).
Test cases
Scenario A — hash not found, no header (server generates ID)
Response
200 OK{"fingerprint_id":"DxgSyhrG6RTnCUZmcLky"}Scenario B — hash not found, caller supplies ID
Response
200 OK{"fingerprint_id":"MyCustomId0123456789"}Scenario C — hash already exists, no header (returns stored ID)
Same request as Scenario A:
Response
200 OK{"fingerprint_id":"DxgSyhrG6RTnCUZmcLky"}Scenario D — hash already exists, header present (header ignored)
Response
200 OK{"fingerprint_id":"DxgSyhrG6RTnCUZmcLky"}Scenario E — invalid header value
Too short —
TooShort123456789(17 chars)Response
{"code":"TE_03","message":"Failed while validation: x-fingerprint-id must be exactly 20 alphanumeric characters","data":null}Non-alphanumeric characters —
bad-id-val-here12345(20 chars, contains-)Response
{"code":"TE_03","message":"Failed while validation: x-fingerprint-id must be exactly 20 alphanumeric characters","data":null}