From 8fd1b7e8e3e79f2746dd551eb3ae10cd1880e883 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Thu, 5 Sep 2019 20:04:48 -0400 Subject: Use CURLINFO_CONTENT_TYPE Oops, didn't see this. --- bin/title.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) (limited to 'bin') diff --git a/bin/title.c b/bin/title.c index 117dc48b..9a74b7f5 100644 --- a/bin/title.c +++ b/bin/title.c @@ -18,11 +18,9 @@ #include #include #include -#include #include #include #include -#include #include #include @@ -82,22 +80,11 @@ static void showTitle(const char *title) { } static CURL *curl; -static bool html; static struct { char buf[8192]; size_t len; } body; -static const char ContentType[] = "Content-Type: text/html"; - -static size_t handleHeader(char *buf, size_t size, size_t nitems, void *user) { - (void)user; - size_t len = size * nitems; - if (sizeof(ContentType) - 1 < len) len = sizeof(ContentType) - 1; - if (!strncasecmp(buf, ContentType, len)) html = true; - return size * nitems; -} - // HE COMES static const char TitlePattern[] = "([^<]*)"; static regex_t TitleRegex; @@ -125,11 +112,14 @@ static CURLcode fetchTitle(const char *url) { CURLcode code = curl_easy_setopt(curl, CURLOPT_URL, url); if (code) return code; - html = false; curl_easy_setopt(curl, CURLOPT_NOBODY, 1L); code = curl_easy_perform(curl); if (code) return code; - if (!html) return CURLE_OK; + + char *type; + code = curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &type); + if (code) return code; + if (strncmp(type, "text/html", 9)) return CURLE_OK; body.len = 0; curl_easy_setopt(curl, CURLOPT_NOBODY, 0L); @@ -155,7 +145,6 @@ int main(int argc, char *argv[]) { curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 3L); - curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, handleHeader); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, handleBody); if (argc > 1) { -- cgit 1.4.1 86e0b9244c44c5b98&showmsg=1&follow=1'>root/bundle/ctrlp.vim (unfollow)
Commit message (Collapse)Author
2012-01-22Revert "Add AutoClose"June McEnroe
This reverts commit 39cfdd62ba82f93f68a2b5fa7b5771303d8b9dee. This fixes the delay when leaving insert mode
2012-01-22Revert "Disable powerline for now"June McEnroe
This reverts commit fa48f5965c57272e616721d92475cd2f1e35f667.
2012-01-22Revert "Add VCS repo directories to wildignore"June McEnroe
This reverts commit 41cb1db33ba7b64d8af63bf55bb82f7e8a617518. This fixes not being able to commit with vim-fugitive
2012-01-22Disable powerline for nowJune McEnroe
2012-01-22Update some pluginsJune McEnroe
2012-01-22Add VCS repo directories to wildignoreJune McEnroe
2012-01-22Map ,e and ,b to CtrlP file and buffer respectivelyJune McEnroe
2012-01-22Add vim-spaceJune McEnroe
2012-01-22Add AutoCloseJune McEnroe
2012-01-22Add binding for GundoJune McEnroe
2012-01-22Add GundoJune McEnroe
2012-01-22Add Jellybeans colorschemeJune McEnroe
2012-01-22Add syntasticJune McEnroe
2012-01-21Add PowerlineJune McEnroe
2012-01-21Add quicktaskJune McEnroe
2012-01-15Moved comments out of mapsJune McEnroe
2012-01-14Disable scrollbarsJune McEnroe