MCPcopy Create free account
hub / github.com/axetroy/forward-cli / NewProxyServer

Function NewProxyServer

proxy.go:53–79  ·  view source on GitHub ↗
(options *ProxyServerOptions)

Source from the content-addressed store, hash-verified

51}
52
53func NewProxyServer(options *ProxyServerOptions) *ProxyServer {
54 proxy := httputil.NewSingleHostReverseProxy(options.Target)
55
56 server := &ProxyServer{
57 options,
58 proxy,
59 }
60
61 originalDirector := proxy.Director
62 proxy.Director = func(req *http.Request) {
63 originalDirector(req)
64 server.modifyRequest(req)
65 }
66
67 proxy.ModifyResponse = server.modifyResponse
68 proxy.ErrorHandler = func(rw http.ResponseWriter, r *http.Request, err error) {
69 if errors.Is(err, context.Canceled) {
70 return
71 }
72 msg := fmt.Sprintf("%+v\n", err)
73 log.Println(msg)
74 rw.WriteHeader(http.StatusInternalServerError)
75 _, _ = rw.Write([]byte(msg))
76 }
77
78 return server
79}
80
81func (p *ProxyServer) Handler() func(http.ResponseWriter, *http.Request) {
82 return func(w http.ResponseWriter, r *http.Request) {

Callers

nothing calls this directly

Calls 1

modifyRequestMethod · 0.95

Tested by

no test coverage detected