Add example for url_decode_field

This commit is contained in:
2025-12-06 01:33:50 +01:00
parent a409997006
commit 841f0731e9
4 changed files with 37 additions and 4 deletions
+29
View File
@@ -0,0 +1,29 @@
#include <stdio.h>
#include <string.h>
#include "../url.h"
int main(void)
{
char src[] = "http://web%73ite.com";
URL parsed;
int ret = url_parse(src, strlen(src), NULL, 1, &parsed);
if (ret < 0) {
printf("Couldn't parse base URL\n");
return -1;
}
printf("%.*s\n",
parsed.host_text.len,
parsed.host_text.ptr);
char buf[100];
ret = url_decode_field(parsed.host_text, buf, (int) sizeof(buf)-1);
if (ret < 0 || ret >= (int) sizeof(buf)) {
printf("Couldn't decode field\n");
return -1;
}
printf("%.*s\n", ret, buf);
return 0;
}