[go: up one dir, main page]

RPC: add [if-none-match] middleware

What

This MR adds a handler for the if-none-match header. Description from MSDN:

The If-None-Match HTTP request header makes the request conditional. For GET and HEAD methods, the server will return the requested resource, with a 200 status, only if it doesn't have an ETag matching the given ones. ... When the condition fails for GET and HEAD methods, then the server must return HTTP status code 304 (Not Modified)

Why

The if-none-match header allows Cache servers to validate their cache before needing to recalculate large values. In combination with max-age, this header is useful for re-using cached responses when the node is out of sync.

How

There are 2 main changes that need to be done in this MR.

  1. Add ETag to each response - ETag is set to the block hash as it naturally identifies the resource. The block hash is obtained by capturing the block argument portion of the URL then getting the block hash from the get_block_hash function exposed in Http_cacher_header tools. The ETag field will be set for all successful responses of head query.
  2. Handle if-none-match header - If block hash of the reference query is not in the list of if-none-match block hashes, then the callback is called like normal. If the block hash is in the list of if-none-match block hashes, then the middleware returns a 304 not modified instead.

Tezt

dune exec tezt/tests/main.exe -- --file http_cache_headers.ml

Manually testing the MR

Follow Manual Testing steps in !13787

Performance

Metric With feature Without feature
health-1-th 3910.2 4142.4
health-10-th 5400.19 5916.41
header-1-th 3720 4235.38
header-10-th 5077.49 6038.69
baking-1-th 690.66 721.45
baking-10-th 754.45 783.96
attestation-1-th 91.32 94.6
attestation-10-th 93.75 96.12
Edited by Ryan Tan

Merge request reports

Loading