Fix net.serve no longer accepting ipv6

This commit is contained in:
Filip Tibell 2024-04-18 20:56:40 +02:00
parent 03c773fd79
commit 4a28499aaa
No known key found for this signature in database

View file

@ -1,4 +1,7 @@
use std::{collections::HashMap, net::Ipv4Addr}; use std::{
collections::HashMap,
net::{IpAddr, Ipv4Addr},
};
use mlua::prelude::*; use mlua::prelude::*;
@ -6,7 +9,7 @@ use reqwest::Method;
use super::util::table_to_hash_map; use super::util::table_to_hash_map;
const DEFAULT_IP_ADDRESS: Ipv4Addr = Ipv4Addr::new(127, 0, 0, 1); const DEFAULT_IP_ADDRESS: IpAddr = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1));
const WEB_SOCKET_UPDGRADE_REQUEST_HANDLER: &str = r#" const WEB_SOCKET_UPDGRADE_REQUEST_HANDLER: &str = r#"
return { return {
@ -155,7 +158,7 @@ impl FromLua<'_> for RequestConfig {
#[derive(Debug)] #[derive(Debug)]
pub struct ServeConfig<'a> { pub struct ServeConfig<'a> {
pub address: Ipv4Addr, pub address: IpAddr,
pub handle_request: LuaFunction<'a>, pub handle_request: LuaFunction<'a>,
pub handle_web_socket: Option<LuaFunction<'a>>, pub handle_web_socket: Option<LuaFunction<'a>>,
} }
@ -175,7 +178,7 @@ impl<'lua> FromLua<'lua> for ServeConfig<'lua> {
let handle_request: Option<LuaFunction> = t.get("handleRequest")?; let handle_request: Option<LuaFunction> = t.get("handleRequest")?;
let handle_web_socket: Option<LuaFunction> = t.get("handleWebSocket")?; let handle_web_socket: Option<LuaFunction> = t.get("handleWebSocket")?;
if handle_request.is_some() || handle_web_socket.is_some() { if handle_request.is_some() || handle_web_socket.is_some() {
let address: Ipv4Addr = match &address { let address: IpAddr = match &address {
Some(addr) => { Some(addr) => {
let addr_str = addr.to_str()?; let addr_str = addr.to_str()?;