Skip to content
This repository has been archived by the owner on Apr 5, 2022. It is now read-only.

Commit

Permalink
Используются константы из fasthttp
Browse files Browse the repository at this point in the history
  • Loading branch information
xtrafrancyz committed Dec 1, 2020
1 parent 8b36837 commit ce63886
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,8 @@ func init() {
}

var (
gzip = []byte("gzip")
vkProxyName = []byte("vk-proxy")
serverHeader = []byte("Server")
setCookie = []byte("Set-Cookie")
acceptEncoding = []byte("Accept-Encoding")
contentEncoding = []byte("Content-Encoding")
gzip = []byte("gzip")
vkProxyName = []byte("vk-proxy")
)

type ProxyConfig struct {
Expand Down Expand Up @@ -237,22 +233,22 @@ func (p *Proxy) prepareProxyRequest(ctx *fasthttp.RequestCtx, replaceContext *re
// After req.URI() call it is impossible to modify URI
req.URI().SetScheme("https")
if p.config.GzipUpstream {
req.Header.SetBytesKV(acceptEncoding, gzip)
req.Header.SetBytesV(fasthttp.HeaderAcceptEncoding, gzip)
} else {
req.Header.DelBytes(acceptEncoding)
req.Header.Del(fasthttp.HeaderAcceptEncoding)
}
return true
}

func (p *Proxy) processProxyResponse(ctx *fasthttp.RequestCtx, replaceContext *replacer.ReplaceContext) error {
res := &ctx.Response
res.Header.DelBytes(setCookie)
res.Header.SetBytesKV(serverHeader, vkProxyName)
res.Header.Del(fasthttp.HeaderSetCookie)
res.Header.SetBytesV(fasthttp.HeaderServer, vkProxyName)

var buf *bytebufferpool.ByteBuffer
// Gunzip body if needed
if bytes.Contains(res.Header.PeekBytes(contentEncoding), gzip) {
res.Header.DelBytes(contentEncoding)
if bytes.Contains(res.Header.Peek(fasthttp.HeaderContentEncoding), gzip) {
res.Header.Del(fasthttp.HeaderContentEncoding)
buf = replacer.AcquireBuffer()
_, err := fasthttp.WriteGunzip(buf, res.Body())
if err != nil {
Expand Down

0 comments on commit ce63886

Please sign in to comment.