mirror of
https://github.com/tokio-rs/axum.git
synced 2025-04-26 13:56:22 +02:00
Fix inconsistent naming of WebSocket rejections (#416)
This commit is contained in:
parent
040f63b8e2
commit
e949c47df6
3 changed files with 53 additions and 49 deletions
|
@ -144,6 +144,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
// ...
|
||||
}
|
||||
```
|
||||
- Misc:
|
||||
- `InvalidWebsocketVersionHeader` has been renamed to `InvalidWebSocketVersionHeader` ([#416])
|
||||
- `WebsocketKeyHeaderMissing` has been renamed to `WebSocketKeyHeaderMissing` ([#416])
|
||||
|
||||
[#339]: https://github.com/tokio-rs/axum/pull/339
|
||||
[#286]: https://github.com/tokio-rs/axum/pull/286
|
||||
|
@ -156,6 +159,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
[#405]: https://github.com/tokio-rs/axum/pull/405
|
||||
[#408]: https://github.com/tokio-rs/axum/pull/408
|
||||
[#412]: https://github.com/tokio-rs/axum/pull/412
|
||||
[#416]: https://github.com/tokio-rs/axum/pull/416
|
||||
|
||||
# 0.2.8 (07. October, 2021)
|
||||
|
||||
|
|
|
@ -1,52 +1,52 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Websocket Chat</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Websocket Chat Example</h1>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>WebSocket Chat</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>WebSocket Chat Example</h1>
|
||||
|
||||
<input id="username" style="display:block; width:100px; box-sizing: border-box" type="text" placeholder="username">
|
||||
<button id="join-chat" type="button">Join Chat</button>
|
||||
<textarea id="chat" style="display:block; width:600px; height:400px; box-sizing: border-box" cols="30" rows="10"></textarea>
|
||||
<input id="input" style="display:block; width:600px; box-sizing: border-box" type="text" placeholder="chat">
|
||||
<input id="username" style="display:block; width:100px; box-sizing: border-box" type="text" placeholder="username">
|
||||
<button id="join-chat" type="button">Join Chat</button>
|
||||
<textarea id="chat" style="display:block; width:600px; height:400px; box-sizing: border-box" cols="30" rows="10"></textarea>
|
||||
<input id="input" style="display:block; width:600px; box-sizing: border-box" type="text" placeholder="chat">
|
||||
|
||||
<script>
|
||||
const username = document.querySelector("#username");
|
||||
const join_btn = document.querySelector("#join-chat");
|
||||
const textarea = document.querySelector("#chat");
|
||||
const input = document.querySelector("#input");
|
||||
<script>
|
||||
const username = document.querySelector("#username");
|
||||
const join_btn = document.querySelector("#join-chat");
|
||||
const textarea = document.querySelector("#chat");
|
||||
const input = document.querySelector("#input");
|
||||
|
||||
join_btn.addEventListener("click", function(e) {
|
||||
this.disabled = true;
|
||||
join_btn.addEventListener("click", function(e) {
|
||||
this.disabled = true;
|
||||
|
||||
const websocket = new WebSocket("ws://localhost:3000/websocket");
|
||||
const websocket = new WebSocket("ws://localhost:3000/websocket");
|
||||
|
||||
websocket.onopen = function() {
|
||||
console.log("connection opened");
|
||||
websocket.send(username.value);
|
||||
}
|
||||
websocket.onopen = function() {
|
||||
console.log("connection opened");
|
||||
websocket.send(username.value);
|
||||
}
|
||||
|
||||
const btn = this;
|
||||
const btn = this;
|
||||
|
||||
websocket.onclose = function() {
|
||||
console.log("connection closed");
|
||||
btn.disabled = false;
|
||||
}
|
||||
websocket.onclose = function() {
|
||||
console.log("connection closed");
|
||||
btn.disabled = false;
|
||||
}
|
||||
|
||||
websocket.onmessage = function(e) {
|
||||
console.log("received message: "+e.data);
|
||||
textarea.value += e.data+"\r\n";
|
||||
}
|
||||
websocket.onmessage = function(e) {
|
||||
console.log("received message: "+e.data);
|
||||
textarea.value += e.data+"\r\n";
|
||||
}
|
||||
|
||||
input.onkeydown = function(e) {
|
||||
if (e.key == "Enter") {
|
||||
websocket.send(input.value);
|
||||
input.value = "";
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
input.onkeydown = function(e) {
|
||||
if (e.key == "Enter") {
|
||||
websocket.send(input.value);
|
||||
input.value = "";
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -209,7 +209,7 @@ where
|
|||
}
|
||||
|
||||
if !header_eq(req, header::SEC_WEBSOCKET_VERSION, "13")? {
|
||||
return Err(InvalidWebsocketVersionHeader.into());
|
||||
return Err(InvalidWebSocketVersionHeader.into());
|
||||
}
|
||||
|
||||
let sec_websocket_key = if let Some(key) = req
|
||||
|
@ -219,7 +219,7 @@ where
|
|||
{
|
||||
key
|
||||
} else {
|
||||
return Err(WebsocketKeyHeaderMissing.into());
|
||||
return Err(WebSocketKeyHeaderMissing.into());
|
||||
};
|
||||
|
||||
let on_upgrade = req
|
||||
|
@ -309,7 +309,7 @@ where
|
|||
} else {
|
||||
return (
|
||||
StatusCode::BAD_REQUEST,
|
||||
"`Sec-Websocket-Protocol` header is invalid",
|
||||
"`Sec-WebSocket-Protocol` header is invalid",
|
||||
)
|
||||
.into_response();
|
||||
}
|
||||
|
@ -578,16 +578,16 @@ pub mod rejection {
|
|||
|
||||
define_rejection! {
|
||||
#[status = BAD_REQUEST]
|
||||
#[body = "`Sec-Websocket-Version` header did not include '13'"]
|
||||
#[body = "`Sec-WebSocket-Version` header did not include '13'"]
|
||||
/// Rejection type for [`WebSocketUpgrade`](super::WebSocketUpgrade).
|
||||
pub struct InvalidWebsocketVersionHeader;
|
||||
pub struct InvalidWebSocketVersionHeader;
|
||||
}
|
||||
|
||||
define_rejection! {
|
||||
#[status = BAD_REQUEST]
|
||||
#[body = "`Sec-Websocket-Key` header missing"]
|
||||
#[body = "`Sec-WebSocket-Key` header missing"]
|
||||
/// Rejection type for [`WebSocketUpgrade`](super::WebSocketUpgrade).
|
||||
pub struct WebsocketKeyHeaderMissing;
|
||||
pub struct WebSocketKeyHeaderMissing;
|
||||
}
|
||||
|
||||
composite_rejection! {
|
||||
|
@ -599,8 +599,8 @@ pub mod rejection {
|
|||
MethodNotGet,
|
||||
InvalidConnectionHeader,
|
||||
InvalidUpgradeHeader,
|
||||
InvalidWebsocketVersionHeader,
|
||||
WebsocketKeyHeaderMissing,
|
||||
InvalidWebSocketVersionHeader,
|
||||
WebSocketKeyHeaderMissing,
|
||||
HeadersAlreadyExtracted,
|
||||
ExtensionsAlreadyExtracted,
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue