Artifactspublic-v0

curl

master
ply4 git calls31 ms288 KiB3 cachedprotocol v2
95 lines2.6 KiBRaw

NAME

CURLOPT_POSTREDIR - how to act on an HTTP POST redirect

SYNOPSIS

c
#include <curl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_POSTREDIR,
                          long bitmask);

DESCRIPTION

Pass a bitmask to control how libcurl acts on redirects after POSTs that get a 301, 302 or 303 response back. A parameter with bit 0 set (value CURL_REDIR_POST_301) tells the library to not convert POST requests into GET requests when following a 301 redirection. Setting bit 1 (value CURL_REDIR_POST_302) makes libcurl maintain the request method after a 302 redirect whilst setting bit 2 (value CURL_REDIR_POST_303) makes libcurl maintain the request method after a 303 redirect. The value CURL_REDIR_POST_ALL is a convenience define that sets all three bits.

The non-RFC behavior is ubiquitous in web browsers, so the library does the conversion by default to maintain consistency. A server may require a POST to remain a POST after such a redirection. This option is meaningful only when setting CURLOPT_FOLLOWLOCATION(3).

This option affects transfers where libcurl has been told to use HTTP POST using for example CURLOPT_POST(3) or CURLOPT_MIMEPOST(3) and not if the method has merely been modified with CURLOPT_CUSTOMREQUEST(3).

DEFAULT

0

%PROTOCOLS%

EXAMPLE

c
int main(void)
{
  CURL *curl = curl_easy_init();
  if(curl) {
    CURLcode result;
    curl_easy_setopt(curl, CURLOPT_URL, "https://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);

    result = curl_easy_perform(curl);
    curl_easy_cleanup(curl);
  }
}

HISTORY

This option was known as CURLOPT_POST301 up to 7.19.0 as it only supported the 301 then. CURL_REDIR_POST_303 was added in 7.26.0.

CURL_REDIR_* macros became long types in 8.16.0, prior to this version a long cast was necessary when passed to curl_easy_setopt(3).

%AVAILABILITY%

RETURN VALUE

curl_easy_setopt(3) returns a CURLcode indicating success or error.

CURLE_OK (0) means everything was OK, non-zero means an error occurred, see libcurl-errors(3).

1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLOPT_POSTREDIR
5Section: 3
6Source: libcurl
7See-also:
8 - CURLINFO_EFFECTIVE_METHOD (3)
9 - CURLINFO_REDIRECT_COUNT (3)
10 - CURLOPT_FOLLOWLOCATION (3)
11 - CURLOPT_MAXREDIRS (3)
12 - CURLOPT_POSTFIELDS (3)
13Protocol:
14 - HTTP
15Added-in: 7.19.1
16---
18# NAME
20CURLOPT_POSTREDIR - how to act on an HTTP POST redirect
22# SYNOPSIS
24~~~c
25#include <curl/curl.h>
27CURLcode curl_easy_setopt(CURL *handle, CURLOPT_POSTREDIR,
28 long bitmask);
29~~~
31# DESCRIPTION
33Pass a bitmask to control how libcurl acts on redirects after POSTs that get a
34301, 302 or 303 response back. A parameter with bit 0 set (value
35**CURL_REDIR_POST_301**) tells the library to not convert POST requests into
36GET requests when following a 301 redirection. Setting bit 1 (value
37**CURL_REDIR_POST_302**) makes libcurl maintain the request method after a 302
38redirect whilst setting bit 2 (value **CURL_REDIR_POST_303**) makes libcurl
39maintain the request method after a 303 redirect. The value
40**CURL_REDIR_POST_ALL** is a convenience define that sets all three bits.
42The non-RFC behavior is ubiquitous in web browsers, so the library does the
43conversion by default to maintain consistency. A server may require a POST to
44remain a POST after such a redirection. This option is meaningful only when
45setting CURLOPT_FOLLOWLOCATION(3).
47This option affects transfers where libcurl has been told to use HTTP POST
48using for example CURLOPT_POST(3) or CURLOPT_MIMEPOST(3) and not if the
49method has merely been modified with CURLOPT_CUSTOMREQUEST(3).
51# DEFAULT
55# %PROTOCOLS%
57# EXAMPLE
59~~~c
60int main(void)
62 CURL *curl = curl_easy_init();
63 if(curl) {
64 CURLcode result;
65 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
67 /* a silly POST example */
68 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "data=true");
70 /* example.com is redirected, so we tell libcurl to send POST on 301,
71 302 and 303 HTTP response codes */
72 curl_easy_setopt(curl, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL);
74 result = curl_easy_perform(curl);
75 curl_easy_cleanup(curl);
76 }
78~~~
80# HISTORY
82This option was known as CURLOPT_POST301 up to 7.19.0 as it only supported the
83301 then. CURL_REDIR_POST_303 was added in 7.26.0.
85**CURL_REDIR_*** macros became `long` types in 8.16.0, prior to this version
86a `long` cast was necessary when passed to curl_easy_setopt(3).
88# %AVAILABILITY%
90# RETURN VALUE
92curl_easy_setopt(3) returns a CURLcode indicating success or error.
94CURLE_OK (0) means everything was OK, non-zero means an error occurred, see
95libcurl-errors(3).
Diagnostics4 git calls · 31 ms
CallStatusSizeTime031 ms
discover200152 B2 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=152
git.server.agent=gitty/1.0
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch object-format
git.server.fetch=shallow filter sideband-all
git.protocol.version=2
git.pkt.frames=8
git.pkt.data=6
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=152
git.pkt.payload.max=34
ls-refs200149 B · hit2 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=149
git.response.cache=HIT
git.response.duration_ms=2
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=149
git.pkt.payload.max=78
git.ls_refs.count=2
git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit4 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=293470
git.response.cache=HIT
git.response.duration_ms=4
git.fetch.filter=blob:none
git.fetch.filter.requested=tree:0
git.fetch.filter.fallback=blob:none
git.fetch.filter.learned=false
git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=10
git.pkt.data=8
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=293470
git.pkt.payload.max=65516
git.sideband.band1.bytes=293354
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=87
git.pack.bytes=293354
git.pack.ofs_delta=0
git.pack.ref_delta=1
git.pack.chain.max=1
git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0
git.pack.full=86
Open pack map
fetch2001.3 KiB · hit25 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=25
git.response.bytes=1372
git.response.cache=HIT
git.response.duration_ms=25
git.fetch.wants=13cd9f333dda864575a688e416f767701a70f621
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=1372
git.pkt.payload.max=1351
git.sideband.band1.bytes=1350
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
Ref
refs/heads/master
Commit
31c911efe5652725e930f4d2e60c9060e5f6646d
cf-ray
a5e3341a7b22f485
Request
d2f98eef…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format