Passa al contenuto principale

Appendice B. Esempi di Digest non richiesto

The following examples demonstrate interactions where a server responds with a Content-Digest or Repr-Digest field, even though the client did not solicit one using Want-Content-Digest or Want-Repr-Digest.

I seguenti esempi mostrano interazioni in cui un server risponde con un campo Content-Digest o Repr-Digest, anche se il client non ne ha richiesto uno utilizzando Want-Content-Digest o Want-Repr-Digest.

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.

Alcuni esempi includono oggetti JSON nel contenuto. A scopo di presentazione, gli oggetti che rientrano completamente nei limiti di lunghezza della riga vengono presentati su una singola riga utilizzando una notazione compatta senza spazi iniziali. Gli oggetti che supererebbero i limiti di lunghezza della riga vengono presentati su più righe (una riga per coppia chiave-valore) con due spazi di rientro iniziale.

Checksum mechanisms defined in this document are media-type agnostic and do not provide canonicalization algorithms for specific formats. Examples are calculated inclusive of any space. While examples can include both fields, Content-Digest and Repr-Digest can be returned independently.

I meccanismi di checksum definiti in questo documento sono indipendenti dal tipo di supporto e non forniscono algoritmi di canonicalizzazione per formati specifici. Gli esempi sono calcolati includendo qualsiasi spazio. Sebbene gli esempi possano includere entrambi i campi, Content-Digest e Repr-Digest possono essere restituiti in modo indipendente.

B.1. Il server restituisce i dati di rappresentazione completi

In this example, the message content conveys complete representation data. This means that in the response, Content-Digest and Repr-Digest are both computed over the JSON object {"hello": "world"} followed by an LF; thus, they have the same value.

In questo esempio, il contenuto del messaggio trasmette dati di rappresentazione completi. Ciò significa che nella risposta, Content-Digest e Repr-Digest sono entrambi calcolati sull'oggetto JSON {"hello": "world"} seguito da un LF; quindi, hanno lo stesso valore.

GET /items/123 HTTP/1.1
Host: foo.example

Figure 11: GET Request for an Item

Figura 11: Richiesta GET per un elemento

NOTE: '' line wrapping per RFC 8792

HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 19
Content-Digest: \
sha-256=:RK/0qy18MlBSVnWgjwz6lZEWjP/lF5HF9bvEF8FabDg=:
Repr-Digest: \
sha-256=:RK/0qy18MlBSVnWgjwz6lZEWjP/lF5HF9bvEF8FabDg=:

{"hello": "world"}

Figure 12: Response with Identical Repr-Digest and Content-Digest

Figura 12: Risposta con Repr-Digest e Content-Digest identici

B.2. Il server non restituisce dati di rappresentazione

In this example, a HEAD request is used to retrieve the checksum of a resource.

In questo esempio, viene utilizzata una richiesta HEAD per recuperare il checksum di una risorsa.

The response Content-Digest field-value is computed on empty content. Repr-Digest is calculated over the JSON object {"hello": "world"} followed by an LF, which is not shown because there is no content.

Il valore del campo Content-Digest della risposta viene calcolato su un contenuto vuoto. Repr-Digest viene calcolato sull'oggetto JSON {"hello": "world"} seguito da un LF, che non viene mostrato perché non c'è contenuto.

HEAD /items/123 HTTP/1.1
Host: foo.example

Figure 13: HEAD Request for an Item

Figura 13: Richiesta HEAD per un elemento

NOTE: '' line wrapping per RFC 8792

HTTP/1.1 200 OK
Content-Type: application/json
Content-Digest: \
sha-256=:47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=:
Repr-Digest: \
sha-256=:RK/0qy18MlBSVnWgjwz6lZEWjP/lF5HF9bvEF8FabDg=:

Figure 14: Response with Both Content-Digest and Digest (Empty Content)

Figura 14: Risposta con sia Content-Digest che Digest (contenuto vuoto)

B.3. Il server restituisce dati di rappresentazione parziali

In this example, the client makes a range request and the server responds with partial content.

In questo esempio, il client effettua una richiesta di intervallo e il server risponde con contenuto parziale.

GET /items/123 HTTP/1.1
Host: foo.example
Range: bytes=10-18

Figure 15: Request for Partial Content

Figura 15: Richiesta di contenuto parziale

NOTE: '' line wrapping per RFC 8792

HTTP/1.1 206 Partial Content
Content-Type: application/json
Content-Range: bytes 10-18/19
Content-Digest: \
sha-256=:jjcgBDWNAtbYUXI37CVG3gRuGOAjaaDRGpIUFsdyepQ=:
Repr-Digest: \
sha-256=:RK/0qy18MlBSVnWgjwz6lZEWjP/lF5HF9bvEF8FabDg=:

"world"}

Figure 16: Partial Response with Both Content-Digest and Repr-Digest

Figura 16: Risposta parziale con sia Content-Digest che Repr-Digest

In the response message above, note that the Repr-Digest and Content-Digests are different. The Repr-Digest field-value is calculated across the entire JSON object {"hello": "world"} followed by an LF, and the field appears as follows:

Nel messaggio di risposta sopra, si noti che Repr-Digest e Content-Digest sono diversi. Il valore del campo Repr-Digest è calcolato sull'intero oggetto JSON {"hello": "world"} seguito da un LF, e il campo appare come segue:

NOTE: '' line wrapping per RFC 8792

Repr-Digest: \
sha-256=:RK/0qy18MlBSVnWgjwz6lZEWjP/lF5HF9bvEF8FabDg=:

However, since the message content is constrained to bytes 10-18, the Content-Digest field-value is calculated over the sequence "world"} followed by an LF, thus resulting in the following:

Tuttavia, poiché il contenuto del messaggio è limitato ai byte 10-18, il valore del campo Content-Digest è calcolato sulla sequenza "world"} seguita da un LF, risultando quindi in quanto segue:

NOTE: '' line wrapping per RFC 8792

Content-Digest: \
sha-256=:jjcgBDWNAtbYUXI37CVG3gRuGOAjaaDRGpIUFsdyepQ=:

B.4. Client e server forniscono dati di rappresentazione completi

The request contains a Repr-Digest field-value calculated on the enclosed representation. It also includes an Accept-Encoding: br header field that advertises that the client supports Brotli encoding.

La richiesta contiene un valore del campo Repr-Digest calcolato sulla rappresentazione inclusa. Include anche un campo di intestazione Accept-Encoding: br che pubblicizza che il client supporta la codifica Brotli.

The response includes a Content-Encoding: br that indicates the selected representation is Brotli-encoded. The Repr-Digest field-value is therefore different compared to the request.

La risposta include un Content-Encoding: br che indica che la rappresentazione selezionata è codificata con Brotli. Il valore del campo Repr-Digest è quindi diverso rispetto alla richiesta.

For presentation purposes, the response body is displayed as a sequence of hex-encoded bytes because it contains non-printable characters.

A scopo di presentazione, il corpo della risposta viene visualizzato come una sequenza di byte codificati in esadecimale perché contiene caratteri non stampabili.

NOTE: '' line wrapping per RFC 8792

PUT /items/123 HTTP/1.1
Host: foo.example
Content-Type: application/json
Accept-Encoding: br
Repr-Digest: \
sha-256=:RK/0qy18MlBSVnWgjwz6lZEWjP/lF5HF9bvEF8FabDg=:

{"hello": "world"}

Figure 17: PUT Request with Digest

Figura 17: Richiesta PUT con Digest

NOTE: '' line wrapping per RFC 8792

HTTP/1.1 200 OK
Content-Type: application/json
Content-Location: /items/123
Content-Encoding: br
Content-Length: 23
Repr-Digest: \
sha-256=:d435Qo+nKZ+gLcUHn7GQtQ72hiBVAgqoLsZnZPiTGPk=:

