Skip to content

Commit

Permalink
Port deno_websocket
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Oct 19, 2021
1 parent 211a897 commit 0a0c463
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 43 deletions.
50 changes: 18 additions & 32 deletions Cargo.lock

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

10 changes: 8 additions & 2 deletions ext/websocket/Cargo.toml
Expand Up @@ -20,5 +20,11 @@ http = "0.2.4"
hyper = { version = "0.14.12" }
serde = { version = "1.0.129", features = ["derive"] }
tokio = { version = "1.10.1", features = ["full"] }
tokio-rustls = "0.22.0"
tokio-tungstenite = { version = "0.14.0", features = ["rustls-tls"] }
tokio-rustls = "0.23.0"

[dependencies.tokio-tungstenite]
version = "0.15.0"
features = ["rustls-tls-webpki-roots"]
# TODO(ry) Waiting for https://github.com/snapview/tokio-tungstenite/pull/198
git = "https://github.com/dnaka91/tokio-tungstenite"
branch = "rustls-0.20"
22 changes: 13 additions & 9 deletions ext/websocket/lib.rs
Expand Up @@ -20,26 +20,29 @@ use deno_core::Resource;
use deno_core::ResourceId;
use deno_core::ZeroCopyBuf;
use deno_tls::create_client_config;
use deno_tls::webpki::DNSNameRef;

use http::{Method, Request, Uri};
use http::Method;
use http::Request;
use http::Uri;
use serde::Deserialize;
use serde::Serialize;
use std::borrow::Cow;
use std::cell::RefCell;
use std::convert::TryFrom;
use std::fmt;
use std::path::PathBuf;
use std::rc::Rc;
use std::sync::Arc;
use tokio::net::TcpStream;
use tokio_rustls::rustls::RootCertStore;
use tokio_rustls::rustls::ServerName;
use tokio_rustls::TlsConnector;
use tokio_tungstenite::tungstenite::{
handshake::client::Response, protocol::frame::coding::CloseCode,
protocol::CloseFrame, Message,
};
use tokio_tungstenite::client_async;
use tokio_tungstenite::tungstenite::handshake::client::Response;
use tokio_tungstenite::tungstenite::protocol::frame::coding::CloseCode;
use tokio_tungstenite::tungstenite::protocol::CloseFrame;
use tokio_tungstenite::tungstenite::protocol::Message;
use tokio_tungstenite::MaybeTlsStream;
use tokio_tungstenite::{client_async, WebSocketStream};
use tokio_tungstenite::WebSocketStream;

pub use tokio_tungstenite; // Re-export tokio_tungstenite

Expand Down Expand Up @@ -244,9 +247,10 @@ where
root_cert_store,
vec![],
unsafely_ignore_certificate_errors,
None,
)?;
let tls_connector = TlsConnector::from(Arc::new(tls_config));
let dnsname = DNSNameRef::try_from_ascii_str(domain)
let dnsname = ServerName::try_from(domain.as_str())
.map_err(|_| invalid_hostname(domain))?;
let tls_socket = tls_connector.connect(dnsname, tcp_socket).await?;
MaybeTlsStream::Rustls(tls_socket)
Expand Down

0 comments on commit 0a0c463

Please sign in to comment.