Set HttpRequestMessage.Properties in C#
See original GitHub issueHi,
Apologies if I’ve missed something obvious, but there doesn’t currently appear to be a way to set values into HttpRequestMessage.Properties
from NSwag-generated C# code layers.
This seems to be an existing pattern for controlling specifics of outgoing requests into various instances of DelegatingHandler
and the HttpClientFactory
chain, that are outside the behaviour of APIs as Swagger would see them, but very much tied into how clients make their actual HTTP calls. Per-request timeouts, OAuth scopes; I’ve come across a variety of handlers that expect Properties
to be accessible to the caller.
Is this something that could be considered, pull-requested etc?
Thanks in advance for your assistance.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:5 (1 by maintainers)
Top Results From Across the Web
HttpRequestMessage.Properties Property (System.Net.Http)
Gets a set of properties for the HTTP request.
Read more >What is HttpRequestMessage.Properties?
The HttpRequestMessage class has a Properties property, which is a dictionary in which we can put whatever we need.
Read more >C# : What is HttpRequestMessage.Properties? - YouTube
C# : What is HttpRequestMessage. Properties ? To Access My Live Chat Page, On Google, Search for "hows tech developer connect" As I...
Read more >C# (CSharp) Microsoft.Http HttpRequestMessage Examples
Http HttpRequestMessage - 35 examples found. These are the top rated real world C# (CSharp) examples of Microsoft.Http.HttpRequestMessage extracted from ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks @YZahringer for the reply. If I am not mistaken, this only allows static configuration at client construction time. That is a good start, for sure, and helps with some scenarios; much appreciated for the idea!
Our use-case is more aimed at per-request properties, where one single request has a specific and specialised need to set some properties for a given invocation, and a different invocation has a different need (contextual calls, essentially). Managing N different copies of a client, each with unique configuration for that, gets complicated fast in dependency injection.
You can use ClientBaseClass and ConfigurationClass to pass configuration. Then use UseHttpRequestMessageCreationMethod to create
HttpRequestMessage
and apply properties.Example of client base class: