Hi, I'm trying to understand how to add and access custom protocols with wry on Windows. I want to use them to more efficiently reimplement tauri::command by using a binary protocol for data transfer.
I seem to have grasped how to implement and add a protocol:
fn custom_protocol(
_req: wry::http::request::Request<Vec<u8>>,
) -> wry::http::response::Response<Cow<'static, [u8]>> {
let resp = wry::http::response::Response::builder()
.status(wry::http::status::StatusCode::OK)
.header(
wry::http::header::ACCESS_CONTROL_ALLOW_ORIGIN,
wry::http::HeaderValue::from_static("*"),
)
.body(Cow::<'static, [u8]>::Borrowed(b"Hello, world!"))
.unwrap();
resp
}
fn main() {
// ...
let _webview = WebViewBuilder::new(&window)
.with_url(&format!("http://localhost:{port}/"))?
.with_custom_protocol("my_proto".to_string(), custom_protocol)
.build()?;
// ...
}
However, I'm struggling to access the protocol data (on Windows).
I opened the console in the dev tools of the wry app (on Windows) and tried the following
function reqListener () {
console.log(this.responseText);
}
var oReq = new XMLHttpRequest();
oReq.addEventListener("load", reqListener);
oReq.open("GET", "http://my_proto.");
oReq.send();
Error:
GET http://my_proto./ net::ERR_NAME_NOT_RESOLVED