pub struct ClientSpecifiesVersionInHeader { /* private fields */ }Expand description
Implementation of DynamicVersionPolicy where the client specifies a
specific semver in a specific header and we always use whatever they
requested.
An incoming request will be rejected with a 400-level error if:
- the header value cannot be parsed as a semver, or
- the requested version is newer than
max_version(seeClientSpecifiesVersionInHeader::new(), which implies that the client is trying to use a newer version of the API than this server supports.
By default, incoming requests will also be rejected with a 400-level error
if the header is missing. To override this behavior, supply a default
version via Self::on_missing.
If you need anything more flexible (e.g., validating the provided version
against a fixed set of supported versions), you’ll want to impl
DynamicVersionPolicy yourself.
Implementations§
Source§impl ClientSpecifiesVersionInHeader
impl ClientSpecifiesVersionInHeader
Sourcepub fn new(
name: HeaderName,
max_version: Version,
) -> ClientSpecifiesVersionInHeader
pub fn new( name: HeaderName, max_version: Version, ) -> ClientSpecifiesVersionInHeader
Make a new ClientSpecifiesVersionInHeader policy.
Arguments:
name: name of the header that the client will use to specify the versionmax_version: the maximum version of the API that this server supports. Requests for a version newer than this will be rejected with a 400-level error.
Sourcepub fn on_missing(self, version: Version) -> Self
pub fn on_missing(self, version: Version) -> Self
If the header is missing, use the provided version instead.
By default, the policy will reject requests with a missing header. Call this function to use the provided version instead.
Typically, the provided version should either be a fixed supported version (for backwards compatibility with older clients), or the newest supported version (in case clients are generally kept up-to-date but not all clients send the header).
Using this function is not recommended if you control all clients—in that case, arrange for clients to send the header instead. In particular, at Oxide, do not use this function for internal APIs.