Class: Rack::IdempotencyKey::RequestHash

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/idempotency_key/request_hash.rb

Instance Method Summary collapse

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

#idString

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.

Returns:

  • (String)

    A SHA-256 hexadecimal digest representing the request fingerprint.



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(authorization_header)
  update_with_request_body_chunks(digest)
  digest.hexdigest
end