Appendix C. Examples of Want-Repr-Digest Solicited Digest
The following examples demonstrate interactions where a client solicits a Repr-Digest using Want-Repr-Digest. The behavior of Content-Digest and Want-Content-Digest is identical.
Some examples include JSON objects in the content. For presentation purposes, objects that fit completely within the line-length limits are presented on a single line using compact notation with no leading space. Objects that would exceed line-length limits are presented across multiple lines (one line per key-value pair) with two spaces of leading indentation.
Checksum mechanisms described in this document are media-type agnostic and do not provide canonicalization algorithms for specific formats. Examples are calculated inclusive of any space.
C.1. Server Selects Client's Least Preferred Algorithm
The client requests a digest and prefers "sha". The server is free to reply with "sha-256" anyway.
GET /items/123 HTTP/1.1
Host: foo.example
Want-Repr-Digest: sha-256=3, sha=10
Figure 31: GET Request with Want-Repr-Digest
NOTE: '' line wrapping per RFC 8792
HTTP/1.1 200 OK
Content-Type: application/json
Repr-Digest: \
sha-256=:RK/0qy18MlBSVnWgjwz6lZEWjP/lF5HF9bvEF8FabDg==:
{"hello": "world"}
Figure 32: Response with Different Algorithm
C.2. Server Selects Algorithm Unsupported by Client
The client requests a "sha" digest because that is the only algorithm it supports. The server is not obliged to produce a response containing a "sha" digest; it instead uses a different algorithm.
GET /items/123 HTTP/1.1
Host: foo.example
Want-Repr-Digest: sha=10
Figure 33: GET Request with Want-Repr-Digest
NOTE: '' line wrapping per RFC 8792
HTTP/1.1 200 OK
Content-Type: application/json
Repr-Digest: \
sha-512=:YMAam51Jz/jOATT6/zvHrLVgOYTGFy1d6GJiOHTohq4yP+pgk4vf2aCs\
yRZOtw8MjkM7iw7yZ/WkppmM44T3qg==:
{"hello": "world"}
Figure 34: Response with Unsupported Algorithm
C.3. Server Does Not Support Client Algorithm and Returns an Error
Appendix C.2 is an example where a server ignores the client's preferred digest algorithm. Alternatively, a server can also reject the request and return a response with an error status code such as 4xx or 5xx. This specification does not prescribe any requirement on status code selection; the following example illustrates one possible option.
In this example, the client requests a "sha" Repr-Digest, and the server returns an error with problem details [RFC9457] contained in the content. The problem details contain a list of the hashing algorithms that the server supports. This is purely an example; this specification does not define any format or requirements for such content.
GET /items/123 HTTP/1.1
Host: foo.example
Want-Repr-Digest: sha=10
Figure 35: GET Request with Want-Repr-Digest
HTTP/1.1 400 Bad Request
Content-Type: application/problem+json
{
"title": "Bad Request",
"detail": "Supported hashing algorithms: sha-256, sha-512",
"status": 400
}
Figure 36: Response Advertising the Supported Algorithms