Spring / Spring Boot
Difference between HttpServletRequest and ServerHttpRequest.
HttpServletRequest is part of the standard Java Servlet API, designed for use in traditional, thread-per-request servlet containers. ServerHttpRequest is an abstraction introduced by the Spring Framework, primarily for use in reactive programming environments (like Spring WebFlux), which is not tied to the Servlet API's thread model.
| Feature | HttpServletRequest | ServerHttpRequest |
|---|---|---|
| Framework/API | Standard Java Servlet API (javax.servlet.http or jakarta.servlet.http) | Spring Framework abstraction (org.springframework.http.server or .reactive) |
| Programming Model | Synchronous, blocking, thread-per-request model | Asynchronous, non-blocking, reactive model (WebFlux) |
| Thread Management | Uses a dedicated thread to handle the entire request life cycle | Can switch threads during processing for efficiency; not thread-aware in the same way as servlets |
| Purpose | Provides request information for HTTP servlets (e.g., doGet, doPost) | Provides a generic abstraction over server-side HTTP, allowing Spring to run on different platforms (Servlet, Netty, etc.) |
| Relationship | Extends the generic ServletRequest interface | Is an interface with specific implementations (e.g., ServletServerHttpRequest wraps an HttpServletRequest when running on a servlet container) |
More Related questions...