|
|
| version 1.65, 2015/04/30 17:37:43 | version 1.69, 2015/10/26 01:21:58 |
|---|---|
| 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 624 File_read_http_result pa_internal_file_r | Line 624 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 758 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; |
| Line 828 File_read_http_result pa_internal_file_r | Line 831 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 887 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 957 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 |