ithewei 4 vuotta sitten
vanhempi
commit
9505910b87
2 muutettua tiedostoa jossa 12 lisäystä ja 4 poistoa
  1. 9 4
      http/client/AsyncHttpClient.cpp
  2. 3 0
      http/client/http_client.cpp

+ 9 - 4
http/client/AsyncHttpClient.cpp

@@ -133,16 +133,21 @@ int AsyncHttpClient::doTask(const HttpClientTaskPtr& task) {
 int AsyncHttpClient::sendRequest(const SocketChannelPtr& channel) {
     HttpClientContext* ctx = (HttpClientContext*)channel->context();
     assert(ctx != NULL && ctx->task != NULL);
+    HttpRequest* req = ctx->task->req.get();
+    HttpResponse* resp = ctx->resp.get();
 
     if (ctx->parser == NULL) {
         ctx->parser.reset(HttpParser::New(HTTP_CLIENT, (http_version)ctx->task->req->http_major));
     }
-    if (ctx->resp == NULL) {
-        ctx->resp.reset(new HttpResponse);
+    if (resp == NULL) {
+        resp = new HttpResponse;
+        ctx->resp.reset(resp);
     }
+    if (req->body_cb)    resp->body_cb = std::move(req->body_cb);
+    if (req->chunked_cb) resp->chunked_cb = std::move(req->chunked_cb);
 
-    ctx->parser->InitResponse(ctx->resp.get());
-    ctx->parser->SubmitRequest(ctx->task->req.get());
+    ctx->parser->InitResponse(resp);
+    ctx->parser->SubmitRequest(req);
 
     char* data = NULL;
     size_t len = 0;

+ 3 - 0
http/client/http_client.cpp

@@ -150,6 +150,9 @@ int http_client_send(http_client_t* cli, HttpRequest* req, HttpResponse* resp) {
         }
     }
 
+    if (req->body_cb)    resp->body_cb = std::move(req->body_cb);
+    if (req->chunked_cb) resp->chunked_cb = std::move(req->chunked_cb);
+
     int ret = __http_client_send(cli, req, resp);
     if (ret != 0) return ret;