--- parser3/src/classes/curl.C 2010/10/21 15:06:27 1.7 +++ parser3/src/classes/curl.C 2011/01/07 23:57:04 1.11 @@ -8,7 +8,7 @@ #ifdef HAVE_CURL -static const char * const IDENT_INET_C="$Date: 2010/10/21 15:06:27 $"; +static const char * const IDENT_INET_C="$Date: 2011/01/07 23:57:04 $"; #include "pa_vmethod_frame.h" #include "pa_request.h" @@ -17,6 +17,7 @@ static const char * const IDENT_INET_C=" #include "pa_vstring.h" #include "pa_vtable.h" #include "pa_common.h" +#include "pa_http.h" #include "ltdl.h" class MCurl: public Methoded { @@ -88,13 +89,9 @@ public: }; -// using thread local variables instead of keeping them in request -// not necessary for cgi version -#ifdef WIN32 -#define __thread __declspec(thread) -#endif -__thread CURL *fcurl = 0; -__thread ParserOptions *foptions = 0; +// using TLS instead of keeping variables in request +THREAD_LOCAL CURL *fcurl = 0; +THREAD_LOCAL ParserOptions *foptions = 0; static CURL *curl(){ if(!fcurl) @@ -249,7 +246,9 @@ public: CURL_OPT(CURL_INT, HTTP_TRANSFER_DECODING); CURL_OPT(CURL_INT, MAXREDIRS); +#ifdef CURLOPT_POSTREDIR CURL_OPT(CURL_INT, POSTREDIR); +#endif CURL_OPT(CURL_STRING, RANGE); @@ -318,9 +317,9 @@ static struct curl_slist *curl_headers(H for(HashStringValue::Iterator i(*value_hash); i; i.next() ){ String header = - String(capitalize(i.key().cstr()), String::L_URI) + String(pa_http_safe_header_name(capitalize(i.key().cstr())), String::L_AS_IS) << ": " - << String(i.value()->as_string(), String::L_URI); + << String(i.value()->as_string(), String::L_HTTP_HEADER); slist=f_curl_slist_append(slist, curl_urlencode(header, r)); } @@ -580,8 +579,11 @@ static void _curl_load_action(Request& r VFile& result=*new VFile; String::Body ct_header = headers.get(HTTP_CONTENT_TYPE_UPPER); - Charset *remote_charset = ct_header.is_empty() ? 0 : detect_charset(ct_header.trim(String::TRIM_BOTH, " \t\n\r").cstr()); - Charset *asked_charset = options().response_charset ? options().response_charset : (remote_charset ? remote_charset : options().charset); + Charset *asked_charset = options().response_charset; + if (asked_charset == 0){ + Charset *remote_charset = ct_header.is_empty() ? 0 : detect_charset(ct_header.trim(String::TRIM_BOTH, " \t\n\r").cstr()); + asked_charset = remote_charset ? remote_charset : options().charset; + } if(options().is_text && asked_charset != 0){ String::C c=Charset::transcode(String::C(body.buf, body.length), *asked_charset, r.charsets.source());