|
@@ -49,16 +49,13 @@ var NonmutableHeaders = map[string]struct{}{
|
|
"Host": struct{}{},
|
|
"Host": struct{}{},
|
|
}
|
|
}
|
|
|
|
|
|
-type TokenUpdate struct {
|
|
|
|
- Code string `form:"code"`
|
|
|
|
- Content string `form:"content"`
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
type Controller struct {
|
|
type Controller struct {
|
|
- Config HttpServerConfig
|
|
|
|
- RouteMaps *RouteMap
|
|
|
|
- Client *http.Client
|
|
|
|
- cache *cache.Cache
|
|
|
|
|
|
+ Config HttpServerConfig
|
|
|
|
+ ProxyAddr string
|
|
|
|
+ TargetAddr string
|
|
|
|
+ RouteMaps *RouteMap
|
|
|
|
+ Client *http.Client
|
|
|
|
+ cache *cache.Cache
|
|
}
|
|
}
|
|
|
|
|
|
type ProxyCookies struct {
|
|
type ProxyCookies struct {
|
|
@@ -118,22 +115,19 @@ func (c *Controller) HandleAny(ctx *gin.Context) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- //dname, ok := c.RouteMaps.GetMappedDomain(incomingPath)
|
|
|
|
- //if ok { // below, RequestURI() returns the whole URI with the query
|
|
|
|
- resp := c.RequestGeneric(ctx.Request.Method, c.Config.ProxyDomain, ctx.Request.URL.RequestURI(), &ctx.Request.Header, ctx.Request.Body)
|
|
|
|
|
|
+ resp := c.RequestGeneric(ctx.Request.Method, c.Config.TargetDomain, ctx.Request.URL.RequestURI(), &ctx.Request.Header, ctx.Request.Body)
|
|
if resp.Error != nil {
|
|
if resp.Error != nil {
|
|
log.Fatal(resp.Error, " failed to route the request: ", incomingPath, " to the target domain: ", ctx.Request.Host, " Error: ", resp.Error)
|
|
log.Fatal(resp.Error, " failed to route the request: ", incomingPath, " to the target domain: ", ctx.Request.Host, " Error: ", resp.Error)
|
|
}
|
|
}
|
|
for k, v := range resp.Headers {
|
|
for k, v := range resp.Headers {
|
|
_, ok := NonmutableHeaders[k]
|
|
_, ok := NonmutableHeaders[k]
|
|
if !ok {
|
|
if !ok {
|
|
|
|
+ // ctx.Header(k, strings.ReplaceAll(v[0], c.Config.TargetDomain, c.Config.ProxyDomain))
|
|
ctx.Header(k, v[0])
|
|
ctx.Header(k, v[0])
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- ctx.Header("access-control-allow-origin", c.Config.ServerDomain)
|
|
|
|
|
|
+ ctx.Header("access-control-allow-origin", c.Config.ProxyDomain)
|
|
ctx.Data(resp.StatusCode, resp.Headers.Get("content-type"), resp.Data)
|
|
ctx.Data(resp.StatusCode, resp.Headers.Get("content-type"), resp.Data)
|
|
return
|
|
return
|
|
- //}
|
|
|
|
|
|
|
|
- //c.TryHosts(ctx.Request.Method, ctx.Request.URL.RequestURI(), &ctx.Request.Header, ctx.Request.Body, c.Config.KnownHosts)
|
|
|
|
}
|
|
}
|