|
9 | 9 | "net/http" |
10 | 10 | "net/netip" |
11 | 11 | "strconv" |
12 | | - "strings" |
13 | 12 | "time" |
14 | 13 | "unicode/utf8" |
15 | 14 |
|
@@ -59,8 +58,8 @@ func (client *Client) Middleware(config *MiddlewareConfig) func(next http.Handle |
59 | 58 | } |
60 | 59 | } |
61 | 60 |
|
62 | | - userAgent := strings.TrimSpace(req.UserAgent()) |
63 | | - var err error |
| 61 | + // userAgent := strings.TrimSpace(req.UserAgent()) |
| 62 | + // var err error |
64 | 63 | path := req.URL.Path |
65 | 64 | ctx := req.Context() |
66 | 65 | logger := client.getLogger(ctx) |
@@ -92,57 +91,58 @@ func (client *Client) Middleware(config *MiddlewareConfig) func(next http.Handle |
92 | 91 | ctx = context.WithValue(ctx, CtxKeyGeoip, geoipInfo) |
93 | 92 | req = req.WithContext(ctx) |
94 | 93 |
|
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/") { |
130 | 95 | // client.handleHttpRequest(ctx, clientIp, res, req) |
131 | 96 | // 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 |
135 | 135 |
|
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 | + // } |
146 | 146 |
|
147 | 147 | nextMiddleware.ServeHTTP(res, req) |
148 | 148 | } |
|
0 commit comments