diff --git a/.gitignore b/.gitignore index 22d0862..c446014 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ WebServer/cert/* WebServer/tools/logs/* WebServer/soft/* !WebServer/soft/soft.rar +Backend/admin/frontend/wailsjs* .cursorrules \ No newline at end of file diff --git a/Backend/WebServer/proxy_server.go b/Backend/WebServer/proxy_server.go index 9976ae3..dbe11c8 100644 --- a/Backend/WebServer/proxy_server.go +++ b/Backend/WebServer/proxy_server.go @@ -1,6 +1,7 @@ package webserver import ( + "bytes" "crypto/tls" "io" "log" @@ -71,9 +72,19 @@ func StartHandlerProxy(w http.ResponseWriter, r *http.Request) (valid bool) { protocol = "https" } + // Читаем тело запроса в буфер для корректной передачи POST данных + var bodyBuffer bytes.Buffer + if r.Body != nil { + if _, err := io.Copy(&bodyBuffer, r.Body); err != nil { + http.Error(w, "Ошибка чтения тела запроса", http.StatusInternalServerError) + return valid + } + r.Body.Close() + } + // Проксирование на локальный адрес proxyURL := protocol + "://" + proxyConfig.LocalAddress + ":" + proxyConfig.LocalPort + r.URL.RequestURI() - proxyReq, err := http.NewRequest(r.Method, proxyURL, r.Body) + proxyReq, err := http.NewRequest(r.Method, proxyURL, &bodyBuffer) if err != nil { http.Error(w, "Ошибка создания прокси-запроса", http.StatusInternalServerError) return valid @@ -95,8 +106,19 @@ func StartHandlerProxy(w http.ResponseWriter, r *http.Request) (valid bool) { } } - // Прозрачная передача - никаких дополнительных заголовков - // Все заголовки уже скопированы выше "как есть" + // Добавляем заголовки для передачи реального IP клиента + clientIP := r.RemoteAddr + if colonIndex := strings.LastIndex(clientIP, ":"); colonIndex != -1 { + clientIP = clientIP[:colonIndex] + } + proxyReq.Header.Set("X-Real-IP", clientIP) + proxyReq.Header.Set("X-Forwarded-For", clientIP) + proxyReq.Header.Set("X-Forwarded-Proto", protocol) + + // Устанавливаем правильный Content-Length для POST/PUT запросов + if bodyBuffer.Len() > 0 { + proxyReq.ContentLength = int64(bodyBuffer.Len()) + } // Выполняем прокси-запрос client := &http.Client{