Skip to content

Add client in constructor in DisposableHandler for convenience #116

Closed
@dan12411

Description

@dan12411

Hi guys, is appropriate to add client in constructor in DisposableHandler for convenience usage?

For example,

class DisposableHandler implements HttpHandler {
  DisposableHandler(this.client);

  Client? client;

  @override
  Future<HttpResponse> handle(HttpRequest request) async {
    final httpClient = client ?? Client();
    try {
      return await PersistentHandler(httpClient).handle(request);
    } finally {
      httpClient.close();
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions