Copilot commented on code in PR #62110:
URL: https://github.com/apache/doris/pull/62110#discussion_r3033411811


##########
be/src/service/http/action/stream_load.cpp:
##########
@@ -906,9 +906,15 @@ Status StreamLoadAction::_check_wal_space(const 
std::string& group_commit_mode,
 Status StreamLoadAction::_can_group_commit(HttpRequest* req, 
std::shared_ptr<StreamLoadContext> ctx,
                                            std::string& group_commit_header,
                                            bool& can_group_commit) {
-    int64_t content_length = req->header(HttpHeaders::CONTENT_LENGTH).empty()
-                                     ? 0
-                                     : 
std::stoll(req->header(HttpHeaders::CONTENT_LENGTH));
+    int64_t content_length = 0;
+    if (!req->header(HttpHeaders::CONTENT_LENGTH).empty()) {
+        try {
+            content_length = 
std::stoll(req->header(HttpHeaders::CONTENT_LENGTH));
+        } catch (const std::exception& e) {
+            return Status::InvalidArgument("invalid HTTP header 
CONTENT_LENGTH={}: {}",
+                                           
req->header(HttpHeaders::CONTENT_LENGTH), e.what());

Review Comment:
   `req->header(HttpHeaders::CONTENT_LENGTH)` is looked up multiple times 
(empty check, parsing, and again in the error message). Since 
`HttpRequest::header()` does a map lookup each call, consider caching the 
header value (e.g., `const auto& content_length_str = ...`) and using that for 
the empty check / `stoll` / error message to avoid redundant lookups and ensure 
the reported value matches what was parsed.
   ```suggestion
       const auto& content_length_str = 
req->header(HttpHeaders::CONTENT_LENGTH);
       if (!content_length_str.empty()) {
           try {
               content_length = std::stoll(content_length_str);
           } catch (const std::exception& e) {
               return Status::InvalidArgument("invalid HTTP header 
CONTENT_LENGTH={}: {}",
                                              content_length_str, e.what());
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to