Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for manipulating request and response body #496

Closed
wants to merge 1 commit into from
Closed

Support for manipulating request and response body #496

wants to merge 1 commit into from

Conversation

kennethmyhra
Copy link
Collaborator

* Added callbacks that allows manipulation of the request and response
  stream
* See issue #478 for more information
@ewoutkramer
Copy link
Member

Anyway, maybe we can piggyback on the new pipeline capabilities in the HttpClient. I am still getting updated on that new class, so I don't know yet!

@kennethmyhra
Copy link
Collaborator Author

Agree, didn't look into it in detail earlier, but I see now that it's the same interface that's used on the server side and it should therefore work quite similar.

Stream respStream = response.GetResponseStream();
respStream = streamProcessor(respStream, response.Headers);

body = HttpUtil.ReadAllFromStream(respStream);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's a potential risk with the new code: you can nest the streams (good design), but the streams, except for the "outer" one, will never get closed anymore. This was done with the "using" statement in the original code, but this is gone. So, we have a potential resource leak. At least we need to make sure that all more outer streams close their inner stream, except for the most inner one (which is the original stream coming from the request).

In fact, because we "+=" to the delegate, the order of execution is undetermined (see for example here: https://stackoverflow.com/questions/1645478/order-of-event-handler-execution), so there is no guarantee that they are called in the order they are supplied.

I think it is better if we create a List<Func<...>> and iterate over it, passing the returned value onto the next. Since we can then also capture the return values, we can in fact make sure they get disposed as well.

@ewoutkramer
Copy link
Member

@kennethmyhra -- oops, I never submitted my review on this PR....Is this PR still of interest to you? (the new client written in #535 will actually fix this is a more elegant way, because of the new .NET Core webclient used).

@kennethmyhra
Copy link
Collaborator Author

@ewoutkramer I am happy with the solution that the .NET Core WebClient gives us in PR #507.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants