Skip to content

Commit

Permalink
Cleanup & bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
coyove committed Sep 4, 2017
1 parent 390847d commit 0fcae35
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 7 deletions.
3 changes: 1 addition & 2 deletions proxy/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@ func (proxy *ProxyHttpServer) CanDirectConnect(host string) bool {
// lookup at upstream
client := http.Client{Timeout: time.Second}
req, _ := http.NewRequest("GET", "http://"+proxy.Upstream, nil)
req.Header.Add(dnsHeader, host)
req.Header.Add(dnsHeaderID, AEncryptString(*G_Key))
req.Header.Add(dnsHeader, EncryptHost(host, "!"))
resp, err := client.Do(req)

if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions proxy/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ type ProxyUpstreamHttpServer struct {
}

func (proxy *ProxyUpstreamHttpServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.Method == "GET" && r.Header.Get(dnsHeader) != "" {
if ADecryptString(r.Header.Get(dnsHeaderID)) == *G_Key {
w.Write([]byte(lookup.LookupIP(r.Header.Get(dnsHeader))))
if dh := r.Header.Get(dnsHeader); r.Method == "GET" && dh != "" {
if x := DecryptHost(dh, "!"); x != "" {
w.Write([]byte(lookup.LookupIP(x)))
return
}
}
Expand Down
2 changes: 1 addition & 1 deletion proxy/shocoex.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func DecryptHost(text, mark string) string {
buf := Base35Decode(parts[i])

parts[i] = shoco.Decompress(ADecrypt(buf))
if parts[i][0] != mark[0] {
if len(parts[i]) == 0 || parts[i][0] != mark[0] {
return ""
}

Expand Down
1 change: 0 additions & 1 deletion proxy/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ var (

rkeyHeader = "X-Request-ID"
rkeyHeader2 = "X-Request-HTTP-ID"
dnsHeaderID = "X-Host-Lookup-ID"
dnsHeader = "X-Host-Lookup"

hostHeadExtract = regexp.MustCompile(`(\S+)\.com`)
Expand Down

0 comments on commit 0fcae35

Please sign in to comment.