Skip to content

Commit

Permalink
Merge pull request #259 from superfly/sub-hash
Browse files Browse the repository at this point in the history
corro-client: expose subscription hash to the clients
  • Loading branch information
pborzenkov authored Sep 17, 2024
2 parents e35acab + 0f8446a commit 30b65ba
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
11 changes: 11 additions & 0 deletions crates/corro-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,14 @@ impl CorrosionApiClient {
.get(HeaderName::from_static("corro-query-id"))
.and_then(|v| v.to_str().ok().and_then(|v| v.parse().ok()))
.ok_or(Error::ExpectedQueryId)?;
let hash = res
.headers()
.get(HeaderName::from_static("corro-query-hash"))
.and_then(|v| v.to_str().map(ToOwned::to_owned).ok());

Ok(SubscriptionStream::new(
id,
hash,
self.api_client.clone(),
self.api_addr,
res.into_body(),
Expand Down Expand Up @@ -189,8 +194,14 @@ impl CorrosionApiClient {
return Err(Error::UnexpectedStatusCode(res.status()));
}

let hash = res
.headers()
.get(HeaderName::from_static("corro-query-hash"))
.and_then(|v| v.to_str().map(ToOwned::to_owned).ok());

Ok(SubscriptionStream::new(
id,
hash,
self.api_client.clone(),
self.api_addr,
res.into_body(),
Expand Down
7 changes: 7 additions & 0 deletions crates/corro-client/src/sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type FramedBody = FramedRead<IoBodyStreamReader, LinesBytesCodec>;

pub struct SubscriptionStream<T> {
id: Uuid,
hash: Option<String>,
client: hyper::Client<HttpConnector, Body>,
api_addr: SocketAddr,
observed_eoq: bool,
Expand Down Expand Up @@ -91,13 +92,15 @@ where
{
pub fn new(
id: Uuid,
hash: Option<String>,
client: hyper::Client<HttpConnector, Body>,
api_addr: SocketAddr,
body: hyper::Body,
change_id: Option<ChangeId>,
) -> Self {
Self {
id,
hash,
client,
api_addr,
observed_eoq: change_id.is_some(),
Expand All @@ -117,6 +120,10 @@ where
self.id
}

pub fn hash(&self) -> Option<&str> {
self.hash.as_deref()
}

pub fn api_addr(&self) -> SocketAddr {
self.api_addr
}
Expand Down

0 comments on commit 30b65ba

Please sign in to comment.