curl-library
Re: redirects and their bodies
Date: Thu, 28 Jul 2005 11:56:25 +0200
Hi Daniel Stenberg, you wrote:
> Or optionally, convince us why this is a handy feature and provide a
> patch that introduces this feature!
Ok, I'll try :)
Imagine an HTTP message parser that processes the data
provided by curl. It will fail on in principle correct
messages, just because the body of the message has been
truncated.
I would be very glad if something like the attached patch
could make it into HEAD, because I currently retreive the
bodies of redirects through the debug callback, which is
an ugly hack - at its best :-/
The patch introduces a new option CURLOPT_REDIRBODIES
(may be anything) that controls wheter curl ignores
the bodies of the redirect responses, though I'm not
shure if it's implemented correctly.
On a side note -- another handy feature would be to
retreive the outgoing HTTP message(s) sent by curl
(maybe through an additional callback) as I'm
doing that again through the debug callback.
Thanks a lot for considering,
-- Michael - < mike(@)php.net >
Index: lib/transfer.c
===================================================================
RCS file: /cvsroot/curl/curl/lib/transfer.c,v
retrieving revision 1.281
diff -u -r1.281 transfer.c
--- lib/transfer.c 12 Jul 2005 18:15:34 -0000 1.281
+++ lib/transfer.c 28 Jul 2005 09:50:10 -0000
@@ -1013,17 +1013,21 @@
if (conn->newurl) {
if(conn->bits.close) {
- /* Abort after the headers if "follow Location" is set
- and we're set to close anyway. */
- k->keepon &= ~KEEP_READ;
+ if(!data->set.redirbodies) {
+ /* Abort after the headers if "follow Location" is set
+ and we're set to close anyway. */
+ k->keepon &= ~KEEP_READ;
+ }
*done = TRUE;
return CURLE_OK;
}
- /* We have a new url to load, but since we want to be able
- to re-use this connection properly, we read the full
- response in "ignore more" */
- k->ignorebody = TRUE;
- infof(data, "Ignoring the response-body\n");
+ if (!data->set.redirbodies) {
+ /* We have a new url to load, but since we want to be able
+ to re-use this connection properly, we read the full
+ response in "ignore more" */
+ k->ignorebody = TRUE;
+ infof(data, "Ignoring the response-body\n");
+ }
}
if (conn->resume_from && !k->content_range &&
(data->set.httpreq==HTTPREQ_GET) &&
Index: lib/url.c
===================================================================
RCS file: /cvsroot/curl/curl/lib/url.c,v
retrieving revision 1.469
diff -u -r1.469 url.c
--- lib/url.c 27 Jul 2005 22:29:50 -0000 1.469
+++ lib/url.c 28 Jul 2005 09:50:18 -0000
@@ -640,6 +640,14 @@
data->set.maxredirs = va_arg(param, long);
break;
+ case CURLOPT_REDIRBODIES:
+ /*
+ * Whether the bodies of redirects should be sent to the
+ * write_data() callback
+ */
+ data->set.redirbodies = va_arg(param, long)?TRUE:FALSE;
+ break;
+
case CURLOPT_POST:
/* Does this option serve a purpose anymore? Yes it does, when
CURLOPT_POSTFIELDS isn't used and the POST data is read off the
Index: lib/urldata.h
===================================================================
RCS file: /cvsroot/curl/curl/lib/urldata.h,v
retrieving revision 1.268
diff -u -r1.268 urldata.h
--- lib/urldata.h 12 Jul 2005 18:15:34 -0000 1.268
+++ lib/urldata.h 28 Jul 2005 09:50:22 -0000
@@ -951,6 +951,7 @@
on this syntax. */
long followlocation; /* as in HTTP Location: */
long maxredirs; /* maximum no. of http(s) redirects to follow */
+ long redirbodies; /* write bodies of redirects too */
char *set_referer; /* custom string */
bool free_referer; /* set TRUE if 'referer' points to a string we
allocated */
Received on 2005-07-28