mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-02-28 12:48:17 -05:00
Compare commits
1 Commits
codex/cli-
...
v2026.3.0-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3a6630a14d |
@@ -1,9 +1,14 @@
|
|||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use std::net::TcpListener;
|
use std::net::{SocketAddr, TcpListener, TcpStream};
|
||||||
|
use std::sync::Arc;
|
||||||
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
pub struct TestHttpServer {
|
pub struct TestHttpServer {
|
||||||
pub url: String,
|
pub url: String,
|
||||||
|
addr: SocketAddr,
|
||||||
|
shutdown: Arc<AtomicBool>,
|
||||||
handle: Option<thread::JoinHandle<()>>,
|
handle: Option<thread::JoinHandle<()>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -12,29 +17,46 @@ impl TestHttpServer {
|
|||||||
let listener = TcpListener::bind("127.0.0.1:0").expect("Failed to bind test HTTP server");
|
let listener = TcpListener::bind("127.0.0.1:0").expect("Failed to bind test HTTP server");
|
||||||
let addr = listener.local_addr().expect("Failed to get local addr");
|
let addr = listener.local_addr().expect("Failed to get local addr");
|
||||||
let url = format!("http://{addr}/test");
|
let url = format!("http://{addr}/test");
|
||||||
|
listener.set_nonblocking(true).expect("Failed to set test server listener nonblocking");
|
||||||
|
|
||||||
|
let shutdown = Arc::new(AtomicBool::new(false));
|
||||||
|
let shutdown_signal = Arc::clone(&shutdown);
|
||||||
let body_bytes = body.as_bytes().to_vec();
|
let body_bytes = body.as_bytes().to_vec();
|
||||||
|
|
||||||
let handle = thread::spawn(move || {
|
let handle = thread::spawn(move || {
|
||||||
if let Ok((mut stream, _)) = listener.accept() {
|
while !shutdown_signal.load(Ordering::Relaxed) {
|
||||||
let mut request_buf = [0u8; 4096];
|
match listener.accept() {
|
||||||
let _ = stream.read(&mut request_buf);
|
Ok((mut stream, _)) => {
|
||||||
|
let _ = stream.set_read_timeout(Some(Duration::from_secs(1)));
|
||||||
|
let mut request_buf = [0u8; 4096];
|
||||||
|
let _ = stream.read(&mut request_buf);
|
||||||
|
|
||||||
let response = format!(
|
let response = format!(
|
||||||
"HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: {}\r\nConnection: close\r\n\r\n",
|
"HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: {}\r\nConnection: close\r\n\r\n",
|
||||||
body_bytes.len()
|
body_bytes.len()
|
||||||
);
|
);
|
||||||
let _ = stream.write_all(response.as_bytes());
|
let _ = stream.write_all(response.as_bytes());
|
||||||
let _ = stream.write_all(&body_bytes);
|
let _ = stream.write_all(&body_bytes);
|
||||||
let _ = stream.flush();
|
let _ = stream.flush();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Err(err) if err.kind() == std::io::ErrorKind::WouldBlock => {
|
||||||
|
thread::sleep(Duration::from_millis(10));
|
||||||
|
}
|
||||||
|
Err(_) => break,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self { url, handle: Some(handle) }
|
Self { url, addr, shutdown, handle: Some(handle) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for TestHttpServer {
|
impl Drop for TestHttpServer {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
|
self.shutdown.store(true, Ordering::Relaxed);
|
||||||
|
let _ = TcpStream::connect(self.addr);
|
||||||
|
|
||||||
if let Some(handle) = self.handle.take() {
|
if let Some(handle) = self.handle.take() {
|
||||||
let _ = handle.join();
|
let _ = handle.join();
|
||||||
}
|
}
|
||||||
|
|||||||
4
crates/yaak-templates/pkg/yaak_templates.d.ts
generated
vendored
4
crates/yaak-templates/pkg/yaak_templates.d.ts
generated
vendored
@@ -1,5 +1,5 @@
|
|||||||
/* tslint:disable */
|
/* tslint:disable */
|
||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
export function unescape_template(template: string): any;
|
|
||||||
export function parse_template(template: string): any;
|
|
||||||
export function escape_template(template: string): any;
|
export function escape_template(template: string): any;
|
||||||
|
export function parse_template(template: string): any;
|
||||||
|
export function unescape_template(template: string): any;
|
||||||
|
|||||||
8
crates/yaak-templates/pkg/yaak_templates_bg.js
generated
8
crates/yaak-templates/pkg/yaak_templates_bg.js
generated
@@ -165,10 +165,10 @@ function takeFromExternrefTable0(idx) {
|
|||||||
* @param {string} template
|
* @param {string} template
|
||||||
* @returns {any}
|
* @returns {any}
|
||||||
*/
|
*/
|
||||||
export function unescape_template(template) {
|
export function escape_template(template) {
|
||||||
const ptr0 = passStringToWasm0(template, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
const ptr0 = passStringToWasm0(template, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
||||||
const len0 = WASM_VECTOR_LEN;
|
const len0 = WASM_VECTOR_LEN;
|
||||||
const ret = wasm.unescape_template(ptr0, len0);
|
const ret = wasm.escape_template(ptr0, len0);
|
||||||
if (ret[2]) {
|
if (ret[2]) {
|
||||||
throw takeFromExternrefTable0(ret[1]);
|
throw takeFromExternrefTable0(ret[1]);
|
||||||
}
|
}
|
||||||
@@ -193,10 +193,10 @@ export function parse_template(template) {
|
|||||||
* @param {string} template
|
* @param {string} template
|
||||||
* @returns {any}
|
* @returns {any}
|
||||||
*/
|
*/
|
||||||
export function escape_template(template) {
|
export function unescape_template(template) {
|
||||||
const ptr0 = passStringToWasm0(template, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
const ptr0 = passStringToWasm0(template, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
||||||
const len0 = WASM_VECTOR_LEN;
|
const len0 = WASM_VECTOR_LEN;
|
||||||
const ret = wasm.escape_template(ptr0, len0);
|
const ret = wasm.unescape_template(ptr0, len0);
|
||||||
if (ret[2]) {
|
if (ret[2]) {
|
||||||
throw takeFromExternrefTable0(ret[1]);
|
throw takeFromExternrefTable0(ret[1]);
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
crates/yaak-templates/pkg/yaak_templates_bg.wasm
generated
BIN
crates/yaak-templates/pkg/yaak_templates_bg.wasm
generated
Binary file not shown.
Reference in New Issue
Block a user