Class: Rack::IdempotencyKey::RequestHash
- Inherits:
-
Object
- Object
- Rack::IdempotencyKey::RequestHash
- Defined in:
- lib/rack/idempotency_key/request_hash.rb
Instance Method Summary collapse
-
#id ⇒ String
Generates a unique SHA-256 hash to identify the request.
-
#initialize(rack_request) ⇒ RequestHash
constructor
A new instance of RequestHash.
Constructor Details
#initialize(rack_request) ⇒ RequestHash
Returns a new instance of RequestHash.
8 9 10 |
# File 'lib/rack/idempotency_key/request_hash.rb', line 8 def initialize(rack_request) @rack_request = rack_request end |
Instance Method Details
#id ⇒ String
Generates a unique SHA-256 hash to identify the request.
The hash is constructed using the request method, full path, idempotency key, authorization header, and the request body (if available and rewindable).
This ensures that requests with identical content produce the same fingerprint, supporting idempotency while preventing accidental collisions between different clients.
21 22 23 24 25 26 27 28 29 |
# File 'lib/rack/idempotency_key/request_hash.rb', line 21 def id digest = Digest::SHA256.new digest.update(rack_request.request_method) digest.update(rack_request.fullpath) digest.update(idempotency_key_header) digest.update() update_with_request_body_chunks(digest) digest.hexdigest end |