| 105 | } |
| 106 | |
| 107 | bool http_response::get_body(xml& out, const char* to_charset /* = NULL */) |
| 108 | { |
| 109 | if (!header_ok_) { |
| 110 | logger_error("header not read yet"); |
| 111 | return false; |
| 112 | } else if (client_->body_length() == 0) { |
| 113 | return true; |
| 114 | } else if (client_->body_length() < 0) { |
| 115 | const char* method = client_->request_method(); |
| 116 | if (method && (strcmp(method, "GET") == 0 |
| 117 | || strcmp(method, "CONNECT") == 0)) { |
| 118 | |
| 119 | return true; |
| 120 | } |
| 121 | |
| 122 | logger_error("client request body length(%d) invalid", |
| 123 | (int) client_->body_length()); |
| 124 | return false; |
| 125 | } |
| 126 | |
| 127 | if (debug_) { |
| 128 | client_->print_header("----request---"); |
| 129 | } |
| 130 | |
| 131 | http_pipe* hp = get_pipe(to_charset); |
| 132 | if (hp) { |
| 133 | hp->append(&out); |
| 134 | } |
| 135 | |
| 136 | string buf; |
| 137 | int ret; |
| 138 | |
| 139 | while (true) { |
| 140 | // ѭ����ȡ�ͻ������������� |
| 141 | ret = client_->read_body(buf); |
| 142 | if (ret == 0) { |
| 143 | break; |
| 144 | } |
| 145 | if (ret < 0) { |
| 146 | logger_error("read client body error"); |
| 147 | close(); |
| 148 | return false; |
| 149 | } |
| 150 | |
| 151 | // ��ʽ���� xml ��ʽ�������� |
| 152 | if (hp) { |
| 153 | hp->update(buf.c_str(), ret); |
| 154 | } else { |
| 155 | out.update(buf.c_str()); |
| 156 | } |
| 157 | if (debug_) { |
| 158 | printf("%s", buf.c_str()); |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | if (hp) { |
| 163 | hp->update_end(); |
| 164 | delete hp; |
nothing calls this directly
no test coverage detected