diff --git a/frameworks/native/http/http_client/http_client_request.cpp b/frameworks/native/http/http_client/http_client_request.cpp index 158b0118b46813eb9291d556f2489f4ba5f09f93..ab383bea36ad6849d503400b6697160f3792c471 100644 --- a/frameworks/native/http/http_client/http_client_request.cpp +++ b/frameworks/native/http/http_client/http_client_request.cpp @@ -100,11 +100,6 @@ void HttpClientRequest::SetHttpProxyType(HttpProxyType type) proxyType_ = type; } -void HttpClientRequest::SetMaxLimit(uint32_t maxLimit) -{ - maxLimit_ = maxLimit; -} - void HttpClientRequest::SetCaPath(const std::string &path) { if (path.empty()) { @@ -173,11 +168,6 @@ uint32_t HttpClientRequest::GetPriority() const return priority_; } -uint32_t HttpClientRequest::GetMaxLimit() const -{ - return maxLimit_; -} - void HttpClientRequest::SetHttpProxy(const HttpProxy &proxy) { proxy_ = proxy; diff --git a/interfaces/innerkits/http_client/include/http_client_request.h b/interfaces/innerkits/http_client/include/http_client_request.h index b8f8599c617c41ebea4018270636d2bcc72b01db..dc094e19dbabf2ad8039545ab5a43c27505959c6 100644 --- a/interfaces/innerkits/http_client/include/http_client_request.h +++ b/interfaces/innerkits/http_client/include/http_client_request.h @@ -112,12 +112,6 @@ public: */ void SetHttpProxy(const HttpProxy &proxy); - /** - * Set max limit data for the request. - * @param maxLimit The HTTP max limit data to be set. - */ - void SetMaxLimit(uint32_t maxLimit); - /** * Set the HTTP proxy type for the request. * @param type The HTTP proxy type to be set. @@ -208,12 +202,6 @@ public: */ [[nodiscard]] const HttpProxy &GetHttpProxy() const; - /** - * Get the dns servers of the request. - * @return The max limit data of the request. - */ - [[nodiscard]] uint32_t GetMaxLimit() const; - /** * Get the HTTP proxy type of the request. * @return The HTTP proxy type of the request. @@ -299,7 +287,6 @@ private: int64_t resumeTo_; HttpClientCert clientCert_; std::string addressFamily_; - uint32_t maxLimit_; }; } // namespace HttpClient } // namespace NetStack diff --git a/interfaces/kits/c/net_http/include/net_http_type.h b/interfaces/kits/c/net_http/include/net_http_type.h index d6efde3078f1ecae6e0204bee3aa1951df1a938c..612d0b9235d741f9f1912fea25cac2a408e6063e 100644 --- a/interfaces/kits/c/net_http/include/net_http_type.h +++ b/interfaces/kits/c/net_http/include/net_http_type.h @@ -132,7 +132,7 @@ typedef enum Http_ResponseCode { /** @brief The request has been accepted but has not been processed completely. */ OH_HTTP_ACCEPTED = 202, /** @brief Unauthorized information. The request was successful. */ - OH_HTTP_NOT_AUTHORITATIVE = 203, + OH_HTTP_NON_AUTHORITATIVE_INFO = 203, /** @brief No content. The server successfully processed, but did not return content. */ OH_HTTP_NO_CONTENT = 204, /** @brief Reset the content. */ @@ -140,7 +140,7 @@ typedef enum Http_ResponseCode { /** @brief Partial content. The server successfully processed some GET requests. */ OH_HTTP_PARTIAL = 206, /** @brief Multiple options. */ - OH_HTTP_MULT_CHOICE = 300, + OH_HTTP_MULTI_CHOICE = 300, /** * @brief Permanently move. The requested resource has been permanently moved to a new URI, * and the returned information will include the new URI. The browser will automatically redirect to the new URI. @@ -186,11 +186,11 @@ typedef enum Http_ResponseCode { /** @brief The request was rejected because the requested entity was too large for the server to process. */ OH_HTTP_ENTITY_TOO_LARGE = 413, /** @brief The requested URI is too long (usually a URL) and the server cannot process it. */ - OH_HTTP_REQ_TOO_LONG = 414, + OH_HTTP_REQUEST_TOO_LONG = 414, /** @brief The server is unable to process the requested format. */ OH_HTTP_UNSUPPORTED_TYPE = 415, /** @brief Requested Range not satisfiable. */ - OH_HTTP_RANGE_NOT_SATISFIABLE = 416, + OH_HTTP_RANGE_NOT_MET = 416, /** @brief Internal server error, unable to complete the request. */ OH_HTTP_INTERNAL_ERROR = 500, /** @brief The server does not support the requested functionality and cannot complete the request. */ @@ -458,8 +458,6 @@ typedef struct Http_RequestOptions { Http_ClientCert *clientCert; /** Set the DNS resolution for the https server. */ const char *dnsOverHttps; - /** Maximum number of bytes in a response message. */ - uint32_t maxLimit; /** The address family can be specified when target domain name is resolved, see {@link Http_AddressFamilyType}. */ Http_AddressFamilyType addressFamily; } Http_RequestOptions; @@ -516,10 +514,10 @@ typedef void (*Http_ResponseCallback)(struct Http_Response *response, uint32_t e * @brief Callback function that is invoked when a response body is received. * * @param data Response body. - * @return size_t the length of response body. + * @param length Length of response body. * @since 20 */ -typedef size_t (*Http_OnDataReceiveCallback)(const char *data); +typedef void (*Http_OnDataReceiveCallback)(const char *data, size_t length); /** * @brief Callback function invoked during request/response data transmission. diff --git a/interfaces/kits/c/net_http/src/net_http_c.cpp b/interfaces/kits/c/net_http/src/net_http_c.cpp index bbe8bcf1e78c0ef4004bfb68ec3b694ff9895d07..ec570de3f4d3fb183ff19a77b2f76a731ead8726 100644 --- a/interfaces/kits/c/net_http/src/net_http_c.cpp +++ b/interfaces/kits/c/net_http/src/net_http_c.cpp @@ -347,7 +347,6 @@ void OH_Http_SetOption(HttpClientRequest *httpReq, Http_Request *request) httpReq->SetHttpProxy(httpProxy); } } - httpReq->SetMaxLimit(request->options->maxLimit); //httpProtocol httpReq->SetHttpProtocol(static_cast(request->options->httpProtocol)); // caPath @@ -461,7 +460,7 @@ void OH_Http_RequestOnDataReceive(std::shared_ptr httpClientTask httpClientTask->OnDataReceive([handler] (const HttpClientRequest &request, const uint8_t *data, size_t length) { if (handler.onDataReceive != nullptr) { - handler.onDataReceive(reinterpret_cast(data)); + handler.onDataReceive(reinterpret_cast(data), length); } return OH_HTTP_RESULT_OK; }); diff --git a/test/fuzztest/httpcapi_fuzzer/http_capi_fuzzer.cpp b/test/fuzztest/httpcapi_fuzzer/http_capi_fuzzer.cpp index 2d90817151e18047f6e1a8f5d59aed0b3edb84a5..88dcfab658675475a12f972976c364bd165da4af 100644 --- a/test/fuzztest/httpcapi_fuzzer/http_capi_fuzzer.cpp +++ b/test/fuzztest/httpcapi_fuzzer/http_capi_fuzzer.cpp @@ -98,11 +98,12 @@ void Http_SampleResponseCallback(Http_Response *response, uint32_t errCode) { response->destroyResponse(&response); } -size_t Http_SampleOnDataReceiveCallback(const char *data) { - if (data == nullptr) { - return 0; +void HttpSampleOnDataReceiveCallback(const char *data, size_t length) +{ + if (data == nullptr || length == 0) { + return; } - return 0; + return; } void Http_SampleOnUploadProgressCallback(uint64_t totalSize, uint64_t transferredSize) { @@ -170,7 +171,7 @@ void HttpRequestTest(const uint8_t *data, size_t size) } request->options->headers = headers; Http_EventsHandler eventsHandler; - eventsHandler.onDataReceive = Http_SampleOnDataReceiveCallback; + eventsHandler.onDataReceive = HttpSampleOnDataReceiveCallback; eventsHandler.onCanceled = Http_SampleOnCancelCallback; eventsHandler.onDataEnd = Http_SampleOnEndCallback; eventsHandler.onDownloadProgress = Http_SampleOnDownloadProgressCallback; diff --git a/test/unittest/http_client/HttpClientRequestTest.cpp b/test/unittest/http_client/HttpClientRequestTest.cpp index 7cd83d53062bee4b800d58f7e1768d388dd359da..ac7400b3efa4da49012017f9e35eec564a487d9e 100644 --- a/test/unittest/http_client/HttpClientRequestTest.cpp +++ b/test/unittest/http_client/HttpClientRequestTest.cpp @@ -411,21 +411,4 @@ HWTEST_F(HttpClientRequestTest, SetClientCertTest002, TestSize.Level1) HttpClientCert client = req.GetClientCert(); EXPECT_EQ(client.keyPassword, ""); } - -HWTEST_F(HttpClientRequestTest, SetMaxLimitTest001, TestSize.Level1) -{ - HttpClientRequest req; - - req.SetMaxLimit(100); - uint32_t maxLimit = req.GetMaxLimit(); - EXPECT_EQ(maxLimit, 100); -} - -HWTEST_F(HttpClientRequestTest, GetMaxLimitTest001, TestSize.Level1) -{ - HttpClientRequest req; - - uint32_t maxLimit = req.GetMaxLimit(); - EXPECT_EQ(maxLimit, 0); -} } // namespace diff --git a/test/unittest/http_client/HttpClientTaskTest.cpp b/test/unittest/http_client/HttpClientTaskTest.cpp index efbc3e4d5a7aa70faabb0a2d129e2e787c2558c7..70e7e64531a2c8ce5a943426b677ffbc1318a1fd 100644 --- a/test/unittest/http_client/HttpClientTaskTest.cpp +++ b/test/unittest/http_client/HttpClientTaskTest.cpp @@ -700,7 +700,6 @@ HWTEST_F(HttpClientTaskTest, DataReceiveCallbackTest004, TestSize.Level1) std::string url = "http://www.httpbin.org/get"; const char *data = "http://www.httpbin.org/get"; httpReq.SetURL(url); - httpReq.SetMaxLimit(5); HttpSession &session = HttpSession::GetInstance(); auto task = session.CreateTask(httpReq); @@ -719,7 +718,6 @@ HWTEST_F(HttpClientTaskTest, DataReceiveCallbackTest005, TestSize.Level1) std::string url = "http://www.httpbin.org/get"; const char *data = "http://www.httpbin.org/get"; httpReq.SetURL(url); - httpReq.SetMaxLimit(20); HttpSession &session = HttpSession::GetInstance(); auto task = session.CreateTask(httpReq); @@ -738,7 +736,6 @@ HWTEST_F(HttpClientTaskTest, DataReceiveCallbackTest006, TestSize.Level1) std::string url = "http://www.httpbin.org/get"; const char *data = "http://www.httpbin.org/get"; httpReq.SetURL(url); - httpReq.SetMaxLimit(3); HttpSession &session = HttpSession::GetInstance(); auto task = session.CreateTask(httpReq); diff --git a/test/unittest/net_http/NetHttpTest.cpp b/test/unittest/net_http/NetHttpTest.cpp index fc0df1c4610820456bee12f7742e1a1f1e8ea4ce..041f9d5c59dbaa43fcb8a5ebe30f33a77ba7c8d4 100644 --- a/test/unittest/net_http/NetHttpTest.cpp +++ b/test/unittest/net_http/NetHttpTest.cpp @@ -56,10 +56,10 @@ static void testResponseCallback(struct Http_Response *response, uint32_t errCod NETSTACK_LOGI("testResponseCallback function called!"); } -static size_t testDataReceiveCallback(const char *data) +static void TestDataReceiveCallback(const char *data, size_t length) { NETSTACK_LOGI("testDataReceiveCallback function called!"); - return 0; + return; } static void testHeaderReceiveCallback(Http_Headers *headers) @@ -499,7 +499,7 @@ HWTEST_F(NetHttpTest, RequestOnDataReceive001, TestSize.Level1) Http_ResponseCallback callback = testResponseCallback; Http_EventsHandler handler; - Http_OnDataReceiveCallback onDataReceiveCallback = testDataReceiveCallback; + Http_OnDataReceiveCallback onDataReceiveCallback = TestDataReceiveCallback; handler.onDataReceive = onDataReceiveCallback; OH_Http_Request(request, callback, handler); OH_Http_Destroy(&request);