8B 08 80 7B 22 68 65 6C 6C 6F
22 3A 20 22 77 6F 72 6C 64 22
7D 0A 03

Figure 18: Response with Digest of Encoded Response

Figura 18: Risposta con Digest della risposta codificata

B.5. Il client fornisce dati di rappresentazione completi e il server non fornisce dati di rappresentazione

The request Repr-Digest field-value is calculated on the enclosed content, which is the JSON object {"hello": "world"} followed by an LF.

Il valore del campo Repr-Digest della richiesta è calcolato sul contenuto incluso, che è l'oggetto JSON {"hello": "world"} seguito da un LF.

The response Repr-Digest field-value depends on the representation metadata header fields, including Content-Encoding: br, even when the response does not contain content.

Il valore del campo Repr-Digest della risposta dipende dai campi di intestazione dei metadati di rappresentazione, incluso Content-Encoding: br, anche quando la risposta non contiene contenuto.

NOTE: '' line wrapping per RFC 8792

PUT /items/123 HTTP/1.1
Host: foo.example
Content-Type: application/json
Content-Length: 19
Accept-Encoding: br
Repr-Digest: \
sha-256=:RK/0qy18MlBSVnWgjwz6lZEWjP/lF5HF9bvEF8FabDg==:

{"hello": "world"}
HTTP/1.1 204 No Content
Content-Type: application/json
Content-Encoding: br
Repr-Digest: sha-256=:d435Qo+nKZ+gLcUHn7GQtQ72hiBVAgqoLsZnZPiTGPk=:

Figure 19: Empty Response with Digest

Figura 19: Risposta vuota con Digest

B.6. Client e server forniscono dati di rappresentazione completi

The response contains two digest values using different algorithms.

La risposta contiene due valori di digest che utilizzano algoritmi diversi.

For presentation purposes, the response body is displayed as a sequence of hex-encoded bytes because it contains non-printable characters.

A scopo di presentazione, il corpo della risposta viene visualizzato come una sequenza di byte codificati in esadecimale perché contiene caratteri non stampabili.

NOTE: '' line wrapping per RFC 8792

PUT /items/123 HTTP/1.1
Host: foo.example
Content-Type: application/json
Accept-Encoding: br
Repr-Digest: \
sha-256=:RK/0qy18MlBSVnWgjwz6lZEWjP/lF5HF9bvEF8FabDg==:

{"hello": "world"}

Figure 20: PUT Request with Digest

Figura 20: Richiesta PUT con Digest

NOTE: '' line wrapping per RFC 8792

HTTP/1.1 200 OK
Content-Type: application/json
Content-Encoding: br
Content-Location: /items/123
Repr-Digest: \
sha-256=:d435Qo+nKZ+gLcUHn7GQtQ72hiBVAgqoLsZnZPiTGPk=:,\
sha-512=:db7fdBbgZMgX1Wb2MjA8zZj+rSNgfmDCEEXM8qLWfpfoNY0sCpHAzZbj\
09X1/7HAb7Od5Qfto4QpuBsFbUO3dQ==:

8B 08 80 7B 22 68 65 6C 6C 6F
22 3A 20 22 77 6F 72 6C 64 22
7D 0A 03

Figure 21: Response with Digest of Encoded Content

Figura 21: Risposta con Digest del contenuto codificato

B.7. La risposta POST non fa riferimento all'URI della richiesta

The request Repr-Digest field-value is computed on the enclosed representation (see Section 3.1), which is the JSON object {"title": "New Title"} followed by an LF.

Il valore del campo Repr-Digest della richiesta è calcolato sulla rappresentazione inclusa (vedere Sezione 3.1), che è l'oggetto JSON {"title": "New Title"} seguito da un LF.

The representation enclosed in the response is a multiline JSON object followed by an LF. It refers to the resource identified by Content-Location (see Section 6.4.2 of [HTTP]); thus, an application can use Repr-Digest in association with the resource referenced by Content-Location.

