HttpBody<T> class

Represents an HTTP entity, consisting of optional headers and an optional body.

This class is a generic container for HTTP request or response data. It allows storage of headers (HttpHeaders) and a typed body (T), providing convenient accessors and equality comparison via EqualsAndHashCode.

Features

  • Stores optional HTTP headers.
  • Stores an optional body of generic type T.
  • Equality and hash code are based on headers and body.
  • Immutable design for thread safety and predictable behavior.

Type Parameters

  • T: The type of the body content. Use void when no body is expected.

Example

final entity = HttpBody<String>(
  'Hello, world!',
  HttpHeaders()
    ..set('Content-Type', 'text/plain')
);

print(entity.getBody()); // 'Hello, world!'
print(entity.getHeaders()?.value('Content-Type')); // 'text/plain'

Notes

  • _headers may be null if not provided.
  • _body may be null if not provided.
  • Designed to be immutable after construction.
Implementers
Annotations
  • @Generic.new(HttpBody)

Constructors

HttpBody([T? _body, HttpHeaders? _headers])
Creates an HttpBody with an optional body and optional headers.

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

equalizedProperties() List<Object?>
Mixin-style contract for value-based equality, hashCode, and toString.
getBody() → T?
Returns the body of this entity.
getHeaders() HttpHeaders?
Returns the HTTP headers associated with this entity.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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