-
Notifications
You must be signed in to change notification settings - Fork 10
Add VssClient::get_version
#61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,8 @@ const CONTENT_TYPE: &str = "content-type"; | |
| const DEFAULT_TIMEOUT_SECS: u64 = 10; | ||
| const MAX_RESPONSE_BODY_SIZE: usize = 1024 * 1024 * 1024; // 1GB | ||
| const DEFAULT_CLIENT_CAPACITY: usize = 10; | ||
| const PROTOCOL_VERSION_HEADER: &str = "vss-protocol-version"; | ||
| const PROTOCOL_VERSION: &str = "0"; | ||
|
|
||
| /// Thin-client to access a hosted instance of Versioned Storage Service (VSS). | ||
| /// The provided [`VssClient`] API is minimalistic and is congruent to the VSS server-side API. | ||
|
|
@@ -212,6 +214,16 @@ impl<R: RetryPolicy<E = VssError>> VssClient<R> { | |
| } | ||
|
|
||
| let response = self.client.send_async(http_request).await?; | ||
| // Return early in case of version mismatch, this issue must be solved first. | ||
| if response.headers.get(PROTOCOL_VERSION_HEADER).map(String::as_str) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need / want to maintain backwards compatibility, i.e., interpret absence of the versioning field as version 0? Or intentionally not?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we remain backwards compatible, then we could break the upcoming That is why I think the VSS client should reject any VSS servers that don't set the version header.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll sleep on it, strict equality may be too restrictive. That being said in the future, we could ship version 2 in |
||
| != Some(PROTOCOL_VERSION) | ||
| { | ||
| let mut response = response; | ||
| return Err(VssError::VSSVersionMismatchError { | ||
| version_served: response.headers.remove(PROTOCOL_VERSION_HEADER), | ||
| version_expected: String::from(PROTOCOL_VERSION), | ||
| }); | ||
| } | ||
|
|
||
| let status_code = response.status_code; | ||
| let payload = response.into_bytes(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,14 @@ pub enum VssError { | |
| /// There is an unknown error, it could be a client-side bug, unrecognized error-code, network error | ||
| /// or something else. | ||
| InternalError(String), | ||
|
|
||
| /// The VSS server and client speak different versions of the VSS protocol | ||
| VSSVersionMismatchError { | ||
| /// The VSS protocol version served | ||
| version_served: Option<String>, | ||
| /// The VSS protocol version expected | ||
| version_expected: String, | ||
| }, | ||
| } | ||
|
|
||
| impl VssError { | ||
|
|
@@ -62,6 +70,21 @@ impl Display for VssError { | |
| VssError::InternalServerError(message) => { | ||
| write!(f, "InternalServerError: {}", message) | ||
| }, | ||
| VssError::VSSVersionMismatchError { | ||
| version_served: Some(served), | ||
| version_expected, | ||
| } => { | ||
| write!( | ||
| f, | ||
| "The VSS server and client speak different versions of the \ | ||
| VSS protocol, the server serves version {}, client expects \ | ||
| {}", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, do we need to sanitize this string before printing or bubbling up the error, or are we expecting this to happen at a higher level anyways?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm thank you yes, I'm thinking we keep validation here minimal and just report the mismatch, together with the different header values ? So as to keep |
||
| served, version_expected, | ||
| ) | ||
| }, | ||
| VssError::VSSVersionMismatchError { version_served: None, version_expected: _ } => { | ||
| write!(f, "The server did not set the `vss-protocol-version` header") | ||
| }, | ||
| VssError::InternalError(message) => { | ||
| write!(f, "InternalError: {}", message) | ||
| }, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While doing this on the server is fine, here I'd not want to do it until we have a better solution in place. Maybe we should go through with merging repos now that both are rust codebases, or have both depend on a shared
vss-protocrate, to ensure version compat?