# Calculate the `digest` of an HTTP request

For all requests that contain a body, the body digest must be calculated and added as a request header named `digest`, as described in [the IETF draft for HTTP digest fields](https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-digest-headers-06#name-the-digest-field).

In summary, the digest calculation algorithm as used for the Investment API can be applied as follows:

* Capture the entire request body's byte stream.
* Calculate the [SHA-256](https://datatracker.ietf.org/doc/html/rfc6234) hash of the body content.
* Encode the resulting value using [Base64 encoding](https://datatracker.ietf.org/doc/html/rfc4648)
* Add a request header named `digest` with this
value: `SHA-256={digest value}`, where `{digest value}` is replaced by the
result of the previous step.


From the above description you should now understand how to calculate a digest. Here are some examples you can use to check your understanding.

| Request body | Content length | `digest` header value |
|  --- | --- | --- |
| {"hello": "world"} | 18 | `SHA-256=X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE=` |
| {"key": "value"} | 16 | `SHA-256=lyTB4g5uPk1/V+0l+dTvsAblCFkNUoyQ2ll/andcE+U=` |
|  | 0 | No `digest` header should be included in the request. |