Class: Protocol::HTTP::Header::Digest

Inherits:
Split
  • Object
show all
Defined in:
lib/protocol/http/header/digest.rb

Overview

The ‘digest` header provides a digest of the message body for integrity verification.

This header allows servers to send cryptographic hashes of the response body, enabling clients to verify data integrity. Multiple digest algorithms can be specified, and the header is particularly useful as a trailer since the digest can only be computed after the entire message body is available.

## Examples

“‘ruby digest = Digest.new(“sha-256=X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE=”) digest << “md5=9bb58f26192e4ba00f01e2e7b136bbd8” puts digest.to_s # => “sha-256=X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE=, md5=9bb58f26192e4ba00f01e2e7b136bbd8” “`

Defined Under Namespace

Classes: Entry

Constant Summary collapse

ParseError =
Class.new(Error)
ENTRY =
/\A(?<algorithm>[a-zA-Z0-9][a-zA-Z0-9\-]*)\s*=\s*(?<value>.*)\z/

Constants inherited from Split

Split::COMMA

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Split

#<<, #initialize, #to_s

Constructor Details

This class inherits a constructor from Protocol::HTTP::Header::Split

Class Method Details

.trailer?Boolean

Whether this header is acceptable in HTTP trailers.

Returns:

  • (Boolean)


64
65
66
# File 'lib/protocol/http/header/digest.rb', line 64

def self.trailer?
  true
end

Instance Method Details

#entriesObject

Parse the ‘digest` header value into a list of digest entries.



52
53
54
55
56
57
58
59
60
# File 'lib/protocol/http/header/digest.rb', line 52

def entries
  self.map do |value|
    if match = value.match(ENTRY)
      Entry.new(match[:algorithm], match[:value])
    else
      raise ParseError.new("Could not parse digest value: #{value.inspect}")
    end
  end
end