Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CURLOPT_FOLLOWLOCATION: add a CURLFOLLOW_NO_CUSTOMMETHOD bit #8130

Closed
wants to merge 1 commit into from

Conversation

bagder
Copy link
Member

@bagder bagder commented Dec 10, 2021

(This is a re-run. This change was already proposed for inclusion in 7.66.0 in #3803 but due to lack of interest I retracted it back then. Since this change would allow us to make a -X from curl that is "less bad", which also might be interesting when considering a coming QUERY method, I think/hope it might get some more interest this time around!?)

With this change, the argument passed to the CURLOPT_FOLLOWLOCATION
option is treated as a bitmask instead of just a long. If the new
CURLFOLLOW_NO_CUSTOMREQUEST bit is set in the bitmask, it means that
libcurl will NOT allow a custom method override the HTTP request method
after a redirect is followed. As is otherwise the default behavior (that
surprises many users).

This change is forward compatible because CURLOPT_FOLLOWLOCATION has
been documented to accept the exact value of '1' to enable redirect
following and therefore the other bits were left unused and
undefined. We now add value to another bit. Starting in 7.66.0, the
value 1 and the first bit still enables plain redirect following but the
second bit adds more meaning.

This change is backward compatible in the following way: setting the
CURLFOLLOW_NO_CUSTOMREQUEST bit in a program that still uses an older
libcurl installation at run-tim will have no effect. This is because
older libcurl code checked if the value was non-zero and then enabled
redirect following. Of course older libcurl will always let the set
CURLOPT_CUSTOMREQUEST string override the method, disregarding what the
HTTP response code suggests.

Test 1589 added to verify the functionality.

@bagder bagder added HTTP feature-window A merge of this requires an open feature window libcurl API labels Dec 10, 2021
@bagder
Copy link
Member Author

bagder commented Dec 10, 2021

CURLFOLLOW_NO_CUSTOMMETHOD is probably a more suitable name. (from @icing)

@jay
Copy link
Member

jay commented Dec 26, 2021

which also might be interesting when considering a coming QUERY method

I read that and it looks like cacheable database search results. So then the resource (database) changes and it's invalidated? I wonder how it will work in practice.

bagder added a commit that referenced this pull request Jan 9, 2022
With this change, the argument passed to the CURLOPT_FOLLOWLOCATION
option is treated as a bitmask instead of just a long. If the new
CURLFOLLOW_NO_CUSTOMMETHOD bit is set in the bitmask, it means that
libcurl will NOT allow a custom method override the HTTP request method
after a redirect is followed. As is otherwise the default behavior (that
surprises many users).

This change is forward compatible because CURLOPT_FOLLOWLOCATION has
been documented to accept the exact value of '1' to enable redirect
following and therefore the other bits were left unused and
undefined. We now add value to another bit. Starting in 7.66.0, the
value 1 and the first bit still enables plain redirect following but the
second bit adds more meaning.

This change is backward compatible in the following way: setting the
CURLFOLLOW_NO_CUSTOMMETHOD bit in a program that still uses an older
libcurl installation at run-tim will have no effect. This is because
older libcurl code checked if the value was non-zero and then enabled
redirect following. Of course older libcurl will always let the set
CURLOPT_CUSTOMMETHOD string override the method, disregarding what the
HTTP response code suggests.

Test 1589 added to verify the functionality.

Closes #8130
@bagder bagder force-pushed the bagder/ignore-custom-request-on-redir branch from 38a0c0a to 760c140 Compare January 9, 2022 21:48
@bagder bagder changed the title CURLOPT_FOLLOWLOCATION: add a CURLFOLLOW_NO_CUSTOMREQUEST bit CURLOPT_FOLLOWLOCATION: add a CURLFOLLOW_NO_CUSTOMMETHOD bit Jan 9, 2022
With this change, the argument passed to the CURLOPT_FOLLOWLOCATION
option is treated as a bitmask instead of just a long. If the new
CURLFOLLOW_NO_CUSTOMMETHOD bit is set in the bitmask, it means that
libcurl will NOT allow a custom method override the HTTP request method
after a redirect is followed. As is otherwise the default behavior (that
surprises many users).

This change is forward compatible because CURLOPT_FOLLOWLOCATION has
been documented to accept the exact value of '1' to enable redirect
following and therefore the other bits were left unused and
undefined. We now add value to another bit. Starting in 7.66.0, the
value 1 and the first bit still enables plain redirect following but the
second bit adds more meaning.

This change is backward compatible in the following way: setting the
CURLFOLLOW_NO_CUSTOMMETHOD bit in a program that still uses an older
libcurl installation at run-tim will have no effect. This is because
older libcurl code checked if the value was non-zero and then enabled
redirect following. Of course older libcurl will always let the set
CURLOPT_CUSTOMMETHOD string override the method, disregarding what the
HTTP response code suggests.

Test 1589 added to verify the functionality.

Closes #8130
\fIenable\fP is a bitmask. If you set the \fICURLFOLLOW_NO_CUSTOMMETHOD\fP
bit, it will tell libcurl that the method set with
\fICURLOPT_CUSTOMREQUEST(3)\fP will not be used after a redirect if the HTTP
response says so.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than have the user set curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, CURLFOLLOW_NO_CUSTOMMETHOD | CURLFOLLOW_ENABLE); , you could instead define CURLFOLLOW_NO_CUSTOMMETHOD as 3 and get rid of CURLFOLLOW_ENABLE. If you feel the bitfield really is the way to go then you should add CURLFOLLOW_DISABLE as well, and document them both.

@bagder
Copy link
Member Author

bagder commented May 23, 2022

I'm not sensing any particular interest from users for this so I'll close this again for this time and maybe bring it back at a later time.

@bagder bagder closed this May 23, 2022
@bagder bagder deleted the bagder/ignore-custom-request-on-redir branch August 9, 2023 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-window A merge of this requires an open feature window HTTP libcurl API
Development

Successfully merging this pull request may close these issues.

None yet

2 participants