Implement interception for send
and MultipartRequests
#94
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi there 👋
I recently started using your package, since I was missing some decent standalone http interceptors for flutter and your package fits the description neatly.
Problem
I stumbled upon the issue of unauthenticated file upload requests (I use an interceptor for auth headers) and learned that the
send
method has no implemented interception. Since the job and code did not seem to difficult, I tried to implement those.What was done
Firstly, i changed the
_sendUnstreamed
method to not use thesend
method directly (which just calls_inner.send
anyways), but rather make a call to_inner.send
Since send returns
StreamedResponse
I duplicated and changed parts of the interception logic to handleStreamedResponse
instead of normalResponse
.I added a
StreamedResponseData
class, which can be "converted" to a normalResponseData
, just without a body/bodyBytes (since that would not make sense in the case of a streamed body). I did this, so we can still handle aStreamedResponse
like a normal one, modifying headers and all that, but dont have access to the body.In case someone wants to modify or access the streamed body, I extended the
InterceptorContract
to include ainterceptStreamedResponse
method. I took some architectural liberties here and this could probably be implemented differently, by making a subclassedStreamedInterceptorContract
for example.Then I also had to make some changes to the
RequestData
class, in order to support Multipart request.I did this, by simply rearranging some ifs. The
fields
andfiles
are put into aMultipartBody
object, that is put into the body.