Skip to content

Commit c25d983

Browse files
author
Vinh Duong
committed
update 🎉
1 parent a179cdc commit c25d983

File tree

2 files changed

+36
-33
lines changed

2 files changed

+36
-33
lines changed

build.sh

+9
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
#!/usr/bin/env sh
22
# go get github.com/josephspurrier/goversioninfo/cmd/goversioninfo
3+
echo 'Building linux i386..'
34
rm -f resource.syso
45
GOOS=linux GOARCH=386 go build
56
zip go-fasthttp-sniproxy-chunks-linux-386.zip domains.txt domains-regex.txt go-fasthttp-sniproxy-chunks
67

8+
echo 'Building linux arm 32bit..'
9+
rm -f resource.syso
10+
GOOS=linux GOARCH=arm go build
11+
zip go-fasthttp-sniproxy-chunks-linux-arm.zip domains.txt domains-regex.txt go-fasthttp-sniproxy-chunks
12+
13+
echo 'Building linux amd64..'
714
rm -f resource.syso
815
GOOS=linux GOARCH=amd64 go build
916
zip go-fasthttp-sniproxy-chunks-linux-amd64.zip domains.txt domains-regex.txt go-fasthttp-sniproxy-chunks
1017

18+
echo 'Building windows i386..'
1119
rm -f resource.syso
1220
goversioninfo -icon=icon.ico
1321
GOOS=windows GOARCH=386 go build
1422
zip go-fasthttp-sniproxy-chunks-win32.zip domains.txt domains-regex.txt go-fasthttp-sniproxy-chunks.exe
1523

24+
echo 'Building windows amd64..'
1625
rm -f resource.syso
1726
goversioninfo -icon=icon.ico
1827
GOOS=windows GOARCH=amd64 go build

main.go

+27-33
Original file line numberDiff line numberDiff line change
@@ -105,42 +105,36 @@ func requestHandler(ctx *fasthttp.RequestCtx) {
105105

106106
// log.Println(string(ctx.Path()), string(ctx.Host()), ctx.String(), "\r\n\r\n", ctx.Request.String())
107107

108-
host := string(ctx.Host())
109-
if len(host) < 1 {
110-
ctx.SetStatusCode(fasthttp.StatusBadRequest)
111-
log.Println("Reject: Empty host")
112-
return
113-
}
114-
115-
hostname, port, err := net.SplitHostPort(host)
116-
if err != nil {
117-
if err1, ok := err.(*net.AddrError); ok && strings.Index(err1.Err, "missing port") != -1 {
118-
hostname, port, err = net.SplitHostPort(host + ":80")
119-
}
108+
// https connecttion
109+
if bytes.Equal(ctx.Method(), []byte("CONNECT")) {
110+
host := string(ctx.RequestURI())
111+
hostname, port, err := net.SplitHostPort(host)
120112
if err != nil {
121-
ctx.SetStatusCode(fasthttp.StatusBadRequest)
122-
log.Println("Reject: Invalid host", host, err)
123-
return
113+
if err1, ok := err.(*net.AddrError); ok && strings.Index(err1.Err, "missing port") != -1 {
114+
hostname, port, err = net.SplitHostPort(host + ":80")
115+
}
116+
if err != nil {
117+
ctx.SetStatusCode(fasthttp.StatusBadRequest)
118+
log.Println("Reject: Invalid host", host, err)
119+
return
120+
}
124121
}
125-
}
126122

127-
cacheAddrMapLock.RLock()
128-
tcpAddr, ok := cacheTCPAddrMap[host]
129-
cacheAddrMapLock.RUnlock()
130-
if ok == false {
131-
tcpAddr, err = getUsableIP(hostname, port)
132-
if err != nil {
133-
ctx.SetStatusCode(fasthttp.StatusInternalServerError)
134-
log.Println("No usable IP:", host, err)
135-
return
123+
cacheAddrMapLock.RLock()
124+
tcpAddr, ok := cacheTCPAddrMap[host]
125+
cacheAddrMapLock.RUnlock()
126+
if ok == false {
127+
tcpAddr, err = getUsableIP(hostname, port)
128+
if err != nil {
129+
ctx.SetStatusCode(fasthttp.StatusInternalServerError)
130+
log.Println("No usable IP:", host, err)
131+
return
132+
}
133+
cacheAddrMapLock.Lock()
134+
cacheTCPAddrMap[host] = tcpAddr
135+
cacheAddrMapLock.Unlock()
136136
}
137-
cacheAddrMapLock.Lock()
138-
cacheTCPAddrMap[host] = tcpAddr
139-
cacheAddrMapLock.Unlock()
140-
}
141137

142-
// https connecttion
143-
if bytes.Equal(ctx.Method(), []byte("CONNECT")) {
144138
err = httpsHandler(ctx, hostname, tcpAddr)
145139
if err != nil {
146140
ctx.SetStatusCode(fasthttp.StatusInternalServerError)
@@ -149,10 +143,10 @@ func requestHandler(ctx *fasthttp.RequestCtx) {
149143
return
150144
}
151145

152-
err = httpClient.DoTimeout(&ctx.Request, &ctx.Response, httpClientTimeout)
146+
err := httpClient.DoTimeout(&ctx.Request, &ctx.Response, httpClientTimeout)
153147
if err != nil {
154148
ctx.SetStatusCode(fasthttp.StatusInternalServerError)
155-
log.Println("httpHandler:", host, err)
149+
log.Println("httpHandler:", string(ctx.Host()), err)
156150
}
157151
}
158152

0 commit comments

Comments
 (0)