feat: update container
This commit is contained in:
@@ -45,8 +45,8 @@ pub fn do_fetch(params: &str) -> FnResult {
|
|||||||
m => return FnResult::fail(format!("Unsupported method: {}", m)),
|
m => return FnResult::fail(format!("Unsupported method: {}", m)),
|
||||||
};
|
};
|
||||||
let mut request_builder = client.request(request_method.clone(), &fetch_params.url);
|
let mut request_builder = client.request(request_method.clone(), &fetch_params.url);
|
||||||
|
let mut has_user_agent = false;
|
||||||
if let Some(options) = &fetch_params.options {
|
if let Some(options) = &fetch_params.options {
|
||||||
let mut has_user_agent = false;
|
|
||||||
if let Some(headers) = &options.headers {
|
if let Some(headers) = &options.headers {
|
||||||
for (k, v) in headers {
|
for (k, v) in headers {
|
||||||
let k = k.to_lowercase();
|
let k = k.to_lowercase();
|
||||||
@@ -56,10 +56,11 @@ pub fn do_fetch(params: &str) -> FnResult {
|
|||||||
request_builder = request_builder.header(k, v.to_string());
|
request_builder = request_builder.header(k, v.to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !has_user_agent {
|
}
|
||||||
request_builder = request_builder.header("User-Agent", "JavaScriptSandboxContainer/0.1");
|
if !has_user_agent {
|
||||||
}
|
request_builder = request_builder.header("User-Agent", "JavaScriptSandboxContainer/0.1");
|
||||||
|
}
|
||||||
|
if let Some(options) = &fetch_params.options {
|
||||||
if let Some(body) = &options.body {
|
if let Some(body) = &options.body {
|
||||||
if Method::POST == request_method {
|
if Method::POST == request_method {
|
||||||
let body = reqwest::blocking::Body::from(body.to_string());
|
let body = reqwest::blocking::Body::from(body.to_string());
|
||||||
|
|||||||
@@ -38,10 +38,14 @@ fn main() -> Result<()> {
|
|||||||
let a = exports.eval_javascript(&mut store, r##"
|
let a = exports.eval_javascript(&mut store, r##"
|
||||||
function hi(name) { return "hi: " + name; }
|
function hi(name) { return "hi: " + name; }
|
||||||
let a = [];
|
let a = [];
|
||||||
a.push(fetch('https://hatter.ink/util/print_request.action'));
|
a.push(fetch('https://hatter.ink/util/print_request.action', {
|
||||||
a.push(fetch('https://hatter.ink/ip.action'));
|
headers: {
|
||||||
|
'Test-Header': 'this is a test header'
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
// a.push(fetch('https://hatter.ink/ip.action'));
|
||||||
a.push(fetch('https://hatter.ink/ip/ip.jsonp'));
|
a.push(fetch('https://hatter.ink/ip/ip.jsonp'));
|
||||||
a.push(fetch('https://hatter.ink/ip2.action'));
|
// a.push(fetch('https://hatter.ink/ip2.action'));
|
||||||
a.push({
|
a.push({
|
||||||
userId: 'id001',
|
userId: 'id001',
|
||||||
name: 'Test',
|
name: 'Test',
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use boa_engine::{Context, JsResult, JsString, JsValue};
|
use boa_engine::{Context, JsResult, JsString, JsValue};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::{Map, Value};
|
use serde_json::{Map, Value};
|
||||||
|
|
||||||
wit_bindgen_rust::export!("../exports.wit");
|
wit_bindgen_rust::export!("../exports.wit");
|
||||||
wit_bindgen_rust::import!("../container.wit");
|
wit_bindgen_rust::import!("../container.wit");
|
||||||
|
|
||||||
@@ -31,7 +32,7 @@ fn do_fetch(_: &JsValue, args: &[JsValue], ctx: &mut Context) -> JsResult<JsValu
|
|||||||
let mut fetch_params_map = Map::new();
|
let mut fetch_params_map = Map::new();
|
||||||
fetch_params_map.insert("url".to_string(), args[0].to_json(ctx).expect("error"));
|
fetch_params_map.insert("url".to_string(), args[0].to_json(ctx).expect("error"));
|
||||||
if args.len() > 1 {
|
if args.len() > 1 {
|
||||||
fetch_params_map.insert("params".to_string(), args[1].to_json(ctx).expect("error"));
|
fetch_params_map.insert("options".to_string(), args[1].to_json(ctx).expect("error"));
|
||||||
}
|
}
|
||||||
let fetch_params = format!("{}", Value::Object(fetch_params_map));
|
let fetch_params = format!("{}", Value::Object(fetch_params_map));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user