Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
resilar committed Jun 2, 2019
1 parent 24716c3 commit 7e5066d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 26 deletions.
33 changes: 18 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,12 @@ httparse = "1.3"
hyper = "0.12"
memmap = "0.7"
native-tls = "0.2"
rpassword = "2.1"
rpassword = "3.0"
tokio-core = "0.1"
tokio-io = "0.1"
tokio-tls = "0.2"
tokio-tungstenite = "0.6"
tungstenite = "0.6"

[patch.crates-io]
tungstenite = { git = 'https://github.com/snapview/tungstenite-rs', rev = 'c33f4f3895ccedf1f370b8b675bf980257f6c3f4' }
tokio-tungstenite = "0.8"
tungstenite = "0.8"

[features]
default = ["verbose"]
Expand Down
11 changes: 7 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ use tokio_io::{AsyncRead, AsyncWrite};
use tokio_tungstenite::accept_hdr_async;
use tungstenite::protocol::Message;

use std::borrow::Cow;
use std::cell::RefCell;
use std::convert::From;
use std::env;
Expand Down Expand Up @@ -90,7 +89,7 @@ where I: AsyncRead + AsyncWrite + 'static
fn handle_websocket<I>(io: I, addr: SocketAddr, state: StateRef) -> impl Future<Item=(), Error=()>
where I: AsyncRead + AsyncWrite + 'static
{
use tungstenite::handshake::server::{Callback, Request};
use tungstenite::handshake::server::{Callback, ErrorResponse, Request};

/// Accept connection if WebSocket subprotocol matches self.0 (password).
struct ProtocolChecker(Option<String>);
Expand All @@ -99,7 +98,7 @@ where I: AsyncRead + AsyncWrite + 'static
fn on_request(
self,
req: &Request
) -> Result<Option<Vec<(String, String)>>, tungstenite::Error> {
) -> Result<Option<Vec<(String, String)>>, ErrorResponse> {
let mut protocols = req.headers.iter()
.filter(|(k, _)| k.eq_ignore_ascii_case("Sec-Websocket-Protocol"))
.filter_map(|(_, v)| std::str::from_utf8(v).ok())
Expand All @@ -108,7 +107,11 @@ where I: AsyncRead + AsyncWrite + 'static
if let Some(p) = protocols.find(move |&v| v == protocol) {
Ok(Some(vec![("Sec-Websocket-Protocol".to_string(), p.to_string())]))
} else {
Err(tungstenite::Error::Protocol(Cow::Borrowed("Bad WebSocket subprotocol")))
Err(ErrorResponse {
error_code: StatusCode::FORBIDDEN,
headers: None,
body: Some("Bad WebSocket subprotocol".to_string())
})
}
} else if let Some(p) = protocols.next() {
// Protocol not required but the client provided one.
Expand Down
2 changes: 1 addition & 1 deletion src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl State {
let file_len = fs::metadata(json_path)?.len() as usize;
let size = align_len(file_len);
if file_len != size { file.set_len(size as u64)?; }
let mut mmap = map(&file, size)?;
let mmap = map(&file, size)?;
let len = mmap.iter().position(|&x| x == 0).unwrap_or(size);
(mmap, len, size)
} else {
Expand Down

0 comments on commit 7e5066d

Please sign in to comment.