Compare commits
2 Commits
cbc05226e0
...
0741768d29
| Author | SHA1 | Date | |
|---|---|---|---|
|
0741768d29
|
|||
|
15bd8076b1
|
@@ -1,3 +1,4 @@
|
||||
use std::time::Duration;
|
||||
use anyhow::Result;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use wasmtime::{Config, Engine, Instance, Linker, Module, Store};
|
||||
@@ -15,6 +16,17 @@ struct JsResult {
|
||||
message: String,
|
||||
}
|
||||
|
||||
pub fn get(url: &str) -> reqwest::Result<reqwest::blocking::Response> {
|
||||
let client = reqwest::blocking::Client::builder()
|
||||
.timeout(Duration::from_secs(8))
|
||||
.connect_timeout(Duration::from_secs(3))
|
||||
// .proxy(reqwest::Proxy::all("http://127.0.0.1:1086").expect("to proxy failed"))
|
||||
.build()?;
|
||||
let request_builder = client.get(url);
|
||||
let request_builder = request_builder.header("X-Custom-Header", "Value");
|
||||
request_builder.send()
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct MyContainer;
|
||||
|
||||
@@ -23,7 +35,7 @@ impl container::Container for MyContainer {
|
||||
println!("fetch arguments: {}", s);
|
||||
let url: String = s.chars().skip(1).take(s.len() - 2).collect();
|
||||
println!("fetch arguments URL: {}", url);
|
||||
let r = match reqwest::blocking::get(&url) {
|
||||
let r = match get(&url) {
|
||||
Err(e) => return serde_json::to_string(&FetchResult {
|
||||
error: Some(serde_json::to_string(&JsResult {
|
||||
message: format!("failed: {}", e)
|
||||
@@ -55,7 +67,7 @@ fn main() -> Result<()> {
|
||||
let a = exports.eval_javascript(&mut store, r##"
|
||||
function hi(name) { return "hi: " + name; }
|
||||
let a = [];
|
||||
a.push(fetch('https://hatter.ink/ip.action'));
|
||||
a.push(fetch('https://hatter.ink/util/print_request.action'));
|
||||
for (let i = 0; i < 3; i++) { a.push(i); }
|
||||
a.push({
|
||||
id: 1, name: 'hatter'
|
||||
@@ -109,6 +121,7 @@ fn default_config() -> Result<Config> {
|
||||
// Create an engine with caching enabled to assist with iteration in this project.
|
||||
let mut config = Config::new();
|
||||
config.cache_config_load_default()?;
|
||||
// config.debug_info(true);
|
||||
config.wasm_backtrace_details(wasmtime::WasmBacktraceDetails::Enable);
|
||||
Ok(config)
|
||||
}
|
||||
Reference in New Issue
Block a user