File tree 2 files changed +11
-6
lines changed
2 files changed +11
-6
lines changed Original file line number Diff line number Diff line change
1
+ all :
2
+ GOOS=linux GOARCH=amd64 go build
Original file line number Diff line number Diff line change @@ -41,13 +41,16 @@ var specailIPs []string
41
41
var allowedIPs []string
42
42
43
43
func updateSpecailIPs (reader * bufio.Reader , conn net.Conn ) bool {
44
- // 使用 io.TeeReader 复制原始数据到另一个 io.Writer
45
- // buf 中保存了一份原始数据的拷贝,你可以根据需求使用它
46
- var buf strings.Builder
47
- teeReader := io .TeeReader (reader , & buf )
44
+ peekData , err := reader .Peek (3 )
45
+ if err != nil {
46
+ return false
47
+ }
48
+ if ! strings .HasPrefix (string (peekData ), "GET" ) {
49
+ return false
50
+ }
48
51
49
52
// 使用 http.Request 对象解析连接的请求
50
- request , err := http .ReadRequest (bufio . NewReader ( teeReader ) )
53
+ request , err := http .ReadRequest (reader )
51
54
if err != nil {
52
55
fmt .Println ("Error reading request:" , err )
53
56
return false
@@ -151,7 +154,7 @@ func needAuth(conn net.Conn) bool {
151
154
152
155
// 如果客户端 IP 不在白名单中,需要认证
153
156
if ! allowed {
154
- log .Println ("Connection from" , clientIP , "is not allowed" )
157
+ // log.Println("Connection from", clientIP, "is not allowed")
155
158
return true
156
159
}
157
160
You can’t perform that action at this time.
0 commit comments