CodingAleCR / http_interceptor

A lightweight, simple plugin that allows you to intercept request and response objects and modify them if desired.
MIT License
134 stars 67 forks source link

Issue with Retrying requests with protobuf as response #39

Closed sunnyagarwal008 closed 3 years ago

sunnyagarwal008 commented 4 years ago

The _attemptRequest method checks if the retry policy is configured, and if yes it creates a response clone using ResponseData.fromHttpResponse(response) which tries to read response body as string (response.body). This will not work if the response body is a protobuf byte array.

Future<Response> _attemptRequest(Request request) async {
    var response;
    try {
      // Intercept request
      request = await _interceptRequest(request);

      var stream = requestTimeout == null
          ? await send(request)
          : await send(request).timeout(requestTimeout);

      response = await Response.fromStream(stream);
      if (retryPolicy != null &&
          retryPolicy.maxRetryAttempts > _retryCount &&
          await retryPolicy.shouldAttemptRetryOnResponse(
              ResponseData.fromHttpResponse(response))) {
        _retryCount += 1;
        return _attemptRequest(request);
      }
    } catch (error) {
      if (retryPolicy != null &&
          retryPolicy.maxRetryAttempts > _retryCount &&
          retryPolicy.shouldAttemptRetryOnException(error)) {
        _retryCount += 1;
        return _attemptRequest(request);
      } else {
        rethrow;
      }
    }

    _retryCount = 0;
    return response;
  }
issue-label-bot[bot] commented 4 years ago

Issue-Label Bot is automatically applying the label bug to this issue, with a confidence of 0.80. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

CodingAleCR commented 4 years ago

Hi, yes, the initial idea was to create a plugin mostly for RESTful APIs, I did not notice that people were using it for protobufs. I'm sorry you are running into this much trouble. I will definitely add protobuf support going forward, but for now, the plugin is not compatible 😕

CodingAleCR commented 3 years ago

Hi, I have added this to the backlog, hopefully I will have it ready soon enough, I will close the issue for now and will ping back once it's merged. Cheers!