Add a http get command

This commit is contained in:
Lncvrt committed 2026-03-13 12:41:51 -07:00
1 parent 434cd69467
commit 05c1fdf6d5
2 files changed
+23 -1

No files matched your search

+17
View File
@@ -0,0 +1,17 @@
#include "../lib/http.h"
#include <cJSON.h>
#include <stdio.h>
#include <stdlib.h>
void http_get_command(int argc, char *argv[]) {
for (int i = 0; i < argc; i++) {
if (i > 0)
putchar(' ');
char *body = http_get(argv[i]);
if (!body) {
printf("Failed to GET url \"%s\"\n", argv[i]);
return;
}
printf("%s\n", body);
}
}
+6 -1
View File
@@ -11,6 +11,7 @@ void base64_decode_command(int argc, char *argv[]);
void base64_encode_command(int argc, char *argv[]); void base64_encode_command(int argc, char *argv[]);
void echo_command(int argc, char *argv[]); void echo_command(int argc, char *argv[]);
void version_command(int argc, char *argv[]); void version_command(int argc, char *argv[]);
void http_get_command(int argc, char *argv[]);
} }
const std::vector<Command> commands = { const std::vector<Command> commands = {
@@ -23,7 +24,11 @@ const std::vector<Command> commands = {
{"base64-encode", {"base64-encode",
"A base64 encode command, \"base64-encode <encoded-text> " "A base64 encode command, \"base64-encode <encoded-text> "
"[encoded-text2]\"", "[encoded-text2]\"",
base64_encode_command}}; base64_encode_command},
{"http-get",
"A HTTP get command, \"http-get <url> "
"[encoded-text2]\"",
http_get_command}};
const std::vector<Command> &getCommands() { return commands; } const std::vector<Command> &getCommands() { return commands; }