From b9044dc69ddd3873de5b8c0706b46a78c3da57e3 Mon Sep 17 00:00:00 2001
From: Stephan van Rooij <1292510+svrooij@users.noreply.github.com>
Date: Sat, 18 May 2024 21:25:35 +0200
Subject: [PATCH 1/3] Returning delegetion types for DI integration
Fixed #254
---
src/KiotaClientFactory.cs | 55 +++++++++++++------
.../Options/UriReplacementHandlerOption.cs | 7 +++
2 files changed, 44 insertions(+), 18 deletions(-)
diff --git a/src/KiotaClientFactory.cs b/src/KiotaClientFactory.cs
index 0439561..99c00ed 100644
--- a/src/KiotaClientFactory.cs
+++ b/src/KiotaClientFactory.cs
@@ -28,21 +28,21 @@ public static HttpClient Create(HttpMessageHandler? finalHandler = null)
var handler = ChainHandlersCollectionAndGetFirstLink(finalHandler ?? GetDefaultHttpMessageHandler(), defaultHandlers.ToArray());
return handler != null ? new HttpClient(handler) : new HttpClient();
}
-
- ///
- /// Initializes the with a custom middleware pipeline.
- ///
- /// The instances to create the from.
- /// The final in the http pipeline. Can be configured for proxies, auto-decompression and auto-redirects
- /// The with the custom handlers.
- public static HttpClient Create(IList handlers, HttpMessageHandler? finalHandler = null)
- {
- if(handlers == null || !handlers.Any())
- return Create(finalHandler);
- var handler = ChainHandlersCollectionAndGetFirstLink(finalHandler ?? GetDefaultHttpMessageHandler(), handlers.ToArray());
- return handler != null ? new HttpClient(handler) : new HttpClient();
- }
-
+
+ ///
+ /// Initializes the with a custom middleware pipeline.
+ ///
+ /// The instances to create the from.
+ /// The final in the http pipeline. Can be configured for proxies, auto-decompression and auto-redirects
+ /// The with the custom handlers.
+ public static HttpClient Create(IList handlers, HttpMessageHandler? finalHandler = null)
+ {
+ if(handlers == null || !handlers.Any())
+ return Create(finalHandler);
+ var handler = ChainHandlersCollectionAndGetFirstLink(finalHandler ?? GetDefaultHttpMessageHandler(), handlers.ToArray());
+ return handler != null ? new HttpClient(handler) : new HttpClient();
+ }
+
///
/// Creates a default set of middleware to be used by the .
///
@@ -51,7 +51,7 @@ public static IList CreateDefaultHandlers()
{
return new List
{
- //add the default middlewares as they are ready
+ //add the default middlewares as they are ready, and add them to the list above as well
new UriReplacementHandler(),
new RetryHandler(),
new RedirectHandler(),
@@ -60,6 +60,25 @@ public static IList CreateDefaultHandlers()
new HeadersInspectionHandler(),
};
}
+
+ ///
+ /// Gets the default handler types.
+ ///
+ /// A list of all the default handlers
+ /// Order matters
+ public static IList GetDefaultHandlerTypes()
+ {
+ return new List
+ {
+ typeof(UriReplacementHandler),
+ typeof(RetryHandler),
+ typeof(RedirectHandler),
+ typeof(ParametersNameDecodingHandler),
+ typeof(UserAgentHandler),
+ typeof(HeadersInspectionHandler),
+ };
+ }
+
///
/// Creates a to use for the from the provided instances. Order matters.
///
@@ -81,7 +100,7 @@ public static IList CreateDefaultHandlers()
}
}
if(finalHandler != null)
- handlers[handlers.Length-1].InnerHandler = finalHandler;
+ handlers[handlers.Length - 1].InnerHandler = finalHandler;
return handlers[0];//first
}
///
@@ -91,7 +110,7 @@ public static IList CreateDefaultHandlers()
/// The created .
public static DelegatingHandler? ChainHandlersCollectionAndGetFirstLink(params DelegatingHandler[] handlers)
{
- return ChainHandlersCollectionAndGetFirstLink(null,handlers);
+ return ChainHandlersCollectionAndGetFirstLink(null, handlers);
}
///
/// Gets a default Http Client handler with the appropriate proxy configurations
diff --git a/src/Middleware/Options/UriReplacementHandlerOption.cs b/src/Middleware/Options/UriReplacementHandlerOption.cs
index b0a14e7..6198111 100644
--- a/src/Middleware/Options/UriReplacementHandlerOption.cs
+++ b/src/Middleware/Options/UriReplacementHandlerOption.cs
@@ -43,6 +43,13 @@ public UriReplacementHandlerOption(bool isEnabled, IEnumerable
+ /// Creates a new instance of UriReplacementOption with no replacements.
+ ///
+ /// Whether replacement is enabled.
+ /// Replacement is disabled by default.
+ public UriReplacementHandlerOption(bool isEnabled = false) : this(isEnabled, Array.Empty>()) { }
+
///
public bool IsEnabled()
{
From a47e2a84acce352c07ad7620b0a75a6feb168fbb Mon Sep 17 00:00:00 2001
From: Stephan van Rooij <1292510+svrooij@users.noreply.github.com>
Date: Sat, 18 May 2024 21:30:40 +0200
Subject: [PATCH 2/3] its below
---
src/KiotaClientFactory.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/KiotaClientFactory.cs b/src/KiotaClientFactory.cs
index 99c00ed..96c1eb5 100644
--- a/src/KiotaClientFactory.cs
+++ b/src/KiotaClientFactory.cs
@@ -51,7 +51,7 @@ public static IList CreateDefaultHandlers()
{
return new List
{
- //add the default middlewares as they are ready, and add them to the list above as well
+ //add the default middlewares as they are ready, and add them to the list below as well
new UriReplacementHandler(),
new RetryHandler(),
new RedirectHandler(),
From 2564189c61d7a2f31cd5403253ef24401068253a Mon Sep 17 00:00:00 2001
From: Stephan van Rooij <1292510+svrooij@users.noreply.github.com>
Date: Tue, 21 May 2024 19:53:16 +0200
Subject: [PATCH 3/3] bump version
---
CHANGELOG.md | 28 +++++++++++--------
...rosoft.Kiota.Http.HttpClientLibrary.csproj | 2 +-
2 files changed, 17 insertions(+), 13 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1b83185..2b5048a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,18 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
-## [1.4.1] - 2024-05-07
-
-## Changed
-
-- Use `SocketsHttpHandler` with `EnableMultipleHttp2Connections` as default HTTP message handler.
-
-## [1.4.0]
-
-## Added
-
-- KiotaClientFactory `create()` overload that accepts a list of handlers.
-
+### Added
+
+- `GetDefaultHandlerTypes` added to `KiotaClientFactory` if you're creating your own `HttpClient` and still want to use the default handlers.
+
+## [1.4.1] - 2024-05-07
+
+## Changed
+
+- Use `SocketsHttpHandler` with `EnableMultipleHttp2Connections` as default HTTP message handler.
+
+## [1.4.0]
+
+## Added
+
+- KiotaClientFactory `create()` overload that accepts a list of handlers.
+
## [1.3.12] - 2024-04-22
- UriReplacementHandler improvements to be added to middleware pipeline by default and respects options set in the HttpRequestMessage (https://github.com/microsoft/kiota-http-dotnet/issues/242)
diff --git a/src/Microsoft.Kiota.Http.HttpClientLibrary.csproj b/src/Microsoft.Kiota.Http.HttpClientLibrary.csproj
index e62ba44..8f30e5b 100644
--- a/src/Microsoft.Kiota.Http.HttpClientLibrary.csproj
+++ b/src/Microsoft.Kiota.Http.HttpClientLibrary.csproj
@@ -15,7 +15,7 @@
https://aka.ms/kiota/docs
true
true
- 1.4.1
+ 1.4.2
true