hotfix(proxy): fix CLI/api mismatch and add proxy type defaults

Signed-off-by: Bo <boironic@gmail.com>
This commit is contained in:
Bo
2026-02-24 19:16:00 +08:00
parent efaf40f678
commit 04c80c9c7e
3 changed files with 18 additions and 3 deletions

View File

@@ -206,6 +206,7 @@ static int cmd_heap_info(int argc, char **argv)
static struct {
struct arg_str *host;
struct arg_int *port;
struct arg_str *type;
struct arg_end *end;
} proxy_args;
@@ -216,7 +217,16 @@ static int cmd_set_proxy(int argc, char **argv)
arg_print_errors(stderr, proxy_args.end, argv[0]);
return 1;
}
http_proxy_set(proxy_args.host->sval[0], (uint16_t)proxy_args.port->ival[0]);
const char *proxy_type = "http";
if (proxy_args.type->count > 0 && proxy_args.type->sval[0] && proxy_args.type->sval[0][0]) {
proxy_type = proxy_args.type->sval[0];
}
if (strcmp(proxy_type, "http") != 0 && strcmp(proxy_type, "socks5") != 0) {
printf("Invalid proxy type: %s. Use http or socks5.\n", proxy_type);
return 1;
}
http_proxy_set(proxy_args.host->sval[0], (uint16_t)proxy_args.port->ival[0], proxy_type);
printf("Proxy set. Restart to apply.\n");
return 0;
}
@@ -732,10 +742,11 @@ esp_err_t serial_cli_init(void)
/* set_proxy */
proxy_args.host = arg_str1(NULL, NULL, "<host>", "Proxy host/IP");
proxy_args.port = arg_int1(NULL, NULL, "<port>", "Proxy port");
proxy_args.end = arg_end(2);
proxy_args.type = arg_str0(NULL, NULL, "<type>", "Proxy type: http|socks5 (default: http)");
proxy_args.end = arg_end(3);
esp_console_cmd_t proxy_cmd = {
.command = "set_proxy",
.help = "Set HTTP proxy (e.g. set_proxy 192.168.1.83 7897)",
.help = "Set proxy (e.g. set_proxy 192.168.1.83 7897 [http|socks5])",
.func = &cmd_set_proxy,
.argtable = &proxy_args,
};