Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
sergei-bronnikov committed Feb 20, 2025
1 parent d29bbd1 commit 7a1032e
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions internal/server/web/proxy/x_custom.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package proxy

import (
"context"
"errors"
"fmt"
"github.com/bricks-cloud/bricksllm/internal/provider"
Expand All @@ -25,8 +24,8 @@ func getXCustomHandler(prod bool) gin.HandlerFunc {
return
}

ctx, cancel := context.WithTimeout(context.Background(), c.GetDuration("requestTimeout"))
defer cancel()
//ctx, cancel := context.WithTimeout(context.Background(), c.GetDuration("requestTimeout"))
//defer cancel()

providerId := c.Param(xcustom.XProviderIdParam)
rawProviderSettings, exists := c.Get("settings")
Expand Down Expand Up @@ -70,23 +69,29 @@ func getXCustomHandler(prod bool) gin.HandlerFunc {
fmt.Println(c.Request.Header)
fmt.Println("=======dumpA===========")
fmt.Println(string(dumpA))
//proxy := &httputil.ReverseProxy{
// Director: func(r *http.Request) {
// r.URL.Scheme = target.Scheme
// r.URL.Host = target.Host
// r.URL.Path, r.URL.RawPath = target.Path, target.RawPath
// r.RequestURI = target.RequestURI()
// r.Host = target.Host
// r = r.WithContext(ctx)
//
// r.Header.Del("X-Amzn-Trace-Id")
// r.Header.Del("X-Forwarded-For")
// r.Header.Del("X-Forwarded-Port")
// r.Header.Del("X-Forwarded-Proto")
//
// dumpB, _ := httputil.DumpRequest(r, true)
// fmt.Println("=======dumpB===========")
// fmt.Println(string(dumpB))
// },
//}
proxy := &httputil.ReverseProxy{
Director: func(r *http.Request) {
r.URL.Scheme = target.Scheme
r.URL.Host = target.Host
r.URL.Path, r.URL.RawPath = target.Path, target.RawPath
r.RequestURI = target.RequestURI()
r.Host = target.Host
r = r.WithContext(ctx)

r.Header.Del("X-Amzn-Trace-Id")
r.Header.Del("X-Forwarded-For")
r.Header.Del("X-Forwarded-Port")
r.Header.Del("X-Forwarded-Proto")

dumpB, _ := httputil.DumpRequest(r, true)
fmt.Println("=======dumpB===========")
fmt.Println(string(dumpB))
Rewrite: func(r *httputil.ProxyRequest) {
r.SetURL(target)
r.Out.URL.Path, r.Out.URL.RawPath = target.Path, target.RawPath
},
}
proxy.ServeHTTP(c.Writer, c.Request)
Expand Down

0 comments on commit 7a1032e

Please sign in to comment.