GNURLINFO_RESPONSE_CODE(3)

πŸ“¦ version 7.72.0, in nixos 26.05, nixpkgs unstable

okay bestie, welcome to GNURLINFO_RESPONSE_CODE(3) β€” straight from the curl_easy_getinfo options manual, and it's giving β€œtiny but powerful” energy. πŸ’…βœ¨

NAME πŸŽ€

CURLINFO_RESPONSE_CODE β€” grab the last response code. no cap, that's the whole vibe. 🫢

SYNOPSIS πŸ“œ

#include <gnurl/curl.h>

CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_RESPONSE_CODE, long *codep);

DESCRIPTION πŸ’–

okay so you pass a pointer to a long, and it receives the last received HTTP, FTP or SMTP response code. that's the main character move. πŸ”₯

fun lil history fact: this option was previously known as CURLINFO_HTTP_CODE in libcurl 7.10.7 and earlier. the stored value will be zero if no server response code has been received. literally zero, bestie. 😌

⚠️ important side note: a proxy's CONNECT response should be read with CURLINFO_HTTP_CONNECTCODE(3) and not this. iykyk. 🫑

Support for SMTP responses added in 7.25.0. slay. πŸ’Œ

PROTOCOLS 🌈

HTTP, FTP and SMTP β€” that's the lineup. πŸ’«

EXAMPLE πŸ“

here's the snippet, copied exactly because we do not mess with code in this group chat: 🧚

CURL *curl = curl_easy_init();
if(curl) {
  CURLcode res;
  curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
  res = curl_easy_perform(curl);
  if(res == CURLE_OK) {
    long response_code;
    curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code);
  }
  curl_easy_cleanup(curl);
}

AVAILABILITY πŸ¦‹

Added in 7.10.8. CURLINFO_HTTP_CODE was added in 7.4.1. vintage but still iconic. πŸ‘‘

RETURN VALUE πŸ’œ

Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not. simple, clean, periodt. πŸ’…

SEE ALSO πŸ”


mwah πŸ’‹ this cutie page comes from libcurl 7.44.0, dated 28 Aug 2015. bye bestie, go get those response codes! πŸŒˆπŸ‘‘βœ¨

πŸ“¦ where this page comes from