Skip to main content

xray_network_dio_interceptor 0.1.3 copy "xray_network_dio_interceptor: ^0.1.3" to clipboard
xray_network_dio_interceptor: ^0.1.3 copied to clipboard

A pure Dart package providing a Dio interceptor for xray_inspector. Works with Flutter and Dart backends (Serverpod, Relic, Dart Frog, Shelf).

xray_network_dio_interceptor #

A Dio interceptor for capturing network calls with the xRay inspector.

For full documentation and guides, see the xRay docs.


Disclaimer: This is a commercial package. To use this package, you need to have either a commercial xRay license or a free xRay Community License. The xRay desktop apps for macOS, Windows and Linux are the authorized UI clients for this library. For more details, please check the LICENSE file.

Setup #

Attach xRay to each Dio instance:

final dio = Dio()
  ..interceptors.addAll([
    AuthInterceptor(),  // may call handler.reject(...)
    CacheInterceptor(), // may call handler.resolve(...)
  ]);
XRayNetworkDioInterceptor.attach(dio, inspector: networkDioInspector);

The order does not matter: call attach before or after adding your own interceptors. xRay puts itself in front of dio.interceptors and runs your interceptors itself, once per request and in the same order, so it sees how every request ended:

  • A request another interceptor rejects shows as failed, with the error it was rejected with and the note "Rejected by interceptor".
  • A request another interceptor answers itself, for example from a cache, shows as successful, with that response and the note "Resolved by interceptor".
  • A cancelled request shows as failed with the note "Cancelled".
  • Every other request is recorded as it went over the network, with the headers and body your interceptors actually sent.

An interceptor that retries with dio.fetch(...) sends a new request, which shows up as a call of its own.

Interceptors you insert in front of xRay after attaching (dio.interceptors.insert(0, ...)) run before xRay sees the request. dio.clone() copies xRay's interceptor, and the clone's requests would then run through the original Dio's interceptors and adapter: clone before attaching, and attach xRay to each clone separately.

Adding the interceptor yourself #

dio.interceptors.add(XRayNetworkDioInterceptor(inspector: ...)) still works for apps without interceptors that stop requests. When another interceptor calls handler.reject or handler.resolve in onRequest, Dio skips xRay's response and error steps wherever xRay is in the list, so that request stays loading or is not shown at all. Use attach instead.

Credentials are masked #

The headers your interceptors add, such as Authorization, are recorded masked: the network inspector keeps only the scheme and the last 4 characters of a long token (Bearer …a1b2), and does the same for Proxy-Authorization, Cookie, Set-Cookie and X-Api-Key. Choose other headers, or record them in full, with redactHeaders on the XRayNetworkInspector you pass to attach; see Masking credentials in the xray_inspector README. Bodies are recorded as they are unless you pass redactBody.

Using it together with enableHttpOverride #

Dio's default adapter sends requests through HttpClient. When the same XRayNetworkInspector (or another one) also has enableHttpOverride: true, the interceptor tells the override to skip the requests it already records, so every Dio call shows up once. Requests are matched on method and URL; no header or other marker is added to the request.

1
likes
0
points
802
downloads

Documentation

Documentation

Publisher

verified publisherxrayinspector.dev

Weekly Downloads

A pure Dart package providing a Dio interceptor for xray_inspector. Works with Flutter and Dart backends (Serverpod, Relic, Dart Frog, Shelf).

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

dio, xray_inspector

More

Packages that depend on xray_network_dio_interceptor