-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
Controller returning IAsyncEnumerable consumed by HttpClient & GetAsync with ResponseHeadersRead not working on Windows with content type application/json #12883
Comments
Thanks for contacting us, @rossbuggins. |
Thanks for getting back to me. When documentation is written for this it needs to be pretty clear this is the behaviour- as I think the general assumption would be that returning IAsyncEnumerable from a controller will stream the response back at each yield return? ie the though that its doing something more special that IEnumerable responses? |
I've quickly knocked up the below ActionResultExecutor to handle a proof of concept. Strange thing though, if i set content type to application/json then HttpClient doesn't return to ReadAsync until the whole request is finished, even though i can see with wireshark (and server memory) that the data is being sent, but if i use text/event-stream then HttpClient is responding each time the buffer is flushed on the server?
|
@Tratcher would you know what's up with the |
Please show the client code. It should look something like this:
|
yup, thats what I've got (tried with SendAsync with type post as well - see below), the latest code which works and deserializes the json objects "live" as they appear at the client is below, seems pretty neat - just not understanding why the variance in behaviour with the content type. Although - I've just tested in chrome and I get this same behaviour, which, I would expect I think. I just thought the HTTP client would not have this behaviour, as the data is getting to the client (both in chrome and .net HTTP client) from looking at wireshark. It's almost as if when it sees text/event-stream it makes the data avaliable straight away but with application/json it keeps it in an internal buffer? Or is this happening somewhere deeper that HttpClient? Server side:
Client code
|
HttpClient doesn't check the content-type. |
at the moment the only difference i can see is switiching between the two
I've double checked fiddler and the headers are showing there with either content type selected. Whats HttpClient looking for when set for HttpCompletionOption.ResponseHeadersRead? |
just looking in HttpClient SendAsync and this is only place i can see a decision based on the completion option,
So the HttpClient then uses HttpClientHandler? So is it going to be something in there or the handlers pipeline? |
Which one is delayed? text/event-stream? Are you using IIS Express? It's dynamic compression module looks for text/* and it partially buffers during compression. |
when using application/json client.GetAsync is delayed until all data is at the client. Using .net core host:
|
3.0.0-preview7.19365.7 in use |
Hi - so I've just tried this on Ubuntu running core 3 preview 7 and the behaviour is what I expected - i.e. no difference between setting content type to be application/json or text/event-stream. This is not the case on windows, where when content type is application/json the call to HttpClient |
Hi, Any thoughts on this? With different behaviour on different platforms? |
No, there shouldn't be a difference here across platforms. I suggest collecting full client and server logs along with wireshark traces for both scenarios and we can compare them. |
So trace level logging in the apps for both server and client? |
Thank you, I've been looking for this. For some reason I cannot get this to work with Blazor Client-side (wasm). It seems like the client is buffering the full response before it starts rendering. If you wouldn't mind maybe you can share some suggestions. Client-side code below: (sorry about the code formatting) `protected override async Task OnInitializedAsync()
} public async IAsyncEnumerable GetDataAsync()
}` |
Thank you for contacting us. Due to no activity on this issue we're closing it in an effort to keep our backlog clean. If you believe there is a concern related to the ASP.NET Core framework, which hasn't been addressed yet, please file a new issue. |
Currently trying out the controller IAsyncEnumerable support. I have a controller returning IAsyncEnumerable. I have a client that it consuming this, and I thought i would be able to access the data before its all finished being received, but not currently seeing this - I'm using ReadAsStreamAsync & ReadAsync on the HttpClient.
The text was updated successfully, but these errors were encountered: