-
Notifications
You must be signed in to change notification settings - Fork 335
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added overload to support SDK supplying query string on invoked URL (#…
…1310) * Refactored extensions and their tests into separate directories Signed-off-by: Whit Waldo <[email protected]> * Added overload to method invocation to allow query string parameters to be passed in via the SDK instead of being uncermoniously added to the end of the produced HttpRequestMessage URI Signed-off-by: Whit Waldo <[email protected]> * Added unit tests to support implementation Signed-off-by: Whit Waldo <[email protected]> * Marking HttpExtensions as internal to prevent external usage and updating to work against Uri instead of HttpRequestMessage. Signed-off-by: Whit Waldo <[email protected]> * Updated unit tests to match new extension purpose Signed-off-by: Whit Waldo <[email protected]> * Resolved an ambiguous method invocation wherein it was taking the query string and passing it as the payload for a request. Removed the offending method and reworked the remaining configurations so there's no API impact. Signed-off-by: Whit Waldo <[email protected]> --------- Signed-off-by: Whit Waldo <[email protected]>
- Loading branch information
Showing
7 changed files
with
238 additions
and
13 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
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,51 @@ | ||
// ------------------------------------------------------------------------ | ||
// Copyright 2024 The Dapr Authors | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// ------------------------------------------------------------------------ | ||
|
||
#nullable enable | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Dapr.Client | ||
{ | ||
/// <summary> | ||
/// Provides extensions specific to HTTP types. | ||
/// </summary> | ||
internal static class HttpExtensions | ||
{ | ||
/// <summary> | ||
/// Appends key/value pairs to the query string on an HttpRequestMessage. | ||
/// </summary> | ||
/// <param name="uri">The uri to append the query string parameters to.</param> | ||
/// <param name="queryStringParameters">The key/value pairs to populate the query string with.</param> | ||
public static Uri AddQueryParameters(this Uri? uri, | ||
IReadOnlyCollection<KeyValuePair<string, string>>? queryStringParameters) | ||
{ | ||
ArgumentNullException.ThrowIfNull(uri, nameof(uri)); | ||
if (queryStringParameters is null) | ||
return uri; | ||
|
||
var uriBuilder = new UriBuilder(uri); | ||
var qsBuilder = new StringBuilder(uriBuilder.Query); | ||
foreach (var kvParam in queryStringParameters) | ||
{ | ||
if (qsBuilder.Length > 0) | ||
qsBuilder.Append('&'); | ||
qsBuilder.Append($"{Uri.EscapeDataString(kvParam.Key)}={Uri.EscapeDataString(kvParam.Value)}"); | ||
} | ||
|
||
uriBuilder.Query = qsBuilder.ToString(); | ||
return uriBuilder.Uri; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.