Add POST support to fetch() in scripts

This commit is contained in:
Tindy X 2020-08-29 01:47:16 +08:00
parent e0a4194a4b
commit 24434b6242
No known key found for this signature in database
GPG Key ID: C6AD413169968D58

View File

@ -107,10 +107,25 @@ static duk_ret_t native_print(duk_context *ctx)
static duk_ret_t fetch(duk_context *ctx)
{
/*
std::string filepath, proxy;
duktape_get_arguments_str(ctx, 1, 2, &filepath, &proxy);
std::string content = fetchFile(filepath, proxy, gCacheConfig);
duk_push_lstring(ctx, content.c_str(), content.size());
*/
std::string filepath, proxy, method, postdata, content;
if(duktape_get_arguments_str(ctx, 1, 4, &filepath, &proxy, &method, &postdata) == 0)
return 0;
switch(hash_(method))
{
case "POST"_hash:
webPost(filepath, postdata, proxy, string_array{}, &content);
break;
default:
content = fetchFile(filepath, proxy, gCacheConfig);
break;
}
duk_push_lstring(ctx, content.c_str(), content.size());
return 1;
}