Skip to content

Commit e7c4d96

Browse files
author
bloom
committed
fix challenge
1 parent aa585e5 commit e7c4d96

File tree

1 file changed

+51
-51
lines changed

1 file changed

+51
-51
lines changed

pingoo-go/middleware.go

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"net/http"
1010
"net/netip"
1111
"strconv"
12-
"strings"
1312
"time"
1413
"unicode/utf8"
1514

@@ -59,8 +58,8 @@ func (client *Client) Middleware(config *MiddlewareConfig) func(next http.Handle
5958
}
6059
}
6160

62-
userAgent := strings.TrimSpace(req.UserAgent())
63-
var err error
61+
// userAgent := strings.TrimSpace(req.UserAgent())
62+
// var err error
6463
path := req.URL.Path
6564
ctx := req.Context()
6665
logger := client.getLogger(ctx)
@@ -92,57 +91,58 @@ func (client *Client) Middleware(config *MiddlewareConfig) func(next http.Handle
9291
ctx = context.WithValue(ctx, CtxKeyGeoip, geoipInfo)
9392
req = req.WithContext(ctx)
9493

95-
if strings.HasPrefix(path, "/__pingoo/") {
96-
client.handleHttpRequest(ctx, clientIp, res, req)
97-
return
98-
}
99-
100-
analyzeRequestInput := analyzeRequestInput{
101-
HttpMethod: req.Method,
102-
Hostname: req.Host,
103-
UserAgent: userAgent,
104-
Ip: clientIp.String(),
105-
Asn: geoipInfo.ASN,
106-
Country: geoipInfo.Country,
107-
Path: req.URL.Path,
108-
HttpVersionMajor: int64(req.ProtoMajor),
109-
HttpVersionMinor: int64(req.ProtoMinor),
110-
Headers: convertHttpheaders(req.Header),
111-
}
112-
analyzeRequestOutput, err := client.analyzeRequest(ctx, analyzeRequestInput)
113-
if err != nil {
114-
// fail open
115-
logger.Error(err.Error(),
116-
slog.String("user_agent", userAgent),
117-
slog.String("ip_address", clientIp.String()),
118-
slog.Int64("asn", geoipInfo.ASN),
119-
)
120-
nextMiddleware.ServeHTTP(res, req)
121-
return
122-
}
123-
124-
switch analyzeRequestOutput.Outcome {
125-
case AnalyzeRequestOutcomeAllowed, AnalyzeRequestOutcomeVerifiedBot:
126-
break
127-
case AnalyzeRequestOutcomeChallenge:
128-
break
129-
// req.URL.Path = "/__pingoo/challenge"
94+
// if strings.HasPrefix(path, "/__pingoo/") {
13095
// client.handleHttpRequest(ctx, clientIp, res, req)
13196
// return
132-
case AnalyzeRequestOutcomeBlocked:
133-
client.serveBlockedResponse(res)
134-
return
97+
// }
98+
99+
// analyzeRequestInput := analyzeRequestInput{
100+
// HttpMethod: req.Method,
101+
// Hostname: req.Host,
102+
// UserAgent: userAgent,
103+
// Ip: clientIp.String(),
104+
// Asn: geoipInfo.ASN,
105+
// Country: geoipInfo.Country,
106+
// Path: req.URL.Path,
107+
// HttpVersionMajor: int64(req.ProtoMajor),
108+
// HttpVersionMinor: int64(req.ProtoMinor),
109+
// Headers: convertHttpheaders(req.Header),
110+
// }
111+
// analyzeRequestOutput, err := client.analyzeRequest(ctx, analyzeRequestInput)
112+
// if err != nil {
113+
// // fail open
114+
// logger.Error(err.Error(),
115+
// slog.String("user_agent", userAgent),
116+
// slog.String("ip_address", clientIp.String()),
117+
// slog.Int64("asn", geoipInfo.ASN),
118+
// )
119+
// nextMiddleware.ServeHTTP(res, req)
120+
// return
121+
// }
122+
123+
// switch analyzeRequestOutput.Outcome {
124+
// case AnalyzeRequestOutcomeAllowed, AnalyzeRequestOutcomeVerifiedBot:
125+
// break
126+
// case AnalyzeRequestOutcomeChallenge:
127+
// break
128+
// // it's causing too much troubles
129+
// // req.URL.Path = "/__pingoo/challenge"
130+
// // client.handleHttpRequest(ctx, clientIp, res, req)
131+
// // return
132+
// case AnalyzeRequestOutcomeBlocked:
133+
// client.serveBlockedResponse(res)
134+
// return
135135

136-
default:
137-
// fail open
138-
logger.Error("pingoo.Middleware: unknown outcome",
139-
slog.String("outcome", string(analyzeRequestOutput.Outcome)),
140-
slog.String("ip", clientIp.String()),
141-
slog.String("user_agent", userAgent),
142-
slog.String("path", path),
143-
slog.Int64("asn", geoipInfo.ASN),
144-
)
145-
}
136+
// default:
137+
// // fail open
138+
// logger.Error("pingoo.Middleware: unknown outcome",
139+
// slog.String("outcome", string(analyzeRequestOutput.Outcome)),
140+
// slog.String("ip", clientIp.String()),
141+
// slog.String("user_agent", userAgent),
142+
// slog.String("path", path),
143+
// slog.Int64("asn", geoipInfo.ASN),
144+
// )
145+
// }
146146

147147
nextMiddleware.ServeHTTP(res, req)
148148
}

0 commit comments

Comments
 (0)