curl-library
Re: CURLOPT_HEADERFUNCTION with non-HTTP response ?
Date: Wed, 4 Dec 2002 01:14:01 +0800
diff -ru curl-7.10.2/include/curl/curl.h curl-7.10.2.simon/include/curl/curl.h
--- curl-7.10.2/include/curl/curl.h Tue Nov 19 06:04:34 2002
+++ curl-7.10.2.simon/include/curl/curl.h Wed Dec 4 01:04:24 2002
@@ -609,7 +609,9 @@
/* Set the Accept-Encoding string. Use this to tell a server you would like
the response to be compressed. */
CINIT(ENCODING, OBJECTPOINT, 102),
-
+
+ /* Set aliases for HTTP 200 in the HTTP Response header */
+ CINIT(HTTP200ALIASES, OBJECTPOINT, 103),
CURLOPT_LASTENTRY /* the last unused */
} CURLoption;
diff -ru curl-7.10.2/lib/transfer.c curl-7.10.2.simon/lib/transfer.c
--- curl-7.10.2/lib/transfer.c Tue Nov 12 07:03:04 2002
+++ curl-7.10.2.simon/lib/transfer.c Wed Dec 4 01:05:02 2002
@@ -114,6 +114,21 @@
KEEP_WRITE
};
+/*
+ * checkPrefixAgainstList()
+ *
+ * Returns TRUE if member of the list matches prefix of string
+ */
+static bool
+checkPrefixAgainstList( const char *s,
+ struct curl_slist *head )
+{
+ while (head) {
+ if (checkprefix(head->data, s)) return TRUE;
+ head = head->next;
+ }
+ return FALSE;
+}
/*
* compareheader()
@@ -291,7 +306,9 @@
k->hbuflen += nread;
if (!k->headerline && (k->hbuflen>5)) {
/* make a first check that this looks like a HTTP header */
- if(!checkprefix("HTTP/", data->state.headerbuff)) {
+ if(!checkprefix("HTTP/", data->state.headerbuff) &&
+ !checkPrefixAgainstList(
+ data->state.headerbuff, data->set.http200aliases)) {
/* this is not the beginning of a HTTP first header line */
k->header = FALSE;
k->badheader = HEADER_ALLBAD;
@@ -345,7 +362,9 @@
if(!k->headerline) {
/* the first read header */
if((k->hbuflen>5) &&
- !checkprefix("HTTP/", data->state.headerbuff)) {
+ !checkprefix("HTTP/", data->state.headerbuff) &&
+ !checkPrefixAgainstList(
+ data->state.headerbuff, data->set.http200aliases)) {
/* this is not the beginning of a HTTP first header line */
k->header = FALSE;
k->badheader = HEADER_PARTHEADER;
@@ -472,6 +491,19 @@
*/
nc=sscanf (k->p, " HTTP %3d", &k->httpcode);
k->httpversion = 10;
+
+ /* If user has set option HTTP200ALIASES,
+ compare header line against list of aliases
+ */
+ if (!nc) {
+ if (checkPrefixAgainstList(
+ k->p, data->set.http200aliases)) {
+ nc = 1;
+ k->httpcode = 200;
+ k->httpversion =
+ data->set.httpversion==CURL_HTTP_VERSION_1_0 ? 10 : 11;
+ }
+ }
}
if (nc) {
diff -ru curl-7.10.2/lib/url.c curl-7.10.2.simon/lib/url.c
--- curl-7.10.2/lib/url.c Tue Nov 12 07:03:05 2002
+++ curl-7.10.2.simon/lib/url.c Wed Dec 4 01:05:02 2002
@@ -1088,6 +1088,13 @@
data->set.proxytype = va_arg(param, long);
break;
+ case CURLOPT_HTTP200ALIASES:
+ /*
+ * Set a list of aliases for HTTP 200 in response header
+ */
+ data->set.http200aliases = va_arg(param, struct curl_slist *);
+ break;
+
default:
/* unknown tag and its companion, just ignore: */
return CURLE_FAILED_INIT; /* correct this */
diff -ru curl-7.10.2/lib/urldata.h curl-7.10.2.simon/lib/urldata.h
--- curl-7.10.2/lib/urldata.h Tue Nov 12 07:03:05 2002
+++ curl-7.10.2.simon/lib/urldata.h Wed Dec 4 01:05:02 2002
@@ -686,6 +686,8 @@
int dns_cache_timeout; /* DNS cache timeout */
long buffer_size; /* size of receive buffer to use */
+
+ struct curl_slist *http200aliases; /* linked list of aliases for http200 */
/* Here follows boolean settings that define how to behave during
this session. They are STATIC, set by libcurl users or at least initially
Hi Daniel,
On Monday, December 2, 2002, at 11:37 PM, Daniel Stenberg wrote:
>
> 1. Use diff -u, otherwise I can't apply it properly on my sources (since
> they
> have changed since the version you made your diff against)
I have now used "diff -ru" as I saw you recommend this in another post.
Hope this is okay.
>
> 2. Please don't write source code wider than 79 columns.
Fixed.
>
> 3. I'd say that the code for checking for the aliases would better be
> placed
> in a separate function rather than having the code duplicated.
Done
>
--Simon Liu
-------------------------------------------------------
This SF.net email is sponsored by: Microsoft Visual Studio.NET
comprehensive development tool, built to increase your
productivity. Try a free online hosted session at:
http://ads.sourceforge.net/cgi-bin/redirect.pl?micr0003en
Received on 2002-12-03