Skip to content

Commit 63444a0

Browse files
author
Devdutt Shenoi
authored
feat(rumqttc): only expect "mqtt" in response header (#729)
1 parent b59e018 commit 63444a0

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

rumqttc/src/websockets.rs

+7-12
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,17 @@ pub enum ValidationError {
2323
pub(crate) fn validate_response_headers(
2424
response: Response<Option<Vec<u8>>>,
2525
) -> Result<(), ValidationError> {
26-
let val = response
26+
let subprotocol = response
2727
.headers()
2828
.get("Sec-WebSocket-Protocol")
29-
.ok_or(ValidationError::SubprotocolHeaderMissing)?;
29+
.ok_or(ValidationError::SubprotocolHeaderMissing)?
30+
.to_str()?;
3031

31-
let subprotocols = val.to_str()?;
32-
33-
// In Sec-WebSocket-Protocol header
34-
// multiple subprotocols can be listed in a comma-delimited format
35-
// e.g. Sec-WebSocket-Protocol: mqtt, chat
36-
if !subprotocols
37-
.split(',')
38-
.any(|protocol| protocol.trim() == "mqtt")
39-
{
32+
// Server must respond with Sec-WebSocket-Protocol header value of "mqtt"
33+
// https://http.dev/ws#sec-websocket-protocol
34+
if subprotocol.trim() != "mqtt" {
4035
return Err(ValidationError::SubprotocolMqttMissing(
41-
subprotocols.to_owned(),
36+
subprotocol.to_owned(),
4237
));
4338
}
4439

0 commit comments

Comments
 (0)