Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/lune-std-net/src/client/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use hyper::{
use url::Url;

use crate::{
client::http_stream::HttpStream,
client::stream::HttpStream,
shared::{hyper::HyperIo, request::Request, response::Response},
};

Expand Down Expand Up @@ -86,7 +86,7 @@ async fn fetch_inner(
mut request: Request,
) -> Result<Response, String> {
loop {
let stream = HttpStream::connect(url.clone())
let stream = HttpStream::connect_url(url.clone())
.await
.map_err(|e| e.to_string())?;

Expand Down
95 changes: 0 additions & 95 deletions crates/lune-std-net/src/client/http_stream.rs

This file was deleted.

30 changes: 25 additions & 5 deletions crates/lune-std-net/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ use url::Url;

use crate::{
body::ReadableBody,
client::ws_stream::WsStream,
shared::{request::Request, websocket::Websocket},
client::{
stream::{MaybeTlsStream, WsStream},
tcp::TcpConfig,
},
shared::{request::Request, tcp::Tcp, websocket::Websocket},
};

pub mod http_stream;
pub mod rustls;
pub mod ws_stream;
pub mod stream;
pub mod tcp;

mod fetch;
mod send;
Expand All @@ -25,10 +28,27 @@ const MAX_REDIRECTS: usize = 10;
Connects to a websocket at the given URL.
*/
pub async fn connect_websocket(url: Url) -> LuaResult<Websocket<WsStream>> {
let stream = WsStream::connect(url).await?;
let stream = WsStream::connect_url(url).await?;
Ok(Websocket::from(stream))
}

/**
Connects using plain TCP using the given host, port, and config.
*/
pub async fn connect_tcp(host: String, port: u16, config: TcpConfig) -> LuaResult<Tcp> {
let tls = config.tls.unwrap_or_default();

let stream = MaybeTlsStream::connect(&host, port, tls)
.await
.into_lua_err()?;

if let Some(ttl) = config.ttl {
stream.set_ttl(ttl).into_lua_err()?;
}

Ok(Tcp::from(stream))
}

fn try_follow_redirect(
url: &mut Url,
request: &mut Request,
Expand Down
4 changes: 2 additions & 2 deletions crates/lune-std-net/src/client/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use mlua::prelude::*;
use url::Url;

use crate::{
client::http_stream::HttpStream,
client::stream::HttpStream,
shared::{
headers::create_user_agent_header,
hyper::{HyperExecutor, HyperIo},
Expand Down Expand Up @@ -51,7 +51,7 @@ pub async fn send(mut request: Request, lua: Lua) -> LuaResult<Response> {

// ... we can now safely continue and send the request
loop {
let stream = HttpStream::connect(url.clone()).await?;
let stream = HttpStream::connect_url(url.clone()).await?;

let (mut sender, conn) = handshake(HyperIo::from(stream)).await.into_lua_err()?;

Expand Down
Loading
Loading