--- parser3/src/classes/curl.C 2012/04/24 21:53:32 1.19 +++ parser3/src/classes/curl.C 2013/03/10 23:36:00 1.23 @@ -16,7 +16,7 @@ #include "pa_http.h" #include "ltdl.h" -volatile const char * IDENT_CURL_C="$Id: curl.C,v 1.19 2012/04/24 21:53:32 moko Exp $"; +volatile const char * IDENT_CURL_C="$Id: curl.C,v 1.23 2013/03/10 23:36:00 misha Exp $"; class MCurl: public Methoded { public: @@ -493,10 +493,8 @@ static void _curl_options(Request& r, Me if(curl_options==0) curl_options=new CurlOptionHash(); - if(HashStringValue* options=params.as_no_junction(0, OPTIONS_MUST_NOT_BE_CODE).get_hash()){ + if(HashStringValue* options=params.as_hash(0)) options->for_each(curl_setopt, r); - } else - throw Exception("curl", 0, OPTIONS_MUST_BE_HASH); } @@ -600,26 +598,41 @@ static void _curl_load_action(Request& r body.length=c.length; } - result.set(true /*tainted*/, body.buf, body.length, options().filename - , options().content_type ? new VString(*options().content_type) : 0 - , &r); - result.set_mode(options().is_text); - + result.set(true/*tainted*/, options().is_text, body.buf, body.length, options().filename + , options().content_type ? new VString(*options().content_type) : 0, &r); long http_status = 0; if(f_curl_easy_getinfo(curl(), CURLINFO_RESPONSE_CODE, &http_status) == CURLE_OK){ result.fields().put("status", new VInt(http_status)); } + Table *cookies=0; for(HASH_STRING::Iterator i(headers); i; i.next() ){ - String::Body key=i.key(); + String::Body HEADER_NAME=i.key(); String::Body value=i.value(); if(asked_charset){ - key=Charset::transcode(key, *asked_charset, r.charsets.source()); + HEADER_NAME=Charset::transcode(HEADER_NAME, *asked_charset, r.charsets.source()); value=Charset::transcode(value, *asked_charset, r.charsets.source()); } - result.fields().put(key, new VString(*new String(value.trim(String::TRIM_BOTH, " \t\n\r"), String::L_TAINTED))); + const String& header_value=*new String(value.trim(String::TRIM_BOTH, " \t\n\r"), String::L_TAINTED); + result.fields().put(HEADER_NAME, new VString(header_value)); + + if(HEADER_NAME == "SET-COOKIE") { + if(!cookies){ + // first appearence + Table::columns_type columns=new ArrayString(1); + *columns+=new String("value"); + cookies=new Table(columns); + } + ArrayString& row=*new ArrayString(1); + row+=&header_value; + *cookies+=&row; + } } + // filling $.cookies + if(cookies) + result.fields().put(HTTP_COOKIES_NAME, new VTable(parse_cookies(r, cookies))); + r.write_no_lang(result); }