init auth

This commit is contained in:
DeniskaRediska committed 2019-10-23 14:17:28 +03:00
1 parent 3a4931ca8c
commit b6baa9e5e7
11 files changed
+224 -82

No files matched your search

+2 -44
View File
@@ -33,58 +33,16 @@ func (p *httpProxy) ProxyRequest(ctx *fasthttp.RequestCtx) {
req := &ctx.Request
res := &ctx.Response
if clientIP, _, err := net.SplitHostPort(ctx.RemoteAddr().String()); err == nil {
req.Header.Add("X-Forwarded-For", clientIP)
}
resHeaders := make(map[string]string)
res.Header.VisitAll(func(k, v []byte) {
key := string(k)
value := string(v)
if val, ok := resHeaders[key]; ok {
resHeaders[key] = val + "," + value
}
resHeaders[key] = value
})
for _, h := range hopHeaders {
// if h == "Te" && hv == "trailers" {
// continue
// }
req.Header.Del(h)
if addr, _, err := net.SplitHostPort(ctx.RemoteAddr().String()); err == nil {
req.Header.Add("X-Forwarded-For", addr)
}
if err := p.client.Do(req, res); err != nil {
log.Error(log_code.ErrorClientHttp, err)
return
}
for _, h := range hopHeaders {
res.Header.Del(h)
}
for k, v := range resHeaders {
res.Header.Set(k, v)
}
}
func (p *httpProxy) Close() {
p.client = nil
p = nil
}
// Hop-by-hop headers. These are removed when sent to the backend.
// As of RFC 7230, hop-by-hop headers are required to appear in the
// Connection header field. These are the headers defined by the
// obsoleted RFC 2616 (section 13.5.1) and are used for backward
// compatibility.
var hopHeaders = []string{
"Connection",
"Proxy-Connection", // non-standard but still sent by libcurl and rejected by e.g. google
"Keep-Alive",
"Proxy-Authenticate",
"Proxy-Authorization",
"Te", // canonicalized version of "TE"
"Trailer", // not Trailers per URL above; https://www.rfc-editor.org/errata_search.php?eid=4522
"Transfer-Encoding",
"Upgrade",
}