add mode debug for request

This commit is contained in:
Дмитрий Саенко 2025-10-23 21:48:15 +03:00
parent 5e98521fbb
commit 030adb5268

View file

@ -1,8 +1,10 @@
package controller package controller
import ( import (
"bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io"
"strconv" "strconv"
"github.com/mhsanaei/3x-ui/v2/database/model" "github.com/mhsanaei/3x-ui/v2/database/model"
@ -103,15 +105,21 @@ func (a *InboundController) getClientTrafficsById(c *gin.Context) {
// addInbound creates a new inbound configuration. // addInbound creates a new inbound configuration.
func (a *InboundController) addInbound(c *gin.Context) { func (a *InboundController) addInbound(c *gin.Context) {
body := c.Request.PostForm.Encode() // Заголовки
defer func() { logger.Debug("=== REQUEST INFO ===")
err := c.Request.Body.Close() logger.Debug(fmt.Sprintf("%s %s", c.Request.Method, c.Request.URL.String()))
if err != nil { logger.Debug("Headers:")
logger.Errorf("error closing request body: %v", err) for k, v := range c.Request.Header {
logger.Debug(fmt.Sprintf(" %s: %v", k, v))
} }
}()
logger.Debugf("debug request body: %v", body) // Тело (прочитаем и восстановим)
bodyBytes, _ := io.ReadAll(c.Request.Body)
logger.Debug(fmt.Sprintf("\nBody:\n%s\n", string(bodyBytes)))
logger.Debug("====================")
// Обязательно восстановить тело, чтобы Gin потом смог его обработать
c.Request.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))
inbound := &model.Inbound{} inbound := &model.Inbound{}
err := c.ShouldBind(inbound) err := c.ShouldBind(inbound)