Skip to content

feat(fetch): make Body subclassable by downstream wrappers #52

Description

@medz

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions