http_interceptor icon indicating copy to clipboard operation
http_interceptor copied to clipboard

Fix send when Request isn't a StreamedRequest

Open FabianTerhorst opened this issue 3 years ago • 10 comments

Send doesn't need to be used with a StreamedRequest. When it doesn't, the interceptor converts the StreamedResponse to a Response.

FabianTerhorst avatar Mar 09 '22 21:03 FabianTerhorst

Hey, thank you for the PR.🎉

I will take a look as soon as I can so that I can review the issue and also the solution proposed.

CodingAleCR avatar Mar 11 '22 07:03 CodingAleCR

Hello, not sure why but using @FabianTerhorst main git repo, I am able to send a request and it works perfectly, but when using @CodingAleCR main branch or 2.0.0-beta.5, it does not work. My send request hangs indefinitely.

giiyms avatar Mar 19 '22 15:03 giiyms

Interesting. Probably pointing to the problem about the streamed request that the PR fixes.

What type of request are you making @giiyms ?

CodingAleCR avatar Mar 19 '22 15:03 CodingAleCR

Interesting. Probably pointing to the problem about the streamed request that the PR fixes.

What type of request are you making @giiyms ?

I am sending an http GET request for an event stream.

  final streamUrl = Uri.https(_sseUrl, '$_channel', {'symbols': symbol});
  final request = http.Request('GET', streamUrl);

  final headers = {'Content-Type': 'text/event-stream'};
  request.headers.addAll(headers);

  final response = await _tokenizedClient.send(request);

The tokenized Client is the standard InterceptorContract which talks to a tokenservice for a parameter on the intercept request.

  @override
  Future<BaseRequest> interceptRequest({required BaseRequest request}) async {
    return request.copyWith(url: request.url.addParameters({'token': _tokenService.token}));
  }

With Fabian's repo, I am able to await stream.first in my test file.

giiyms avatar Mar 19 '22 16:03 giiyms

Oh my bad @CodingAleCR. I thought the commit you did last was applied to your repo and therefore 2.0.0-beta.5, but I see now its on Fabian's repo. Sorry for mix up. I guess I can confirm Fabian's changes fixed my issue!

giiyms avatar Mar 19 '22 16:03 giiyms

Nice! Thank you for the confirmation. I am trying to check that these changes don't affect the MultiPartRequest. Could you confirm what type of request you are using with the send method?

CodingAleCR avatar Mar 19 '22 16:03 CodingAleCR

Nice! Thank you for the confirmation. I am trying to check that these changes don't affect the MultiPartRequest. Could you confirm what type of request you are using with the send method?

Hello, it was not a MultiPartRequest, so I can not confirm it does not affect that.

giiyms avatar Mar 20 '22 14:03 giiyms

Currently adding a new MultipartApp to the example app, just so we can test properly. In the meantime I'd like to know are you using server sent events by any chance? I want to add as many tests to this as possible.

CodingAleCR avatar Aug 03 '22 05:08 CodingAleCR

I was looking at the implementation of this PR and this might break streamed requests, if we added tests or thought of a different solution then I would definitely merge this to the main repo.

CodingAleCR avatar Aug 10 '22 17:08 CodingAleCR

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Oct 12 '22 08:10 stale[bot]

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Mar 18 '23 05:03 stale[bot]