MCPcopy Create free account
hub / github.com/acl-dev/acl / request

Method request

lib_acl_cpp/src/http/http_request.cpp:409–480  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

407}
408
409bool http_request::request(const void* data, size_t len) {
410 bool have_retried = false;
411 bool reuse_conn;
412 http_method_t method = header_.get_method();
413
414 // ���� HTTP ����ͷ
415 if (data && len > 0) {
416 header_.set_content_length(len);
417
418 if (method != HTTP_METHOD_POST && method != HTTP_METHOD_PUT
419 && method != HTTP_METHOD_PATCH) {
420
421 // ����������������£��������� HTTP ���󷽷�
422 header_.set_method(HTTP_METHOD_POST);
423 }
424 } else if (method == HTTP_METHOD_POST || method == HTTP_METHOD_PUT) {
425 header_.set_content_length(0);
426 }
427
428 while (true) {
429 // ���Դ�Զ������
430 if (!try_open(&reuse_conn)) {
431 logger_error("connect server error");
432 return false;
433 }
434
435 // ���� HTTP ������������
436 if (!send_request(data, len)) {
437 if (have_retried || !reuse_conn) {
438 logger_error("send request error");
439 return false;
440 }
441
442 // �ȹر�֮ǰ��������
443 close();
444
445 // ���ڳ����ӣ�����ǵ�һ��IOʧ�ܣ������������һ��
446 have_retried = true;
447 continue;
448 }
449
450 if (client_) {
451 client_->reset(); // ����״̬
452 if (client_->read_head()) { // �� HTTP ��Ӧͷ
453 break;
454 }
455 }
456
457 if (last_error() == ECANCELED) {
458 //logger_error("read response canceled");
459 return false;
460 }
461
462 if (have_retried || !reuse_conn) {
463 logger_error("read response header error");
464 return false;
465 }
466

Callers

nothing calls this directly

Calls 5

last_errorFunction · 0.85
get_methodMethod · 0.80
read_headMethod · 0.80
closeFunction · 0.50
resetMethod · 0.45

Tested by

no test coverage detected