Skip to content

Commit 8569379

Browse files
committed
fix build error
1 parent 8c1f715 commit 8569379

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

internal/handler/handler.go

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,24 @@ import (
1414
log "github.com/sirupsen/logrus"
1515
)
1616

17+
// bufferPool implements httputil.BufferPool interface
18+
type bufferPool struct {
19+
pool sync.Pool
20+
}
21+
22+
func (bp *bufferPool) Get() []byte {
23+
if bp.pool.New == nil {
24+
bp.pool.New = func() interface{} {
25+
return make([]byte, 32*1024) // 32KB buffer
26+
}
27+
}
28+
return bp.pool.Get().([]byte)
29+
}
30+
31+
func (bp *bufferPool) Put(b []byte) {
32+
bp.pool.Put(b)
33+
}
34+
1735
func NewHandler(ctx context.Context, class service.Class, enableFakeKline bool, alwaysShowForwards bool) func(w http.ResponseWriter, r *http.Request) {
1836
handler := &Handler{
1937
srv: service.NewService(ctx, class),
@@ -251,15 +269,9 @@ func (s *Handler) reverseProxy(w http.ResponseWriter, r *http.Request) {
251269
// req.URL.Path is already set from the original request
252270
},
253271
Transport: banTransport,
254-
BufferPool: &sync.Pool{
255-
New: func() interface{} {
256-
return make([]byte, 32*1024) // 32KB buffer
257-
},
258-
},
272+
BufferPool: &bufferPool{},
259273
}
260274

261-
proxy.Transport = banTransport
262-
263275
// Additional safety check before calling ServeHTTP
264276
if proxy.Director == nil {
265277
log.Errorf("Proxy director is nil, cannot serve request")
@@ -269,8 +281,8 @@ func (s *Handler) reverseProxy(w http.ResponseWriter, r *http.Request) {
269281

270282
// Add panic recovery for the proxy ServeHTTP call
271283
defer func() {
272-
if r := recover(); r != nil {
273-
log.Errorf("Panic recovered in reverseProxy.ServeHTTP for %s %s: %v", r.Method, r.URL.Path, r)
284+
if panicVal := recover(); panicVal != nil {
285+
log.Errorf("Panic recovered in reverseProxy.ServeHTTP for %s %s: %v", r.Method, r.URL.Path, panicVal)
274286
// Try to write error response (it may fail if headers already sent)
275287
defer func() { recover() }() // Ignore any panic from writing response
276288
http.Error(w, "Internal server error", http.StatusInternalServerError)

0 commit comments

Comments
 (0)