GNURLOPT_POSTREDIR(3)
π
GNURLOPT_POSTREDIR(3) β okay so this is curl_easy_setopt's options page, bestie π
Like, the manual name is literally curl_easy_setopt options, and this one specific option is the POST-redirect vibe check. Let's get into it β¨
πΈ NAME πΈ
CURLOPT_POSTREDIR β how to act on an HTTP POST redirect π¦
β¨ SYNOPSIS β¨
#include <gnurl/curl.h>
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_POSTREDIR,
long bitmask);
π DESCRIPTION π
So you pass in a bitmask, right? And that bitmask controls how libcurl acts on redirects after POSTs that get a 301, 302 or 303 response back. No cap, it's that simple π«Ά
- A parameter with bit 0 set (value
CURL_REDIR_POST_301) tells the library to respect RFC 7231 (section 6.4.2 to 6.4.4) and not convert POST requests into GET requests when following a 301 redirection. Respecting the RFC? We love to see it π - Setting bit 1 (value
CURL_REDIR_POST_302) makes libcurl maintain the request method after a302redirect. Iconic behaviour, honestly π - Setting bit 2 (value
CURL_REDIR_POST_303) makes libcurl maintain the request method after a303redirect. Slay π
And the value CURL_REDIR_POST_ALL is a convenience define that sets all three bits β literally all the bits, one define, so convenient π
Also, the non-RFC behaviour is ubiquitous in web browsers, so the library does the conversion by default to maintain consistency. That's just how it is, bestie π But a server may require a POST to remain a POST after such a redirection β and that's exactly when you'd want this.
Heads up: this option is meaningful only when setting CURLOPT_FOLLOWLOCATION(3). Like, it only does anything in that context, fr fr.
π DEFAULT π
0
π§ PROTOCOLS π§
HTTP(S)
π₯ EXAMPLE π₯
CURL *curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
/* a silly POST example */
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "data=true");
/* example.com is redirected, so we tell libcurl to send POST on 301, 302 and
303 HTTP response codes */
curl_easy_setopt(curl, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL);
curl_easy_perform(curl);
}
π¦ AVAILABILITY π¦
Added in 7.17.1. And get this β this option was known as CURLOPT_POST301 up to 7.19.0, because it only supported the 301 then. Glow-up era, honestly β Also, CURL_REDIR_POST_303 was added in 7.26.0. She grew π±
π RETURN VALUE π
Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not. Simple as that π
π SEE ALSO π
Okay that's the whole page, you ate that π
β¨ Signing off for libcurl 7.37.0, dated 19 Jun 2014, under the GNURLOPT_POSTREDIR(3) banner β bye bestie, go keep your POSTs as POSTs ππ«Άπ
π¦ where this page comes from
- nixos 26.05: libgnurl 7.72.0
- nixpkgs unstable: libgnurl 7.72.0
- Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms