From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NO_DNS_FOR_FROM,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 Received: from localhost.localdomain (unknown [180.246.144.41]) by gnuweeb.org (Postfix) with ESMTPSA id 287D880A16; Sun, 21 Aug 2022 11:25:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1661081139; bh=N6eNN0WrqLTgPZM4vBExcyHVgZ3ePbihO1juP1XtDEA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cs68hHR3IgD53AudhM3XYSGBJzGGe5oI4sjZtnK4GpKdbAagBbIvwsFfvFGVbjPt1 84dx5eTL6L5jQdxCJP0Rv8fqnrEOkYyaufEra7SVBIgC4ZJKcKT0EeOnvXaRP0XL7a jESQxDtNKvckuQlMEpPjA1RpBa/AxNkxU5EgMT8DgHOAqCLf2qZ++OFSqFeQUyWeJi g34m3fug7W+EG6A3hjGoZN0Yo9+ymRNGF3HqHyRnUgoiM4VYJf+/PhEJKj4USZTtXu Amu80tz+/mJ+wRYAG5kU4Z5sncbg8lErKrnH99FhYJOrarsHeWDlQWfz3wtht8Mkkv FZGtQ8xXguZbA== From: Ammar Faizi To: Alviro Iskandar Setiawan Cc: Ammar Faizi , Muhammad Rizki , Kanna Scarlet , GNU/Weeb Mailing List Subject: [PATCH v1 10/22] chnet: Split construct URL req creation into a new function Date: Sun, 21 Aug 2022 18:24:41 +0700 Message-Id: <20220821112453.3026255-11-ammarfaizi2@gnuweeb.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220821112453.3026255-1-ammarfaizi2@gnuweeb.org> References: <20220821112453.3026255-1-ammarfaizi2@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This is a preparation to add the set header function. We can efficiently set a new HTTP header if we create the URL request first as we don't have to have the copy of HTTP headers in a vector. Signed-off-by: Ammar Faizi --- chnet/chnet.cc | 9 ++++++++- chnet/chnet.h | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/chnet/chnet.cc b/chnet/chnet.cc index 058af89..67d420b 100644 --- a/chnet/chnet.cc +++ b/chnet/chnet.cc @@ -111,7 +111,7 @@ CHNetDelegate::~CHNetDelegate(void) sig.Wait(); } -void CHNetDelegate::_Start(Waiter *sig) +void CHNetDelegate::ConstructURLRequest(void) { net::URLRequestContextBuilder url_req_ctx_b; @@ -128,6 +128,13 @@ void CHNetDelegate::_Start(Waiter *sig) url_req_ctx_ = url_req_ctx_b.Build(); url_req_ = url_req_ctx_->CreateRequest(url_, DEFAULT_PRIORITY, this, traffic_annotation, false); +} + +void CHNetDelegate::_Start(Waiter *sig) +{ + if (!url_req_) + ConstructURLRequest(); + url_req_->set_method(method_); sig->Signal(); diff --git a/chnet/chnet.h b/chnet/chnet.h index 7f6359b..5e2392c 100644 --- a/chnet/chnet.h +++ b/chnet/chnet.h @@ -109,6 +109,7 @@ public: private: void _Start(Waiter *sig); + void ConstructURLRequest(void); std::unique_ptr url_req_ctx_; scoped_refptr read_buf_; -- Ammar Faizi