Skip to content

Instantly share code, notes, and snippets.

@lemire
Created November 21, 2023 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lemire/7a64fa2732e5e35f65568a0f98a9db18 to your computer and use it in GitHub Desktop.
Save lemire/7a64fa2732e5e35f65568a0f98a9db18 to your computer and use it in GitHub Desktop.
C program to test curl URL normalization
// cc test.c -lcurl -o testcurl && ./testcurl
#include <curl/curl.h>
#include <stdio.h>
int main() {
CURLU *url = curl_url();
CURLUcode rc = curl_url_set(
url, CURLUPART_URL, "https://www.7‑Eleven.com/Home/Privacy/Montréal", 0);
// Returns a CURLUcode error value, which is (0) if everything went fine.
if (rc == 0) {
char *buffer;
// When asked to return the full URL, curl_url_get will return a
// normalized and possibly cleaned up version of what was previously
// parsed.
rc = curl_url_get(url, CURLUPART_URL, &buffer, 0);
printf("%s\n", buffer);
if (rc == 0) {
curl_free(buffer);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment