Content Digest

The :content_plugin plugin can encode the digest of request payloads in the “content-digest” header, and can also validate integrity of response payloads using the same header, as described in the Digest Fields RFC

How to use

session = HTTPX.plugin(:content_digest)
session.post(uri, body: body) # calculates the body digest and puts it in the "content-digest" header)

:digest_algorithm

You can set the digest algorithm to generate the request payload hash with. Options are "sha-256" (default) and "sha-512".

session = HTTPX.plugin(:content_digest, digest_algorithm: "sha-512")
session.post(... #=>
# POST <URL>
# ...
# Content-Digest: sha-512=:<HASH>:
# ...

<PAYLOAD>

:encode_content_digest

You can set whether the request should generate a digest at all (true by default). Options are a boolean, or a callable receiving a request:

HTTPX.plugin(:content_digest, encode_content_digest: false)
# or
HTTPX.plugin(:content_digest, encode_content_digest: -> (req) { is_blacklisted?(req.uri) })

:validate_content_digest

You can set whether the request should validate the response digest (false by default). Options are a boolean, or a callable receiving a response:

HTTPX.plugin(:content_digest, validate_content_digest: true)
# or
HTTPX.plugin(:content_digest, validate_content_digest: -> (res) { res.headers.key?("content-digest") })

When the :validate_content_digest option is set to true, a request will respond with an ErrorResponse if the payload integrity verification fails.

Missing features

  • No support for "repr-digest" yet
  • No support for calculating or verifying digest for chunked requests/responses yet.

Next: XML