Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a canonical base io.HttpClient implementation to use for HttpOverrides #40519

Open
davidmorgan opened this issue Feb 7, 2020 · 1 comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-io type-enhancement A request for a change that isn't a bug

Comments

@davidmorgan
Copy link
Contributor

Filed on behalf of an internal customer.

dart:io provides a mechanism to swap the implementation of HTTP used by all components in a program with HttpOverrides mechanism.

Real world dart programs resort to this mechanism in several situations:

  1. Fake internet data in tests.
  2. Route HTTP requests through higher level services on platforms with limited networking t
  3. Enforce program-wide policies.

Trying to implement HttpClient from scratch is pretty tricky:

  1. HttpClient has 14 methods, 2 for each HTTP verb. Each of which usually has a one line implementation routing to open(), but this repesents 100 lines of boilerplate in each HttpClient implementation.
  2. HttpClientResponse implements Stream<List>. Stream interface is tricky to implement from scratch, yet (as far as I remember) we can't usefully extend Stream.
  3. HttpHeaders is a class wrapping a simple Map<String, List>, which doesn't bear any dependency on the exact implementation of HTTP, yet needs to be implemented from scratch every time.
  4. All of the above makes users' HttpClient implementation tightly couple to the upstream dart:io interface and make the changes to it burdensome: [Breaking Change Request] HttpHeaders allows cased header fields #39657

Proposal:
dart:io should provide some kind of BaseHttpClient implementing HttpClient and allowing users to implement only the transport mechanism. This could be similar to package:http.BaseClient.

@zichangg

@vsmenon vsmenon added area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-io labels Feb 7, 2020
@sortie sortie added the type-enhancement A request for a change that isn't a bug label Feb 7, 2020
@sortie
Copy link
Contributor

sortie commented Feb 7, 2020

This could potentially be provided in a package.

@zichangg zichangg self-assigned this Feb 15, 2020
@natebosch natebosch reopened this May 14, 2020
@zichangg zichangg removed their assignment Sep 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-io type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

5 participants