libhv icon indicating copy to clipboard operation
libhv copied to clipboard

http_client_send_async返回状态正常,但是body偶尔为空的问题

Open LOUTINIER opened this issue 10 months ago • 4 comments

http_client_send_async(req, [=](const HttpResponsePtr &resp) {
if (resp != nullptr)
        {
            resp->body; //body=""
            resp->status_code; // status_code=200
        }
        else
        {
        }
}

有没有人遇到这种情况,发生这种情况时服务端并未收到这条请求,但是libhv确实返回了200以及空body

LOUTINIER avatar Feb 12 '25 12:02 LOUTINIER

resp->Dump(true, false),打印下整个响应头看看

ithewei avatar Feb 18 '25 03:02 ithewei

空body的头dump出来是这样的

HTTP/1.1 200 OK
Content-Length: 0
Date: Tue, 18 Feb 2025 03:58:28 GMT

正常的是这样的

HTTP/1.1 200 OK
Access-Control-Allow-Headers: *
Access-Control-Allow-Methods: *
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: *
Access-Control-Max-Age: 5
Connection: keep-alive
Content-Type: text/json;charset=UTF-8
Date: Tue, 18 Feb 2025 03:58:17 GMT
Server: APISIX/3.10.0
Transfer-Encoding: chunked
Vary: Accept-Encoding
X-Powered-By: AtomCode v3.3.2
X-Request-Id: 14af424c-b36a-4fee-a81b-47dcce23b1b9

LOUTINIER avatar Feb 18 '25 04:02 LOUTINIER

成功回调最终是调用这里,上面是有判断解析器状态的,https://github.com/ithewei/libhv/blob/4f05ec33106df4f6af14b474b61543156af25db9/http/client/AsyncHttpClient.cpp#L115 你可以加点日志看看

ithewei avatar Feb 18 '25 06:02 ithewei

好,近期没空,后面再看看

LOUTINIER avatar Feb 19 '25 06:02 LOUTINIER