Skip to content
This repository was archived by the owner on Nov 5, 2024. It is now read-only.

Commit 9774d14

Browse files
committed
[waf]如果状态码是444,则直接关闭连接
1 parent 2839713 commit 9774d14

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

teaproxy/response.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package teaproxy
22

33
import (
4+
"bufio"
45
"bytes"
56
"compress/gzip"
67
"github.com/TeaWeb/code/teaconfigs"
78
"github.com/iwind/TeaGo/logs"
9+
"net"
810
"net/http"
911
)
1012

@@ -225,3 +227,12 @@ func (this *ResponseWriter) Close() {
225227
this.gzipWriter = nil
226228
}
227229
}
230+
231+
// Hijack
232+
func (this *ResponseWriter) Hijack() (conn net.Conn, buf *bufio.ReadWriter, err error) {
233+
hijack, ok := this.writer.(http.Hijacker)
234+
if ok {
235+
return hijack.Hijack()
236+
}
237+
return
238+
}

teawaf/action_block.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@ type BlockAction struct {
2727

2828
func (this *BlockAction) Perform(waf *WAF, request *requests.Request, writer http.ResponseWriter) (allow bool) {
2929
if writer != nil {
30+
// if status code eq 444, we close the connection
31+
if this.StatusCode == 444 {
32+
hijack, ok := writer.(http.Hijacker)
33+
if ok {
34+
conn, _, _ := hijack.Hijack()
35+
if conn != nil {
36+
_ = conn.Close()
37+
return
38+
}
39+
}
40+
}
41+
42+
// output response
3043
if this.StatusCode > 0 {
3144
writer.WriteHeader(this.StatusCode)
3245
} else {

0 commit comments

Comments
 (0)