Skip to content

Commit e55b309

Browse files
committed
feat: add an option to bypass our encoding
1 parent ac581f2 commit e55b309

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

http/http.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,13 @@ func (w *NgResponseWriter) Header() http.Header {
223223
return w.stdrw.Header()
224224
}
225225

226+
func (w *NgResponseWriter) BypassEncoding() {
227+
if w.acceptEncoding != "" {
228+
w.Header().Set("Accept-Encoding", w.acceptEncoding)
229+
w.acceptEncoding = ""
230+
}
231+
}
232+
226233
func (w *NgResponseWriter) initForWrite() {
227234
w.Header().Set("Server", utils.ServerSign)
228235
switch w.code {

http/proxy.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type HttpHost struct {
2424
Backend *net.URL
2525
InsecureSkipVerify bool
2626
MaxConnsPerHost int
27+
BypassEncoding bool
2728
Underlying net.Interface
2829

2930
proxy *httputil.ReverseProxy
@@ -171,6 +172,10 @@ func (h *ReverseProxy) HandleHTTP(ctx *HttpCtx) Ret {
171172
recover()
172173
}()
173174

175+
if host.BypassEncoding {
176+
ctx.Resp.BypassEncoding()
177+
}
178+
174179
if ctx.Req.Header.Get("Upgrade") == "websocket" {
175180
host.wsproxy.ServeHTTP(ctx.Resp, ctx.Req)
176181
} else {
@@ -187,14 +192,15 @@ func (hpx *ReverseProxy) GetHosts() []*HttpHost {
187192
return hpx.hosts
188193
}
189194

190-
func (hpx *ReverseProxy) Insert(index int, id string, hosts []string, backend *net.URL, MaxConnsPerHost int, InsecureSkipVerify bool) error {
195+
func (hpx *ReverseProxy) Insert(index int, id string, hosts []string, backend *net.URL, MaxConnsPerHost int, InsecureSkipVerify bool, BypassEncoding bool) error {
191196
buf := HttpHost{
192197
Id: id,
193198
ServerName: utils.MustCompileRegexp(dns.Dnsnames2Regexps(hosts)),
194199
Backend: backend,
195200
MaxConnsPerHost: MaxConnsPerHost,
196201
InsecureSkipVerify: InsecureSkipVerify,
197202
Underlying: backend.Underlying,
203+
BypassEncoding: BypassEncoding,
198204
}
199205
buf.Init()
200206

ui/builtin.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ var _builtin_refs_assertions = map[string]Assert{
148148
Default: false,
149149
Desc: "skip TLS certificate verification for backend",
150150
},
151+
"BypassEncoding": {
152+
Type: "bool",
153+
Default: false,
154+
Desc: "bypass encoding for backend",
155+
},
151156
},
152157
},
153158
},
@@ -1003,15 +1008,17 @@ var _builtin_refs = map[string]Inst{
10031008
backend := host.MustGet("backend").ToURL()
10041009
maxconns := host.MustGet("MaxConnsPerHost").ToInt()
10051010
tlsskip := host.MustGet("TlsSkipVerify").ToBool()
1011+
bypassencoding := host.MustGet("BypassEncoding").ToBool()
10061012

1007-
proxier.Insert(id, name, hosts, backend, maxconns, tlsskip)
1013+
proxier.Insert(id, name, hosts, backend, maxconns, tlsskip, bypassencoding)
10081014

10091015
zlog.Debug().
10101016
Str("name", name).
10111017
Strs("hosts", hosts).
10121018
Str("backend", backend.String()).
10131019
Int("maxconns", maxconns).
10141020
Bool("tlsskip", tlsskip).
1021+
Bool("bypassencoding", bypassencoding).
10151022
Msg("new http reverse host")
10161023
}
10171024

0 commit comments

Comments
 (0)