Skip to content

Commit

Permalink
add code
Browse files Browse the repository at this point in the history
  • Loading branch information
allnash committed Nov 20, 2024
1 parent 5fa79f1 commit e71f793
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion fast-server/handlers/proxy_handler.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package handlers

import (
"bytes"
"crypto/tls"
"fast/config"
"fmt"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"io"
"math"
"net/http"
"net/url"
Expand Down Expand Up @@ -191,10 +193,26 @@ func HandleProxy(c echo.Context, domain config.Domain) error {
Rewrite: rewriteMap,
Transport: transport,
ModifyResponse: func(res *http.Response) error {
c.Logger().Infof("[LoadBalancer] Response from %s: %d %s",
// Read and log the response body
body, err := io.ReadAll(res.Body)
if err != nil {
c.Logger().Errorf("[LoadBalancer] Failed to read response body: %v", err)
return err
}
err = res.Body.Close()
if err != nil {
c.Logger().Errorf("[LoadBalancer] Failed to read response body: %v", err)
return err
}
// Create new ReadCloser for the body
res.Body = io.NopCloser(bytes.NewBuffer(body))

c.Logger().Infof("[LoadBalancer] Response from %s: %d %s, Content-Type: %s, Body: %s",
selectedHost,
res.StatusCode,
http.StatusText(res.StatusCode),
res.Header.Get("Content-Type"),
string(body),
)
return nil
},
Expand Down

0 comments on commit e71f793

Please sign in to comment.