HttpOverrides class

This class facilitates overriding HttpClient with a mock implementation. It should be extended by another class in client code with overrides that construct a mock implementation. The implementation in this base class defaults to the actual HttpClient implementation. For example:

class MyHttpClient implements HttpClient {
  ...
  // An implementation of the HttpClient interface
  ...
}

main() {
  HttpOverrides.runZoned(() {
    ...
    // Operations will use MyHttpClient instead of the real HttpClient
    // implementation whenever HttpClient is used.
    ...
  }, createHttpClient: (SecurityContext c) => new MyHttpClient(c));
}

Constructors

HttpOverrides()

Properties

hashCodeint
read-only, inherited
The hash code for this object. [...]
runtimeTypeType
read-only, inherited
A representation of the runtime type of the object.

Methods

createHttpClient(SecurityContext? context) → HttpClient
Returns a new HttpClient using the given context. [...]
findProxyFromEnvironment(Uri url, Map<String, String>? environment) → String
Resolves the proxy server to be used for HTTP connections. [...]
noSuchMethod(Invocation invocation) → dynamic
inherited
Invoked when a non-existent method or property is accessed. [...]
toString() → String
inherited
A string representation of this object. [...]

Operators

operator ==(Object other) → bool
inherited
The equality operator. [...]

Static Properties

currentHttpOverrides?
read-only
globalHttpOverrides?
write-only
The HttpOverrides to use in the root Zone. [...]

Static Methods

runWithHttpOverrides<R>(R body(), HttpOverrides overrides) → R
Runs body in a fresh Zone using the overrides found in overrides. [...]
runZoned<R>(R body(), {HttpClient createHttpClient(SecurityContext?), String findProxyFromEnvironment(Uri uri, Map<String, String>? environment)}) → R
Runs body in a fresh Zone using the provided overrides.

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dart.dev/stable/2.13.0/dart-io/HttpOverrides-class.html