Edit this page

up.protocol X-Up-Context
HTTP header

This feature is experimental. It may be changed or removed in a future version.

This request header contains the targeted layer's context, serialized as JSON.

The user may choose to not send this header by configuring up.network.config.requestMetaKeys.

Example

X-Up-Context: { "lives": 3 }

Updating context from the server

The server may update the layer context by sending a X-Up-Context response header with changed key/value pairs:

Content-Type: text/html
X-Up-Context: { "lives": 2 }

<html>
  ...
</html>

Upon seeing the response header, Unpoly will assign the server-provided context object to the layer's context object, adding or replacing keys as needed.

Client-side context keys not mentioned in the response will remain unchanged. There is no explicit protocol to remove keys from the context, but the server may send a key with a null value to effectively remove a key.

The frontend will use the server-provided context upates for both successful (HTTP status 200 OK) and failed (status 4xx or 5xx) responses. If no X-Up-Context response header is set, the updating layer's context will not be changed.

It is recommended that the server only places changed key/value pairs into the X-Up-Context response header, and not echo the entire context object. Otherwise any client-side changes made while the request was in flight will get overridden by the server-provided context.

This website uses cookies to improve usability and analyze traffic.
I accept or learn more