close method

  1. @override
Future<HttpClientResponse> close()
override

Completes the request and intercepts the response.

Sends the response headers to the native side, triggers interpretation of the response stream, and returns a wrapped response that tracks the response data.

Implementation

@override
Future<HttpClientResponse> close() async {
  final response = await request.close();

  // Notify the native side of response headers and metadata.
  MethodChannelController.responseHeadersReceived(
    StethoInspectorResponse(
      url: request.uri.toString(),
      statusCode: response.statusCode,
      requestId: id,
      headers: headersToMap(response.headers),
      connectionReused: false,
      reasonPhrase: response.reasonPhrase,
      connectionId: id.hashCode,
    ),
  );

  // Request native side to interpret the response stream.
  MethodChannelController.interpretResponseStream(id);

  // Return a wrapped response that intercepts the response body.
  return StethoHttpClientResponse(
    response,
    response.transform(createResponseTransformer(id)),
  );
}