cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Patch for 301/302 redirect after post

From: Martin Drasar <drasar_at_optimsys.cz>
Date: Mon, 11 Aug 2008 13:07:07 +0200

Dan Fandrich napsal(a):
> On Thu, Aug 07, 2008 at 10:50:09AM +0200, Martin Drasar wrote:
>> I don't know if I have renamed the POST301 option correctly, i.e. is
>> using CINIT with different name but same number what you call renaming?
>
> There's a section in curl.h starting #ifndef CURL_NO_OLDIES that contains
> other renamed options. CURLOPT_POST301 should go in there, which lets
> users test that their apps aren't using any outdated options by setting
> CURL_NO_OLDIES.

There are several oldies sections so I have placed it after the CINITs
section. However that section is labeled as supported till 2009. If I
understood Daniel well, this option should be supported longer. Should
it go somewhere else or it doesn't matter?

>
>> I have tried to keep the spirit of "non-zero turns it on", but for
>> obvious reasons, anyone who use 2 as a setting value for CURLOPT_POST301
>> will not get it working as he/she wanted.
>
> These values also work as bit fields, so POST_301|POST_302 == POST_ALL
> It might be worthwhile documenting them as such.
>

Somehow documented in curl.h

>> As for the magic names - I was too scared to try to insert them into some
>> file, so it will probably up to you :-)
>
> Just create an enum similar to the one for CURLOPT_HTTP_VERSION and put it
> in the same section of the file.
>
>> My suggestion:
>> either
>> 0 = 301_GET_302_GET
>> 1 = 301_POST_302_GET
>> 2 = 301_GET_302_POST
>> 3 = 301_POST_302_POST
>> or
>> 0 = GET_ALL
>> 1 = POST_301
>> 2 = POST_302
>> 3 = POST_ALL
>> and maybe some prefixes or suffixes ;-)
>
> These should have at least a CURL_ prefix, maybe CURL_REDIR_POST_301 etc.
>
>>>> Dan

I have used second option and added prefix CURL_REDIR_

Thanks for your comments Dan.
Patch is attached, I hope that this time it's ok ;-)

-- 
   Martin Drasar, Developer / Analyst
   OptimSys, s.r.o.
   drasar_at_optimsys.cz
   Tel: +420 541 143 065
   Fax: +420 541 143 066
   http://www.optimsys.cz

? patch
Index: include/curl/curl.h
===================================================================
RCS file: /cvsroot/curl/curl/include/curl/curl.h,v
retrieving revision 1.361
diff -r1.361 curl.h
1123,1124c1123,1125
< /* Obey RFC 2616/10.3.2 and keep POSTs as POSTs after a 301 */
< CINIT(POST301, LONG, 161),

---
>   /* Set the behaviour of POST when redirecting. Values must be set to one
>      of CURL_REDIR* enums below */
>   CINIT(POSTREDIR, LONG, 161),
1163a1165,1168
> /* This one was added in version 7.18.2 */
> #define CURLOPT_POST301 CURLOPT_POSTREDIR
> 
> 
1225a1231,1240
> /* enums to use with CURLOPT_POSTREDIR.
>    CURL_REDIR_POST_301 and CURL_REDIR_POST_302 can be bitwise ORed so that
>    CURL_REDIR_POST_301 | CURL_REDIR_POST_302 == CURL_REDIR_POST_ALL */
> enum {
>   CURL_REDIR_GET_ALL,
>   CURL_REDIR_POST_301,
>   CURL_REDIR_POST_302,
>   CURL_REDIR_POST_ALL
> };
> 
Index: lib/transfer.c
===================================================================
RCS file: /cvsroot/curl/curl/lib/transfer.c,v
retrieving revision 1.399
diff -r1.399 transfer.c
2195c2195,2196
<      * This behaviour can be overriden with CURLOPT_POST301.
---
>      * This behaviour can be overriden with CURLOPT_POST301 or 
>      * CURLOPT_POSTREDIR
2221a2223,2224
> 
>     This behaviour can be overriden with CURLOPT_POSTREDIR
2222a2226,2234
>     if( (data->set.httpreq == HTTPREQ_POST
>          || data->set.httpreq == HTTPREQ_POST_FORM)
>         && !data->set.post302) {
>       infof(data,
>             "Violate RFC 2616/10.3.3 and switch from POST to GET\n");
>       data->set.httpreq = HTTPREQ_GET;
>     }
>     break;
> 
Index: lib/url.c
===================================================================
RCS file: /cvsroot/curl/curl/lib/url.c,v
retrieving revision 1.726
diff -r1.726 url.c
1024c1024
<   case CURLOPT_POST301:
---
>   case CURLOPT_POSTREDIR:
1026,1028c1026,1036
<      * Obey RFC 2616/10.3.2 and resubmit a POST as a POST after a 301.
<      */
<     data->set.post301 = (bool)(0 != va_arg(param, long));
---
>      * Set the behaviour of POST when redirecting
>      * CURL_REDIR_GET_ALL - POST is changed to GET after 301 and 302
>      * CURL_REDIR_POST_301 - POST is kept as POST after 301
>      * CURL_REDIR_POST_302 - POST is kept as POST after 302
>      * CURL_REDIR_POST_ALL - POST is kept as POST after 301 and 302
>      * other - POST is kept as POST after 301 and 302
>      */
>     data->set.post301 = (CURL_REDIR_GET_ALL  != va_arg(param, long)) && 
>                         (CURL_REDIR_POST_302 != va_arg(param, long));
>     data->set.post302 = (CURL_REDIR_GET_ALL  != va_arg(param, long)) &&
>                         (CURL_REDIR_POST_301 != va_arg(param, long));
Index: lib/urldata.h
===================================================================
RCS file: /cvsroot/curl/curl/lib/urldata.h,v
retrieving revision 1.384
diff -r1.384 urldata.h
1350a1351
>   bool post302;      /* keep POSTs as POSTs after a 302 */
Received on 2008-08-11