Skip to content

Commit

Permalink
Merge pull request #161 from nats-io/tyler_error_on_unsupported_heade…
Browse files Browse the repository at this point in the history
…r_publish

error on unsupported header publish. Closes #159. Closes #160.
  • Loading branch information
spacejam authored Mar 22, 2021
2 parents e3fb52d + 9cee09b commit 7ffd1fa
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# 0.9.8

## Bug Fixes

- #161 When attempting to send a message with headers
to a server that does not support headers, an error
is now properly returned instead of silently dropping
the message.

# 0.9.7

## Improvements
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nats"
version = "0.9.7"
version = "0.9.8"
description = "A Rust NATS client"
authors = ["Derek Collison <[email protected]>", "Tyler Neely <[email protected]>", "Stjepan Glavina <[email protected]>"]
edition = "2018"
Expand Down
4 changes: 2 additions & 2 deletions async-nats/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "async-nats"
version = "0.9.7"
version = "0.9.8"
description = "An async Rust NATS client"
authors = ["Derek Collison <[email protected]>", "Tyler Neely <[email protected]>", "Stjepan Glavina <[email protected]>"]
edition = "2018"
Expand All @@ -17,7 +17,7 @@ maintenance = { status = "actively-developed" }

[dependencies]
blocking = "1.0.2"
nats = { path = "..", version = "0.9.7" }
nats = { path = "..", version = "0.9.8" }

[dev-dependencies]
smol = "1.2.5"
Expand Down
9 changes: 9 additions & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,15 @@ impl Client {
// Inject random delays when testing.
inject_delay();

if headers.is_some()
&& !self.server_info.lock().as_ref().unwrap().headers
{
return Err(Error::new(
ErrorKind::InvalidInput,
"the server does not support headers",
));
}

let mut state = self.state.lock();

// Check if the client is closed.
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ struct ServerInfo {
pub connect_urls: Vec<String>,
/// The client IP as known by the server.
pub client_ip: String,
/// Whether the server supports headers.
pub headers: bool,
}

impl ServerInfo {
Expand All @@ -295,6 +297,7 @@ impl ServerInfo {
.filter_map(|m| m.take_string())
.collect(),
client_ip: obj["client_ip"].take_string().unwrap_or_default(),
headers: obj["headers"].as_bool().unwrap_or(false),
})
}
}
Expand Down

0 comments on commit 7ffd1fa

Please sign in to comment.