--- parser3/src/main/pa_http.C 2005/11/24 12:28:48 1.1 +++ parser3/src/main/pa_http.C 2006/04/09 13:38:47 1.3 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char * const IDENT_HTTP_C="$Date: 2005/11/24 12:28:48 $"; +static const char * const IDENT_HTTP_C="$Date: 2006/04/09 13:38:47 $"; #include "pa_http.h" #include "pa_common.h" @@ -91,9 +91,24 @@ static int http_read_response(char*& res "error receiving response header: %s (%d)", pa_socks_strerr(no), no); goto done; } + // terminator [helps futher string searches] + preview_buf[received_size]=0; + // checking status + if(char* EOLat=strstr(preview_buf, "\n")) { + const String status_line(pa_strdup(preview_buf, EOLat-preview_buf)); + ArrayString astatus; + size_t pos_after=0; + status_line.split(astatus, pos_after, " "); + const String& status_code=*astatus.get(astatus.count()>1?1:0); + result=status_code.as_int(); + + if(fail_on_status_ne_200 && result!=200) + throw Exception("http.status", + &status_code, + "invalid HTTP response status"); + } // detecting response_size { - preview_buf[received_size]=0; // terminator if(size_t content_length=guess_content_length(preview_buf)) response_size=preview_size+content_length; // a little more than needed, will adjust response_size by actual received size later } @@ -144,21 +159,6 @@ static int http_read_response(char*& res // can't do this before realloc: we need 1?1:0); - result=status_code.as_int(); - - if(fail_on_status_ne_200 && result!=200) - throw Exception("http.status", - &status_code, - "invalid HTTP response status"); - } } } done: @@ -382,7 +382,7 @@ static void form_value2string( } const char* pa_form2string(HashStringValue& form) { String string; - form.for_each(form_value2string, &string); + form.for_each(form_value2string, &string); return string.cstr(String::L_UNSPECIFIED); } static void find_headers_end(char* p, @@ -527,7 +527,7 @@ File_read_http_result pa_internal_file_r if(vheaders && !vheaders->is_string()) { // allow empty if(HashStringValue *headers=vheaders->get_hash()) { Http_pass_header_info info={&charsets, &head, false}; - headers->for_each(http_pass_header, &info); + headers->for_each(http_pass_header, &info); user_agent_specified=info.user_agent_specified; } else throw Exception("parser.runtime",