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
session = HTTPX.plugin(:content_digest)
session.post(uri, body: body) # calculates the body digest and puts it in the "content-digest" header)
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>
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) })
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.
"repr-digest"
yetNext: XML