Context
PR #51 moves Body toward the shape downstream clients want: a Fetch-style body primitive that extends Blob, implements Stream<Uint8List>, and exposes stream(), listen, bytes(), arrayBuffer(), text(), json(), blob(), slice(), clone(), bodyUsed, size, and type / contentType.
That shape would let request libraries build on ht.Body directly instead of wrapping or re-modeling body behavior.
The remaining blocker for downstream packages is subclassing. Today Body is constructed through a public factory and a private Body._(...) generative constructor, so an external package cannot write:
final class RequestBody extends Body {
RequestBody(super.init);
}
Dart subclasses need to call a superclass generative constructor, and a factory constructor cannot be used as super(...).
Request
Please make Body subclassable by external packages, either with a public generative constructor that preserves the current BodyInit normalization behavior or an equivalent documented extension point.
The ideal downstream use case is:
final class RequestBody extends Body {
RequestBody(
super.init, {
required this.replayable,
});
final bool replayable;
@override
RequestBody clone() {
return RequestBody._fromBody(
super.clone(),
replayable: replayable,
);
}
}
The downstream class would inherit the body primitive API from ht.Body and only add request-specific metadata or policy.
Requirements
- External packages can subclass
Body without reimplementing BodyInit normalization.
- Subclasses can override
clone() and return the subclass type while preserving metadata.
- Existing
Body behavior for bodyUsed, size, type, contentType, stream(), and byte readers remains intact.
- The shape works across VM, Node, and browser runtimes.
Related
Context
PR #51 moves
Bodytoward the shape downstream clients want: a Fetch-style body primitive that extendsBlob, implementsStream<Uint8List>, and exposesstream(),listen,bytes(),arrayBuffer(),text(),json(),blob(),slice(),clone(),bodyUsed,size, andtype/contentType.That shape would let request libraries build on
ht.Bodydirectly instead of wrapping or re-modeling body behavior.The remaining blocker for downstream packages is subclassing. Today
Bodyis constructed through a public factory and a privateBody._(...)generative constructor, so an external package cannot write:Dart subclasses need to call a superclass generative constructor, and a factory constructor cannot be used as
super(...).Request
Please make
Bodysubclassable by external packages, either with a public generative constructor that preserves the currentBodyInitnormalization behavior or an equivalent documented extension point.The ideal downstream use case is:
The downstream class would inherit the body primitive API from
ht.Bodyand only add request-specific metadata or policy.Requirements
Bodywithout reimplementingBodyInitnormalization.clone()and return the subclass type while preserving metadata.Bodybehavior forbodyUsed,size,type,contentType,stream(), and byte readers remains intact.Related