-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #330 from microsoft/feature/middlewares
adds support for http middlewares
- Loading branch information
Showing
38 changed files
with
575 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Microsoft.Kiota.Abstractions { | ||
/// <summary> | ||
/// Represents a middleware option. | ||
/// </summary> | ||
public interface IMiddlewareOption { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
abstractions/java/lib/src/main/java/com/microsoft/kiota/MiddlewareOption.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.microsoft.kiota; | ||
|
||
/** Represents a middleware option. */ | ||
public interface MiddlewareOption { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** Represents a middleware option. */ | ||
export interface MiddlewareOption { | ||
/** Gets the option key for when adding it to a request. Must be unique. */ | ||
getKey(): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System.Linq; | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using Microsoft.Kiota.Abstractions; | ||
|
||
namespace Microsoft.Kiota.Http.HttpClient { | ||
/// <summary> | ||
/// This class is used to build the HttpClient instance used by the core service. | ||
/// </summary> | ||
public static class HttpClientBuilder { | ||
/// <summary> | ||
/// Initializes the <see cref="HttpClient"/> with the default configuration and middlewares including a authentention middleware using the <see cref="IAuthenticationProvider"/> if provided. | ||
/// </summary> | ||
/// <param name="authenticationProvider">The <see cref="IAuthenticationProvider"/> to use for authentention.</param> | ||
/// <returns>The <see cref="HttpClient"/> with the default middlewares.</returns> | ||
public static System.Net.Http.HttpClient Create(IAuthenticationProvider authenticationProvider = default) { | ||
var defaultHandlers = CreateDefaultHandlers(authenticationProvider); | ||
var handler = ChainHandlersCollectionAndGetFirstLink(defaultHandlers.ToArray()); | ||
return handler != null ? new System.Net.Http.HttpClient(handler) : new System.Net.Http.HttpClient(); //TODO configure the default client options | ||
} | ||
/// <summary> | ||
/// Creates a default set of middleware to be used by the <see cref="HttpClient"/>. | ||
/// </summary> | ||
/// <param name="authenticationProvider">The <see cref="IAuthenticationProvider"/> to authenticate requests.</param> | ||
/// <returns>A list of the default handlers used by the client.</returns> | ||
public static IList<DelegatingHandler> CreateDefaultHandlers(IAuthenticationProvider authenticationProvider = default) | ||
{ | ||
return new List<DelegatingHandler>(); //TODO add the default middlewares when they are ready | ||
} | ||
/// <summary> | ||
/// Creates a <see cref="DelegatingHandler"/> to use for the <see cref="HttpClient" /> from the provided <see cref="DelegatingHandler"/> instances. Order matters. | ||
/// </summary> | ||
/// <param name="handlers">The <see cref="DelegatingHandler"/> instances to create the <see cref="DelegatingHandler"/> from.</param> | ||
/// <returns>The created <see cref="DelegatingHandler"/>.</returns> | ||
public static DelegatingHandler ChainHandlersCollectionAndGetFirstLink(params DelegatingHandler[] handlers) { | ||
if(handlers == null || !handlers.Any()) return default; | ||
var handlersCount = handlers.Count(); | ||
for(var i = 0; i < handlersCount; i++) { | ||
var handler = handlers[i]; | ||
var previousItemIndex = i - 1; | ||
if(previousItemIndex >= 0) { | ||
var previousHandler = handlers[previousItemIndex]; | ||
previousHandler.InnerHandler = handler; | ||
} | ||
} | ||
return handlers.First(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
http/java/okhttp/lib/src/main/java/com/microsoft/kiota/http/OkHttpClientBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.microsoft.kiota.http; | ||
|
||
import com.microsoft.kiota.AuthenticationProvider; | ||
|
||
import okhttp3.OkHttpClient; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
/** This class is used to build the HttpClient instance used by the core service. */ | ||
public class OkHttpClientBuilder { | ||
private OkHttpClientBuilder() { } | ||
/** | ||
* Creates an OkHttpClient Builder with the default configuration and middlewares including a authentention middleware using the {@link AuthenticationProvider} if provided. | ||
* @param authenticationProvider the authentication provider used to authenticate the requests. | ||
* @return an OkHttpClient Builder instance. | ||
*/ | ||
public static OkHttpClient.Builder Create(@Nullable final AuthenticationProvider authenticationProvider) { | ||
return new OkHttpClient.Builder(); //TODO configure the default client options. | ||
//TODO add the default middlewares when they are ready | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.