Aias00 commented on code in PR #977:
URL: https://github.com/apache/dubbo-go-pixiu/pull/977#discussion_r3393283625


##########
pkg/hotreload/http_handler.go:
##########
@@ -95,14 +98,20 @@ func (h *ReloadHandler) ServeHTTP(w http.ResponseWriter, r 
*http.Request) {
        // Try to read from body first (handles chunked encoding where 
ContentLength == -1)
        // If body is empty, fallback to file reload
        if r.Body != nil {
-               content, readErr := io.ReadAll(r.Body)
+               content, readErr := io.ReadAll(io.LimitReader(r.Body, 
maxReloadBodyBytes+1))
 
                if readErr != nil {
                        logger.Errorf("Failed to read request body: %v", 
readErr)
                        http.Error(w, fmt.Sprintf("Failed to read request body: 
%v", readErr), http.StatusBadRequest)
                        return
                }
 
+               if len(content) > maxReloadBodyBytes {
+                       logger.Warnf("Reload request body from %s exceeded %d 
bytes", r.RemoteAddr, maxReloadBodyBytes)
+                       http.Error(w, "Request body too large", 
http.StatusRequestEntityTooLarge)
+                       return
+               }

Review Comment:
   Addressed in a3381743 by adding tests for the exact max-size boundary and 
empty-body fallback behavior.



##########
pkg/hotreload/http_handler.go:
##########
@@ -95,14 +98,20 @@ func (h *ReloadHandler) ServeHTTP(w http.ResponseWriter, r 
*http.Request) {
        // Try to read from body first (handles chunked encoding where 
ContentLength == -1)
        // If body is empty, fallback to file reload
        if r.Body != nil {
-               content, readErr := io.ReadAll(r.Body)
+               content, readErr := io.ReadAll(io.LimitReader(r.Body, 
maxReloadBodyBytes+1))

Review Comment:
   Addressed in a3381743 by replacing LimitReader with http.MaxBytesReader and 
handling http.MaxBytesError as 413.



##########
pkg/hotreload/http_handler_test.go:
##########
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package hotreload
+
+import (
+       "net/http"
+       "net/http/httptest"
+       "strings"
+       "testing"
+)
+
+import (
+       "github.com/stretchr/testify/assert"
+)

Review Comment:
   Thanks. This repository enforces imports-formatter in CI rather than plain 
gofmt import grouping. I kept the current grouping because it matches the 
formatter used by the repository checks.



-- 
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