Create optimized HTTP session with connection pooling
(self)
| 262 | pass |
| 263 | |
| 264 | def create_http_session(self): |
| 265 | """Create optimized HTTP session with connection pooling""" |
| 266 | session = requests.Session() |
| 267 | |
| 268 | # Configure retry strategy |
| 269 | retry_strategy = Retry( |
| 270 | total=3, |
| 271 | backoff_factor=0.5, |
| 272 | status_forcelist=[429, 500, 502, 503, 504], |
| 273 | ) |
| 274 | |
| 275 | # Configure adapter with connection pooling |
| 276 | adapter = HTTPAdapter( |
| 277 | pool_connections=100, |
| 278 | pool_maxsize=100, |
| 279 | max_retries=retry_strategy |
| 280 | ) |
| 281 | |
| 282 | session.mount("http://", adapter) |
| 283 | session.mount("https://", adapter) |
| 284 | |
| 285 | # Set default headers |
| 286 | session.headers.update({ |
| 287 | 'User-Agent': random.choice(self.user_agents), |
| 288 | 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', |
| 289 | 'Accept-Language': 'en-US,en;q=0.5', |
| 290 | 'Accept-Encoding': 'gzip, deflate', |
| 291 | 'Connection': 'keep-alive', |
| 292 | 'Cache-Control': 'no-cache', |
| 293 | }) |
| 294 | |
| 295 | return session |
| 296 | |
| 297 | def realistic_http_flood(self, target_ip, target_port, duration): |
| 298 | """Advanced HTTP load test with realistic patterns""" |
no outgoing calls
no test coverage detected