���� text/json ����
| 142 | |
| 143 | // ���� text/json ���� |
| 144 | bool do_json(http_response& res, const char* req_charset, string& err) { |
| 145 | json body; |
| 146 | if (res.get_body(body, local_charset_) == false) { |
| 147 | err += "get_body error"; |
| 148 | return false; |
| 149 | } |
| 150 | |
| 151 | json_node* node = body.first_node(); |
| 152 | while (node) { |
| 153 | if (node->tag_name()) { |
| 154 | printf("tag: %s", node->tag_name()); |
| 155 | if (node->get_text()) { |
| 156 | printf(", value: %s\r\n", node->get_text()); |
| 157 | } else { |
| 158 | printf("\r\n"); |
| 159 | } |
| 160 | } |
| 161 | node = body.next_node(); |
| 162 | } |
| 163 | |
| 164 | // ������Ӧͷ�ֶ� |
| 165 | http_header& header = res.response_header(); |
| 166 | string ctype("text/json"); |
| 167 | if (req_charset) { |
| 168 | ctype << "; charset=" << req_charset; |
| 169 | header.set_content_type(ctype); |
| 170 | } else { |
| 171 | header.set_content_type(ctype); |
| 172 | } |
| 173 | |
| 174 | printf(">>ctype: %s\r\n", ctype.c_str()); |
| 175 | |
| 176 | // ������Ӧ�����ݣ���������Ӧ������ |
| 177 | string buf; |
| 178 | body.build_json(buf); |
| 179 | |
| 180 | // ������Ӧ������ |
| 181 | return response_body(res, buf, req_charset); |
| 182 | } |
| 183 | |
| 184 | bool response_body(http_response& res, const string& body, |
| 185 | const char* req_charset) { |
nothing calls this directly
no test coverage detected