--- parser3/src/main/pa_http.C 2010/10/16 22:24:20 1.48 +++ parser3/src/main/pa_http.C 2010/12/29 12:17:58 1.50 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char * const IDENT_HTTP_C="$Date: 2010/10/16 22:24:20 $"; +static const char * const IDENT_HTTP_C="$Date: 2010/12/29 12:17:58 $"; #include "pa_http.h" #include "pa_common.h" @@ -295,6 +295,19 @@ struct Http_pass_header_info { bool* content_type_url_encoded; }; #endif + +char *pa_http_safe_header_name(const char *name) { + char *result=pa_strdup(name); + char *n=result; + if(isdigit(*n)) + *n++ = '_'; + for(; *n; ++n) { + if (!isalnum(*n) && *n != '_') + *n = '_'; + } + return result; +} + static void http_pass_header(HashStringValue::key_type aname, HashStringValue::value_type avalue, Http_pass_header_info *info) { @@ -304,8 +317,8 @@ static void http_pass_header(HashStringV if(strcasecmp(name_cstr, HTTP_CONTENT_LENGTH)==0) return; - String name=String(capitalize(name_cstr), String::L_URI); - String value=attributed_meaning_to_string(*avalue, String::L_URI, true); + String name=String(pa_http_safe_header_name(capitalize(name_cstr)), String::L_AS_IS); + String value=attributed_meaning_to_string(*avalue, String::L_HTTP_HEADER, true); *info->request << name << ": " << value << CRLF; @@ -521,7 +534,7 @@ File_read_http_result pa_internal_file_r File_read_http_result result; char host[MAX_STRING]; const char* uri; - short port; + short port=80; const char* method="GET"; bool method_is_get=true; HashStringValue* form=0; @@ -641,8 +654,13 @@ File_read_http_result pa_internal_file_r char* host_uri=lsplit(host, '/'); uri=host_uri?current+(host_uri-1-host):"/"; char* port_cstr=lsplit(host, ':'); - char* error_pos=0; - port=port_cstr?(short)strtol(port_cstr, &error_pos, 0):80; + + if (port_cstr){ + char* error_pos=0; + port=(short)strtol(port_cstr, &error_pos, 10); + if(port==0 || *error_pos) + throw Exception(PARSER_RUNTIME, &connect_string, "invalid port number '%s'", port_cstr); + } // making request head String head; @@ -650,7 +668,10 @@ File_read_http_result pa_internal_file_r if(method_is_get && form) head << (strchr(uri, '?')!=0?"&":"?") << pa_form2string(*form, r.charsets); - head <<" HTTP/1.0" CRLF "Host: "<< host << CRLF; + head <<" HTTP/1.0" CRLF "Host: "<< host; + if (port != 80) + head << ":" << port_cstr; + head << CRLF; char* boundary=0;