MCPcopy Index your code
hub / github.com/GoEdgeLab/EdgeNode / doRequestLimit

Method doRequestLimit

internal/nodes/http_request_limit.go:10–41  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

8)
9
10func (this *HTTPRequest) doRequestLimit() (shouldStop bool) {
11 // 是否在全局名单中
12 _, isInAllowedList, _ := iplibrary.AllowIP(this.RemoteAddr(), this.ReqServer.Id)
13 if isInAllowedList {
14 return false
15 }
16
17 // 检查请求Body尺寸
18 // TODO 处理分片提交的内容
19 if this.web.RequestLimit.MaxBodyBytes() > 0 &&
20 this.RawReq.ContentLength > this.web.RequestLimit.MaxBodyBytes() {
21 this.writeCode(http.StatusRequestEntityTooLarge, "", "")
22 return true
23 }
24
25 // 设置连接相关参数
26 if this.web.RequestLimit.MaxConns > 0 || this.web.RequestLimit.MaxConnsPerIP > 0 {
27 var requestConn = this.RawReq.Context().Value(HTTPConnContextKey)
28 if requestConn != nil {
29 clientConn, ok := requestConn.(ClientConnInterface)
30 if ok && !clientConn.IsBound() {
31 if !clientConn.Bind(this.ReqServer.Id, this.requestRemoteAddr(true), this.web.RequestLimit.MaxConns, this.web.RequestLimit.MaxConnsPerIP) {
32 this.writeCode(http.StatusTooManyRequests, "", "")
33 this.Close()
34 return true
35 }
36 }
37 }
38 }
39
40 return false
41}

Callers 1

doBeginMethod · 0.95

Calls 8

RemoteAddrMethod · 0.95
writeCodeMethod · 0.95
requestRemoteAddrMethod · 0.95
CloseMethod · 0.95
AllowIPFunction · 0.92
ContextMethod · 0.80
IsBoundMethod · 0.65
BindMethod · 0.65

Tested by

no test coverage detected