IoHttpTransport class

The HttpTransport for platforms with dart:io (the Dart VM, Flutter on mobile and desktop), built on dart:io's HttpClient.

platformHttpTransport() returns one on these platforms, so you create it yourself only to configure the HttpClient: a proxy, trusted certificates, a user agent. Declare it as an HttpTransport bean and the Feign starter uses it.

How it treats an HttpRequest:

  • Its headers replace the HttpClient defaults of the same name (User-Agent, Accept-Encoding); Content-Length is always taken from the body.
  • Redirects are followed when followRedirects is set, as far as HttpClient follows them: for GET and HEAD, and a 303 after a POST.
  • readTimeout limits each wait for data (the response, then every chunk of the body) and timeout the whole exchange. When one runs out the request is aborted and an HttpTransportException with isTimeout is thrown.
  • Socket and other I/O errors become an HttpTransportException whose cause is the original error.
import 'dart:io';

import 'package:spring_web_dart/io.dart';

// Feign calls go through the company proxy.
@Configuration()
class HttpSetup {
  @Bean()
  HttpTransport httpTransport() => IoHttpTransport(
    connectTimeout: const Duration(seconds: 3),
    client: HttpClient()
      ..findProxy = (_) => 'PROXY proxy.neon.books:3128',
  );
}

Spring (Java): JdkClientHttpRequestFactory, on the JDK's HttpClient:

var factory = new JdkClientHttpRequestFactory(HttpClient.newHttpClient());
factory.setReadTimeout(Duration.ofSeconds(5));
Implemented types

Constructors

IoHttpTransport({Duration? connectTimeout, HttpClient? client})
A transport that sends through client, or through a new HttpClient when none is given. connectTimeout, when set, becomes the client's connectionTimeout: the longest wait for a connection to open. close closes the client, also one passed in.

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

close() → void
Releases the transport's connections. Call it when the transport is no longer needed (the Feign starter does when the application stops); do not use the transport afterwards.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
send(HttpRequest request) → Future<HttpResponse>
Sends request and reads the whole response into memory.
override
stream(HttpRequest request) → Future<StreamedHttpResponse>
Sends request and completes as soon as the status and headers have arrived. The body is then read from StreamedHttpResponse.body as it comes.
override
toString() → String
A string representation of this object.
inherited

Operators

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