La rappresentazione inclusa nella risposta è un oggetto JSON multilinea seguito da un LF. Si riferisce alla risorsa identificata da Content-Location (vedere Sezione 6.4.2 di [HTTP]); quindi, un'applicazione può utilizzare Repr-Digest in associazione con la risorsa referenziata da Content-Location.

POST /books HTTP/1.1
Host: foo.example
Content-Type: application/json
Accept: application/json
Accept-Encoding: identity
Repr-Digest: sha-256=:mEkdbO7Srd9LIOegftO0aBX+VPTVz7/CSHes2Z27gc4=:

{"title": "New Title"}

Figure 22: POST Request with Digest

Figura 22: Richiesta POST con Digest

HTTP/1.1 201 Created
Content-Type: application/json
Content-Location: /books/123
Location: /books/123
Repr-Digest: sha-256=:uVSlinTTdQUwm2On4k8TJUikGN1bf/Ds8WPX4oe0h9I=:

{
"id": "123",
"title": "New Title"
}

Figure 23: Response with Digest of Resource

Figura 23: Risposta con Digest della risorsa

B.8. La risposta POST descrive lo stato della richiesta

The request Repr-Digest field-value is computed on the enclosed representation (see Section 3.1), which is the JSON object {"title": "New Title"} followed by an LF.

Il valore del campo Repr-Digest della richiesta è calcolato sulla rappresentazione inclusa (vedere Sezione 3.1), che è l'oggetto JSON {"title": "New Title"} seguito da un LF.

The representation enclosed in the response describes the status of the request, so Repr-Digest is computed on that enclosed representation. It is a multiline JSON object followed by an LF.

La rappresentazione inclusa nella risposta descrive lo stato della richiesta, quindi Repr-Digest è calcolato su quella rappresentazione inclusa. È un oggetto JSON multilinea seguito da un LF.

Response Repr-Digest has no explicit relation with the resource referenced by Location.

La risposta Repr-Digest non ha alcuna relazione esplicita con la risorsa referenziata da Location.

POST /books HTTP/1.1
Host: foo.example
Content-Type: application/json
Accept: application/json
Accept-Encoding: identity
Repr-Digest: sha-256=:mEkdbO7Srd9LIOegftO0aBX+VPTVz7/CSHes2Z27gc4=:

{"title": "New Title"}

Figure 24: POST Request with Digest

Figura 24: Richiesta POST con Digest

HTTP/1.1 201 Created
Content-Type: application/json
Repr-Digest: sha-256=:yXIGDTN5VrfoyisKlXgRKUHHMs35SNtyC3szSz1dbO8=:
Location: /books/123

{
"status": "created",
"id": "123",
"ts": 1569327729,
"instance": "/books/123"
}

Figure 25: Response with Digest of Representation

Figura 25: Risposta con Digest della rappresentazione

B.9. Digest con PATCH

This case is analogous to a POST request where the target resource reflects the target URI.

Questo caso è analogo a una richiesta POST in cui la risorsa di destinazione riflette l'URI di destinazione.

The PATCH request uses the application/merge-patch+json media type defined in [RFC7396]. Repr-Digest is calculated on the content that corresponds to the patch document and is the JSON object {"title": "New Title"} followed by an LF.

La richiesta PATCH utilizza il tipo di supporto application/merge-patch+json definito in [RFC7396]. Repr-Digest è calcolato sul contenuto che corrisponde al documento di patch ed è l'oggetto JSON {"title": "New Title"} seguito da un LF.

The response Repr-Digest field-value is computed on the complete representation of the patched resource. It is a multiline JSON object followed by an LF.

Il valore del campo Repr-Digest della risposta è calcolato sulla rappresentazione completa della risorsa patchata. È un oggetto JSON multilinea seguito da un LF.

PATCH /books/123 HTTP/1.1
Host: foo.example
Content-Type: application/merge-patch+json
Accept: application/json
Accept-Encoding: identity
Repr-Digest: sha-256=:mEkdbO7Srd9LIOegftO0aBX+VPTVz7/CSHes2Z27gc4=:

{"title": "New Title"}

Figure 26: PATCH Request with Digest

Figura 26: Richiesta PATCH con Digest

HTTP/1.1 200 OK
Content-Type: application/json
Repr-Digest: sha-256=:uVSlinTTdQUwm2On4k8TJUikGN1bf/Ds8WPX4oe0h9I=:

{
"id": "123",
"title": "New Title"
}

Figure 27: Response with Digest of Representation

Figura 27: Risposta con Digest della rappresentazione

Note that a 204 No Content response without content, but with the same Repr-Digest field-value, would have been legitimate too. In that case, Content-Digest would have been computed on an empty content.

Si noti che anche una risposta 204 No Content senza contenuto, ma con lo stesso valore del campo Repr-Digest, sarebbe stata legittima. In quel caso, Content-Digest sarebbe stato calcolato su un contenuto vuoto.

B.10. Risposte di errore

In error responses, the representation data does not necessarily refer to the target resource. Instead, it refers to the representation of the error.

Nelle risposte di errore, i dati di rappresentazione non si riferiscono necessariamente alla risorsa di destinazione. Invece, si riferiscono alla rappresentazione dell'errore.

In the following example, a client sends the same request from Figure 26 to patch the resource located at /books/123. However, the resource does not exist and the server generates a 404 response with a body that describes the error in accordance with [RFC9457].

Nell'esempio seguente, un client invia la stessa richiesta della Figura 26 per patchare la risorsa situata su /books/123. Tuttavia, la risorsa non esiste e il server genera una risposta 404 con un corpo che descrive l'errore in conformità con [RFC9457].

The response Repr-Digest field-value is computed on this enclosed representation. It is a multiline JSON object followed by an LF.

Il valore del campo Repr-Digest della risposta è calcolato su questa rappresentazione inclusa. È un oggetto JSON multilinea seguito da un LF.

HTTP/1.1 404 Not Found
Content-Type: application/problem+json
Repr-Digest: sha-256=:EXB0S2VF2H7ijkAVJkH1Sm0pBho0iDZcvVUHHXTTZSA=:

{
"title": "Not Found",
"detail": "Cannot PATCH a non-existent resource",
"status": 404
}

Figure 28: Response with Digest of Error Representation

Figura 28: Risposta con Digest della rappresentazione dell'errore

B.11. Utilizzo con campi trailer e codifica di trasferimento

An origin server sends Repr-Digest as trailer field, so it can calculate digest-value while streaming content and thus mitigate resource consumption. The Repr-Digest field-value is the same as in Appendix B.1 because Repr-Digest is designed to be independent of the use of one or more transfer codings (see Section 3).

Un server di origine invia Repr-Digest come campo trailer, in modo che possa calcolare il valore del digest durante lo streaming del contenuto e quindi mitigare il consumo di risorse. Il valore del campo Repr-Digest è lo stesso di Appendice B.1 perché Repr-Digest è progettato per essere indipendente dall'uso di una o più codifiche di trasferimento (vedere Sezione 3).

In the response content below, the string "\r\n" represents the CRLF bytes.

Nel contenuto della risposta qui sotto, la stringa "\r\n" rappresenta i byte CRLF.

GET /items/123 HTTP/1.1
Host: foo.example

Figure 29: GET Request

Figura 29: Richiesta GET

NOTE: '' line wrapping per RFC 8792

HTTP/1.1 200 OK
Content-Type: application/json
Transfer-Encoding: chunked
Trailer: Repr-Digest

8\r\n
{"hello"\r\n
8\r\n
: "world\r\n
3\r\n
"}\n\r\n
0\r\n
Repr-Digest: \
sha-256=:RK/0qy18MlBSVnWgjwz6lZEWjP/lF5HF9bvEF8FabDg==:\r\n

Figure 30: Chunked Response with Digest

Figura 30: Risposta chunked con Digest