--- parser3/src/classes/curl.C 2016/11/01 23:10:39 1.46 +++ parser3/src/classes/curl.C 2016/12/28 22:50:06 1.49 @@ -17,7 +17,7 @@ #include "pa_http.h" #include "ltdl.h" -volatile const char * IDENT_CURL_C="$Id: curl.C,v 1.46 2016/11/01 23:10:39 moko Exp $"; +volatile const char * IDENT_CURL_C="$Id: curl.C,v 1.49 2016/12/28 22:50:06 moko Exp $"; class MCurl: public Methoded { public: @@ -398,7 +398,7 @@ static void curl_form(HashStringValue *v static const char *curl_check_file(const String &file_spec){ const char *file_spec_cstr=file_spec.taint_cstr(String::L_FILE_SPEC); struct stat finfo; - if(stat(file_spec_cstr, &finfo)==0) + if(pa_stat(file_spec_cstr, &finfo)==0) check_safe_mode(finfo, file_spec, file_spec_cstr); return file_spec_cstr; } @@ -453,21 +453,19 @@ static void curl_setopt(HashStringValue: break; } case CurlOption::CURL_FORM:{ - HashStringValue *value_hash = v.get_hash(); + HashStringValue *value_hash = v.as_hash("failed to set option 'httppost': value"); if(value_hash){ curl_form(value_hash, r); - } else if(v.get_string()->is_empty()){ + } else { f_curl_formfree(options().f_post); options().f_post = 0; - } else { - throw Exception("curl", 0, "failed to set option '%s': value must be a hash", key.cstr()); } res=f_curl_easy_setopt(curl(), CURLOPT_HTTPPOST, foptions->f_post); break; } case CurlOption::CURL_HEADERS:{ // http headers curl option - HashStringValue *value_hash=v.get_hash(); + HashStringValue *value_hash=v.as_hash("failed to set option 'httpheader': value"); res=f_curl_easy_setopt(curl(), opt->id, value_hash ? curl_headers(value_hash, r) : 0); break; } @@ -617,7 +615,13 @@ static int curl_header(char *data, size_ size=size*nmemb; if(size>0){ - result->add_header(pa_strdup(data, size)); + char *header=pa_strdup(data, size); + if(!pa_strncasecmp(header, "HTTP/") && !strchr(header, ':')){ + // response code, clearing possible headers from previous requests + result->clear(); + } else { + result->add_header(header); + } } return size; }