ServerHttpRequest class abstract interface

An abstract interface representing an HTTP request on the server side.

This interface provides a standardized way to interact with HTTP requests in server environments, abstracting away framework-specific details while providing access to all essential request information. It extends HttpInputMessage to include request body capabilities and adds server-specific features like attributes and parameter handling.

Features

  • Framework abstraction: Works with any underlying HTTP framework through the generic type
  • Request metadata: Access to method, URI, query parameters, and headers
  • Attribute storage: Server-side request-scoped attribute storage
  • Parameter handling: Convenient access to query and form parameters
  • Type safety: Generic type parameter for framework-specific request types

Type Parameters

  • HttpRequest: The underlying framework-specific request type (e.g., shelf.Request, io.HttpRequest)

Example Implementations

// For Shelf framework
class ShelfServerHttpRequest implements ServerHttpRequest<shelf.Request> {
  // Implementation for Shelf requests
}

// For Dart IO
class IoServerHttpRequest implements ServerHttpRequest<io.HttpRequest> {
  // Implementation for Dart IO requests
}

Common Use Cases

  • Middleware: Intercept and process requests in HTTP middleware
  • Controllers: Access request data in web controllers
  • Filters: Apply request filtering and validation
  • Framework Adapters: Create adapters for different HTTP frameworks
Implemented types
Implementers

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

getAttribute(String name) Object?
Returns the value of the specified request attribute, or null if not set.
getAttributeNames() Set<String>
Returns a set of all attribute names currently stored in this request.
getAttributes() Map<String, Object>
Returns a map of all attributes attached to this request.
getBody() → InputStream
Returns the message body as an InputStream.
inherited
getContentLength() int
Returns the size of the HTTP request body in bytes, if known.
getContextPath() String
Returns the context path of the current web application.
getCookies() HttpCookies
Returns the HttpCookies collection associated with this request or response.
getHeaders() HttpHeaders
Returns the HTTP headers associated with this message.
inherited
getMethod() HttpMethod
Returns the HttpMethod used for this request.
getOrigin() String
Returns the origin of the incoming HTTP request.
getParameter(String name) String?
Returns the first value of the specified request parameter, or null if not present.
getParameterMap() Map<String, List<String>>
Returns a map of all request parameters and their corresponding values.
getParameterValues(String name) List<String>
Returns all values for the specified request parameter name.
getPathVariable(String name) String?
Returns the value of a single path variable by its name, or null if not present.
getPathVariables() Map<String, String>
Returns all path variables extracted from the matched URI template.
getQueryString() String?
Returns the raw query string component of the request URI, if any.
getRequestURI() Uri
Returns the request URI as provided by the client.
getRequestUrl() String?
Returns the logical request URL associated with this HTTP request.
getSession([bool create = true]) HttpSession?
Returns the current HttpSession associated with this request, or optionally creates one.
getUri() Uri
Returns the full URI of this request.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
removeAttribute(String name) → void
Removes the request attribute with the specified name.
setAttribute(String name, Object value) → void
Sets or replaces a request attribute with the given name and value.
setContextPath(String contextPath) → void
Sets the context path for the http request.
setHandlerContext(HandlerMethod handler, PathPattern pattern) → void
Associates the resolved handler method and path pattern with this request.
setHeaders(HttpHeaders headers) → void
Replaces the entire set of HTTP headers for this message.
inherited
setRequestUrl(String requestUrl) → void
Sets the request URL associated with this HTTP request.
shouldUpgrade() bool
Indicates whether this request should be upgraded to a higher-level protocol (e.g., WebSocket, HTTP/2 push, or other upgrade-capable protocols).
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

ATTRIBUTE_NAME String
The common suffix used to identify attribute-related metadata keys.
final
CLASS → Class
Represents the ServerHttpRequest type for reflection purposes.
final
REST__REQUESTED__ String
The key used to store or reference the controller type metadata within the framework’s context or attribute maps.
final