Kaynağa Gözat

added an option to omit rewrite rules

svcs 1 yıl önce
ebeveyn
işleme
c28f0e5df1
3 değiştirilmiş dosya ile 15 ekleme ve 8 silme
  1. 11 5
      pkg/client.go
  2. 2 2
      pkg/controller.go
  3. 2 1
      pkg/pagemod.go

+ 11 - 5
pkg/client.go

@@ -32,7 +32,6 @@ import (
 	"io"
 	"log"
 	"net/http"
-	"net/textproto"
 	"strings"
 	"sync"
 )
@@ -75,17 +74,24 @@ func (c *Controller) RequestGeneric(method string, host string, path string, hdr
 	if err != nil {
 		return nil, nil, 500, err
 	}
-	altPage := c.pageMod(b)
-	resp.Header.Set(textproto.CanonicalMIMEHeaderKey("content-length"), string(len(altPage)))
+	var data []byte
+
+	_, ok := c.PageMods.Bypass[path]
+	if ok {
+		data = b
+	} else {
+		data = c.pageMod(b)
+
+	}
 
 	if !strings.Contains(path, "?") {
 		if resp.StatusCode == 200 {
 			if method == "GET" {
-				c.CacheResource(path, NewCachedResource(altPage, &resp.Header, resp.StatusCode))
+				c.CacheResource(path, NewCachedResource(data, &resp.Header, resp.StatusCode))
 			}
 		}
 	}
-	return altPage, &resp.Header, resp.StatusCode, nil
+	return data, &resp.Header, resp.StatusCode, nil
 
 }
 

+ 2 - 2
pkg/controller.go

@@ -84,7 +84,7 @@ func NewController(cfg *HttpServerConfig, routeMap *RouteMap) *Controller {
 	jar.SetCookies(domain, sessCookies)
 	cache := cache.New(24*time.Hour, 10*time.Minute)
 
-	return &Controller{Config: cfg, Client: &http.Client{Jar: jar}, //	CheckRedirect: func(req *http.Request, via []*http.Request) error {return http.ErrUseLastResponse}
+	return &Controller{Config: cfg, Client: &http.Client{Jar: jar, CheckRedirect: func(req *http.Request, via []*http.Request) error { return http.ErrUseLastResponse }},
 		SiteUrl: domain, cache: cache, RouteMaps: routeMap, PageMods: pgMod}
 }
 
@@ -114,7 +114,7 @@ func (c *Controller) Get(ctx *gin.Context) {
 		if err != nil {
 			log.Fatal(err)
 		}
-		//		ctx.Data(cacheHit.Rcode, cacheHit.Headers.Get("content-type"), cacheHit.Data)
+		ctx.Data(cacheHit.Rcode, cacheHit.Headers.Get("content-type"), cacheHit.Data)
 		return
 	}
 

+ 2 - 1
pkg/pagemod.go

@@ -39,7 +39,8 @@ type PageMod struct {
 }
 
 type AllPageMods struct {
-	Content []*PageMod `json:"modifications"`
+	Content []*PageMod          `json:"modifications"`
+	Bypass  map[string]struct{} `json:"bypass"`
 }
 
 /*