Diff for /parser3/src/main/pa_http.C between versions 1.65 and 1.71

version 1.65, 2015/04/30 17:37:43 version 1.71, 2016/07/21 17:05:37
Line 1 Line 1
 /** @file  /** @file
         Parser: http support functions.          Parser: http support functions.
   
         Copyright (c) 2001-2012 Art. Lebedev Studio (http://www.artlebedev.com)          Copyright (c) 2001-2015 Art. Lebedev Studio (http://www.artlebedev.com)
         Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)          Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
  */   */
   
Line 37  volatile const char * IDENT_PA_HTTP_C="$ Line 37  volatile const char * IDENT_PA_HTTP_C="$
 #define HTTP_USER "user"  #define HTTP_USER "user"
 #define HTTP_PASSWORD "password"  #define HTTP_PASSWORD "password"
   
   #define HTTP_USER_AGENT "user-agent"
 #define DEFAULT_USER_AGENT "parser3"  #define DEFAULT_USER_AGENT "parser3"
   
 #ifndef INADDR_NONE  #ifndef INADDR_NONE
Line 624  File_read_http_result pa_internal_file_r Line 625  File_read_http_result pa_internal_file_r
                                                 bool transcode_text_result) {                                                  bool transcode_text_result) {
         File_read_http_result result;          File_read_http_result result;
         char host[MAX_STRING];          char host[MAX_STRING];
           const char *idna_host;
         const char* uri;           const char* uri; 
         short port=80;          short port=80;
         const char* method="GET";          const char* method="GET";
Line 757  File_read_http_result pa_internal_file_r Line 759  File_read_http_result pa_internal_file_r
                                 throw Exception(PARSER_RUNTIME, &connect_string, "invalid port number '%s'", port_cstr);                                  throw Exception(PARSER_RUNTIME, &connect_string, "invalid port number '%s'", port_cstr);
                 }                  }
   
                   idna_host=pa_idna_encode(host, r.charsets.source());
   
                 // making request head                  // making request head
                 String head;                  String head;
                 head << method << " " << uri;                  head << method << " " << uri;
                 if(method_is_get && form)                  if(method_is_get && form)
                         head << (strchr(uri, '?')!=0?"&":"?") << pa_form2string(*form, r.charsets);                          head << (strchr(uri, '?')!=0?"&":"?") << pa_form2string(*form, r.charsets);
   
                 head <<" HTTP/1.0" CRLF "Host: "<< host;                  head <<" HTTP/1.0" CRLF "Host: "<< idna_host;
                 if (port != 80)                  if (port != 80)
                         head << ":" << port_cstr;                          head << ":" << port_cstr;
                 head << CRLF;                  head << CRLF;
   
                 char* boundary=0;                  char* boundary= multipart ? get_uuid_boundary() : 0;
   
                 if(multipart){  
                         uuid uuid=get_uuid();  
                         const int boundary_bufsize=10+32+1/*for zero-teminator*/+1/*for faulty snprintfs*/;  
                         boundary=new(PointerFreeGC) char[boundary_bufsize];  
                         snprintf(boundary, boundary_bufsize,  
                                 "----------%08X%04X%04X%02X%02X%02X%02X%02X%02X%02X%02X",  
                                 uuid.time_low, uuid.time_mid, uuid.time_hi_and_version,  
                                 uuid.clock_seq >> 8, uuid.clock_seq & 0xFF,  
                                 uuid.node[0], uuid.node[1], uuid.node[2],  
                                 uuid.node[3], uuid.node[4], uuid.node[5]);  
                 }  
   
                 String user_headers;                  String user_headers;
                 bool user_agent_specified=false;                  bool user_agent_specified=false;
Line 828  File_read_http_result pa_internal_file_r Line 820  File_read_http_result pa_internal_file_r
                                         String::C(vbody->as_string().cstr(), vbody->as_string().length()),                                          String::C(vbody->as_string().cstr(), vbody->as_string().length()),
                                         r.charsets.source(),                                          r.charsets.source(),
                                         *asked_remote_charset                                          *asked_remote_charset
                                 );                                  ).str;
                         }                          }
                         post_size=strlen(request_body);                          post_size=strlen(request_body);
                 }                  }
Line 884  File_read_http_result pa_internal_file_r Line 876  File_read_http_result pa_internal_file_r
   
         // sending request          // sending request
         int status_code=http_request(response, response_size,          int status_code=http_request(response, response_size,
                 pa_idna_encode(host, r.charsets.source()), port, request, request_size,                  idna_host, port, request, request_size,
                 timeout_secs, fail_on_status_ne_200);                   timeout_secs, fail_on_status_ne_200); 
                   
         // processing results             // processing results   
Line 954  File_read_http_result pa_internal_file_r Line 946  File_read_http_result pa_internal_file_r
                         result.headers->put(HTTP_COOKIES_NAME, new VTable(parse_cookies(r, vcookies->get_table())));                          result.headers->put(HTTP_COOKIES_NAME, new VTable(parse_cookies(r, vcookies->get_table())));
         }          }
   
         if(as_text && raw_body_size>=3 && strncmp(raw_body, "\xEF\xBB\xBF", 3)==0){          if(as_text){
                 // skip UTF-8 signature (BOM code)                  real_remote_charset=charsets.checkBOM(raw_body, raw_body_size, real_remote_charset);
                 raw_body+=3;  
                 raw_body_size-=3;  
                 if(!real_remote_charset)  
                         real_remote_charset=&UTF8_charset;  
         }          }
   
         // output response          // output response

Removed from v.1.65  
changed lines
  Added in v.1.71


E-mail: