Diff for /parser3/src/main/pa_http.C between versions 1.94 and 1.99

version 1.94, 2020/10/14 16:51:46 version 1.99, 2020/10/29 14:26:07
Line 59  bool HTTP_Headers::add_header(const char Line 59  bool HTTP_Headers::add_header(const char
                         content_type=header.value;                          content_type=header.value;
   
                 if(header.name == String::Body("CONTENT-LENGTH") && content_length==0)                  if(header.name == String::Body("CONTENT-LENGTH") && content_length==0)
                         content_length=pa_atoul(header.value.cstr());                          ALTER_EXCEPTION_COMMENT(content_length=pa_atoul(header.value.cstr()), " for content-length");
   
                 headers+=header;                  headers+=header;
   
Line 105  public: Line 105  public:
         size_t body_offset;          size_t body_offset;
   
         HTTP_Headers headers;          HTTP_Headers headers;
         const String &url;  
   
         HTTP_response(const String& aurl) : buf(NULL), length(0), buf_size(0), body_offset(0), url(aurl){}          HTTP_response() : buf(NULL), length(0), buf_size(0), body_offset(0){}
   
         void resize(size_t size){          void resize(size_t size){
                 buf_size=size;                  buf_size=size;
Line 122  public: Line 121  public:
                         return false;                          return false;
                 if(received_size<0) {                  if(received_size<0) {
                         if(int no=pa_socks_errno())                          if(int no=pa_socks_errno())
                                 throw Exception("http.timeout", &url, "error receiving response body: %s (%d)", pa_socks_strerr(no), no);                                  throw Exception("http.timeout", 0, "error receiving response body: %s (%d)", pa_socks_strerr(no), no);
                         return false;                          return false;
                 }                  }
                 length+=received_size;                  length+=received_size;
Line 153  public: Line 152  public:
                         return status_line;                          return status_line;
   
                 const char *result_str=pa_strdup(status_start, status_end-status_start);                  const char *result_str=pa_strdup(status_start, status_end-status_start);
                 result=pa_atoui(result_str);                  ALTER_EXCEPTION_COMMENT(result=pa_atoui(result_str), " for HTTP status");
                 return result_str;                  return result_str;
         }          }
   
Line 186  public: Line 185  public:
                 for(;i.has_next();){                  for(;i.has_next();){
                         const char *line=i.next()->cstr();                          const char *line=i.next()->cstr();
                         if(!headers.add_header(line))                          if(!headers.add_header(line))
                                 throw Exception("http.response", &url, "bad response from host - bad header \"%s\"", line);                                  throw Exception("http.response", 0, "bad response from host - bad header \"%s\"", line);
                 }                  }
         }          }
   
Line 227  int HTTP_response::read_response(int soc Line 226  int HTTP_response::read_response(int soc
   
                                 parse_headers();                                  parse_headers();
   
                                 size_t content_length=check_file_size(headers.content_length, url);                                  size_t content_length=check_file_size(headers.content_length, 0);
                                 if(content_length>0 && (content_length + body_offset) > length){                                  if(content_length>0 && (content_length + body_offset) > length){
                                         resize(content_length + body_offset + 0x400*64);                                          resize(content_length + body_offset + 0x400*64);
                                 }                                  }
Line 244  int HTTP_response::read_response(int soc Line 243  int HTTP_response::read_response(int soc
         }          }
   
         if(state==HTTP_STATUS_CODE)          if(state==HTTP_STATUS_CODE)
                 throw Exception("http.response", &url, "bad response from host - no status found (size=%u)", length);                  throw Exception("http.response", 0, "bad response from host - no status found (size=%u)", length);
   
         if(state==HTTP_HEADERS){          if(state==HTTP_HEADERS){
                 parse_headers();                  parse_headers();
Line 864  File_read_http_result pa_internal_file_r Line 863  File_read_http_result pa_internal_file_r
         }          }
                   
   
         HTTP_response response(connect_string);          HTTP_response response;
   
         // sending request          // sending request
         int status_code=http_request(response, idna_host, port, request, request_size, timeout_secs, fail_on_status_ne_200);          int status_code;
           ALTER_EXCEPTION_SOURCE(status_code=http_request(response, idna_host, port, request, request_size, timeout_secs, fail_on_status_ne_200), &connect_string);
   
         // processing results          // processing results
         char* raw_body=response.buf + response.body_offset;          char* raw_body=response.buf + response.body_offset;
Line 926  public: Line 926  public:
         const char *method;          const char *method;
         const char *uri;          const char *uri;
   
         HTTPD_request() : HTTP_response(String::Empty), method(NULL), uri(NULL){};          HTTPD_request() : HTTP_response(), method(NULL), uri(NULL){};
   
         const char *extract_method(char *method_line){          const char *extract_method(char *method_line){
                 char* uri_start = strchr(method_line, ' ');                  char* uri_start = strchr(method_line, ' ');
Line 1001  void HTTPD_request::read_header(int sock Line 1001  void HTTPD_request::read_header(int sock
   
 size_t HTTPD_request::read_post(int sock, char *body, size_t max_bytes) {  size_t HTTPD_request::read_post(int sock, char *body, size_t max_bytes) {
         size_t total_read = min(length - body_offset, max_bytes);          size_t total_read = min(length - body_offset, max_bytes);
         memcpy(body, buf, total_read);          memcpy(body, buf + body_offset, total_read);
   
         while (total_read < max_bytes){          while (total_read < max_bytes){
                 ssize_t received_size = recv(sock, buf + total_read, max_bytes - total_read, 0);                  ssize_t received_size = recv(sock, body + total_read, max_bytes - total_read, 0);
                 if(received_size == 0)                  if(received_size == 0)
                         return total_read;                          return total_read;
                 if(received_size < 0) {                  if(received_size < 0) {
                         if(int no = pa_socks_errno())                          if(int no = pa_socks_errno())
                                 throw Exception("httpd.timeout", &url, "error receiving request body: %s (%d)", pa_socks_strerr(no), no);                                  throw Exception("httpd.timeout", new String(uri), "error receiving request body: %s (%d)", pa_socks_strerr(no), no);
                         return total_read;                          return total_read;
                 }                  }
                 total_read += received_size;                  total_read += received_size;

Removed from v.1.94  
changed lines
  Added in v.1.99


E-mail: