# Calculate the `content-digest` of an HTTP request.

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

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-512](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 `content-digest` with this
value: `sha-512=:{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 | `content-digest` header value |
|  --- | --- | --- |
| {"hello": "world"} | 18 | `sha-512=:WZDPaVn/7XgHaAy8pmojAkGWoRx2UFChF41A2svX+TaPm+AbwAgBWnrIiYllu7BNNyealdVLvRwEmTHWXvJwew==:` |
| {"key": "value"} | 16 | `sha-512=:Hd9/AvGZkbjitW1+Ml8Fg1ux1mtcDYe6mLQjDyoowIWa3LM/PmwN2v9O+MjtQGrCA3EQWUL54dlgxKHyYbrucw==:` |
|  | 0 | No `content-digest` header should be included in the request. |