Defaults for HttpClient helper methods
Description
@guardrex Given the option to modify Headers shown here it would be great to see what the defaults for some of the more interesting headers when using the HttpClient Helpers, such as Headers.Accept, Headers.AcceptEncoding, Content.Headers.ContentType, HttpCompletionOption, etc. I may be going to unnecessary troubles to configuring what's already default in the Helpers. Thanks!
Page URL
https://learn.microsoft.com/en-us/aspnet/core/blazor/call-web-api?view=aspnetcore-8.0&pivots=webassembly#typed-httpclient
Content source URL
https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/blazor/call-web-api.md
Document ID
c7e59a08-1c60-32c2-75fd-33cb77ff7a5d
Article author
@guardrex
💘 Hello, February! Goodbye, New Year's resolutions! 😆
A green dinosaur 🦖 will be along shortly to assist. Stand-by ........
Hello @markarnolditpro ... I'll need to get back to you in a day (or three! 😆). I'm experiencing an extremely high Blazor issue load at the moment ⛰️⛏️😅. I'll get back to you as soon as I can.
OK ... I'm BACK! 😄
Well ... I don't think that are very many (or any 😄) to describe for Blazor (i.e., headers that Blazor sets for you). AFAIK, a new HttpClient will get the default request headers ...
https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.defaultrequestheaders?view=net-8.0#system-net-http-httpclient-defaultrequestheaders
... based on a new HttpRequestHeaders ...
... and I don't think very many (or any) of those get set by Blazor.
Let's ask @MackinnonBuck if he has a comment on this ... about Blazor setting any request headers, which I don't think Blazor really does, and any non-Blazor influences on headers ... Kestrel influences ... middleware along the pipeline ... the browser itself. I'm not sure that we can be specific at all, except perhaps to say that Blazor doesn't set additional request headers for an HttpClient.
I'm not sure that we can be specific at all, except perhaps to say that Blazor doesn't set additional request headers for an
HttpClient.
Yep, this sounds right to me 🙂
Thanks @MackinnonBuck @guardrex. Farther down in the doc I see:
Blazor's client-side implementation of HttpClient uses Fetch API. Fetch API allows the configuration of several request-specific options....
Implication is that HttpClient for Blazor WASM is something "else", hence my concern that it may not have the same functionality / behavior as a non-browser implementation.
It's "something else" in the sense that it isn't an ASP.NET Core API ... it's a JavaScript API. It's used by Blazor, so it's not "something else" in that sense.
The article covers how one can use the HttpRequestMessage API of System.Net.Http to interact with headers. I think I'll add a remark immediately under that to the effect that Blazor doesn't directly set other request headers. Fetch API doesn't either. That's covered by the Fetch API docs, which are cross-linked. The user agent interacts directly with headers, but that's also in external doc sets, including the Fetch API docs, and doesn't pertain to Blazor. I'll try to wrap all of this up in a couple of remarks for the article.
I'm also going to make a small change to that Fetch API line about configuring request options. The options are configured via the .NET API and Blazor API, so I don't want readers to feel that they need to explicitly go into Fetch API docs and figure out how to do something. Devs should look to the knobs and switches of the .NET API and Blazor API (crosslinked to WebAssemblyHttpRequestMessageExtensions) ... which in turn affect Fetch API params. I'll improve that bit because we only currently link to four of six extension methods. I think it best to "harden" that API coverage by just linking to WebAssemblyHttpRequestMessageExtensions instead of showing a table that's subject to churn over the years.