Skip to content

Commit

Permalink
http optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
yisier committed Jan 5, 2024
1 parent 19a1e31 commit c44a5da
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions server/proxy/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,27 @@ reset:
if isReset {
host.Client.AddConn()
}

remoteAddr = strings.TrimSpace(r.Header.Get("X-Forwarded-For"))
if len(remoteAddr) == 0 {
remoteAddr = c.RemoteAddr().String()
}

// 判断访问地址是否在全局黑名单内
if IsGlobalBlackIp(c.RemoteAddr().String()) {
c.Close()
return
}

if host, err = file.GetDb().GetInfoByHost(r.Host, r); err != nil {
logs.Notice("the url %s %s %s can't be parsed!", r.URL.Scheme, r.Host, r.RequestURI)
logs.Notice("the url %s %s %s can't be parsed!, host %s, url %s, remote address %s", r.URL.Scheme, r.Host, r.RequestURI, r.Host, r.URL.Path, remoteAddr)
c.Close()
return
}

if err := s.CheckFlowAndConnNum(host.Client); err != nil {
logs.Warn("client id %d, host id %d, error %s, when https connection", host.Client.Id, host.Id, err.Error())
c.Close()
return
}
if !isReset {
Expand All @@ -167,12 +182,6 @@ reset:
return
}

// 判断访问地址是否在全局黑名单内
if IsGlobalBlackIp(c.RemoteAddr().String()) {
c.Close()
return
}

// 判断访问地址是否在黑名单内
if common.IsBlackIp(c.RemoteAddr().String(), host.Client.VerifyKey, host.Client.BlackIpList) {
c.Close()
Expand Down Expand Up @@ -239,10 +248,6 @@ reset:
//change the host and header and set proxy setting
common.ChangeHostAndHeader(r, host.HostChange, host.HeaderChange, c.Conn.RemoteAddr().String(), s.addOrigin)

remoteAddr = strings.TrimSpace(r.Header.Get("X-Forwarded-For"))
if len(remoteAddr) == 0 {
remoteAddr = c.RemoteAddr().String()
}
logs.Info("%s request, method %s, host %s, url %s, remote address %s, target %s", r.URL.Scheme, r.Method, r.Host, r.URL.Path, remoteAddr, lk.Host)

//write
Expand Down

0 comments on commit c44a5da

Please sign in to comment.