|
169 | 169 | }); |
170 | 170 | }); |
171 | 171 |
|
| 172 | +// ----------------------------------------------------------------------------- |
| 173 | +// Request Timeouts (Kestrel) |
| 174 | +// ----------------------------------------------------------------------------- |
| 175 | +// Add request timeouts for local development to match IIS behavior (web.config). |
| 176 | +// This ensures slow requests timeout after 30 seconds, consistent with the UI threshold. |
| 177 | +// Educational Note: In Azure App Service, the web.config requestTimeout handles this. |
| 178 | +// For local Kestrel development, we use the RequestTimeouts middleware instead. |
| 179 | +builder.Services.AddRequestTimeouts(options => |
| 180 | +{ |
| 181 | + // Default 30-second timeout for all endpoints (matches web.config and UI threshold) |
| 182 | + options.DefaultPolicy = new Microsoft.AspNetCore.Http.Timeouts.RequestTimeoutPolicy |
| 183 | + { |
| 184 | + Timeout = TimeSpan.FromSeconds(30), |
| 185 | + TimeoutStatusCode = StatusCodes.Status504GatewayTimeout |
| 186 | + }; |
| 187 | + |
| 188 | + // Extended timeout for slow request simulation endpoint |
| 189 | + // This endpoint intentionally runs 20-35s requests, so it needs more time |
| 190 | + options.AddPolicy("SlowRequest", new Microsoft.AspNetCore.Http.Timeouts.RequestTimeoutPolicy |
| 191 | + { |
| 192 | + Timeout = TimeSpan.FromSeconds(120), |
| 193 | + TimeoutStatusCode = StatusCodes.Status504GatewayTimeout |
| 194 | + }); |
| 195 | + |
| 196 | + // No timeout for health/admin endpoints - they must always respond |
| 197 | + options.AddPolicy("NoTimeout", new Microsoft.AspNetCore.Http.Timeouts.RequestTimeoutPolicy |
| 198 | + { |
| 199 | + Timeout = null // Disable timeout |
| 200 | + }); |
| 201 | +}); |
| 202 | + |
172 | 203 | var app = builder.Build(); |
173 | 204 |
|
174 | 205 | // ----------------------------------------------------------------------------- |
|
195 | 226 | // CORS must be called before UseRouting |
196 | 227 | app.UseCors(); |
197 | 228 |
|
| 229 | +// Request timeouts middleware (Kestrel) - matches web.config requestTimeout for IIS |
| 230 | +// Educational Note: This must be placed before UseRouting so timeouts apply to all requests. |
| 231 | +app.UseRequestTimeouts(); |
| 232 | + |
198 | 233 | // Serve static files from wwwroot (for the SPA dashboard) |
199 | 234 | app.UseDefaultFiles(); // Enables default document (index.html) |
200 | 235 | app.UseStaticFiles(); |
|
0 commit comments