-
Notifications
You must be signed in to change notification settings - Fork 345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added overload to support SDK supplying query string on invoked URL #1310
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3c537d8
Refactored extensions and their tests into separate directories
WhitWaldo 15e44a2
Added overload to method invocation to allow query string parameters …
WhitWaldo ad9fb14
Added unit tests to support implementation
WhitWaldo fbbccb3
Marking HttpExtensions as internal to prevent external usage and upda…
WhitWaldo 7431945
Updated unit tests to match new extension purpose
WhitWaldo bf8be73
Merge branch 'master' into svc-invocation-query
WhitWaldo 1cb6240
Merge branch 'dapr:master' into svc-invocation-query
WhitWaldo 1256a33
Resolved an ambiguous method invocation wherein it was taking the que…
WhitWaldo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious why not NameValueCollection?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fundamentally, I was looking to ensure that a read-only collection is passed. Conceptually, they wind up operationally working the same way. I don't see why an overload couldn't be added for a
NameValueCollection
as well.