Remove Microsoft.AspNetCore.WebUtilities dependency (#419)
* Remove Microsoft.AspNetCore.WebUtilities dependency * Fix more query-string handling * Add unit test * Merge with master
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using k8s.Models;
|
||||
using Microsoft.AspNetCore.WebUtilities;
|
||||
using Microsoft.Rest;
|
||||
using Microsoft.Rest.Serialization;
|
||||
using System;
|
||||
@@ -14,6 +13,8 @@ using System.Net.Security;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Text;
|
||||
using System.Globalization;
|
||||
|
||||
namespace k8s
|
||||
{
|
||||
@@ -102,27 +103,23 @@ namespace k8s
|
||||
|
||||
uriBuilder.Path += $"api/v1/namespaces/{@namespace}/pods/{name}/exec";
|
||||
|
||||
var query = string.Empty;
|
||||
var query = new StringBuilder();
|
||||
|
||||
foreach (var c in command)
|
||||
{
|
||||
query = QueryHelpers.AddQueryString(query, "command", c);
|
||||
Utilities.AddQueryParameter(query, "command", c);
|
||||
}
|
||||
|
||||
if (container != null)
|
||||
if (!string.IsNullOrEmpty(container))
|
||||
{
|
||||
query = QueryHelpers.AddQueryString(query, "container", Uri.EscapeDataString(container));
|
||||
Utilities.AddQueryParameter(query, "container", container);
|
||||
}
|
||||
|
||||
query = QueryHelpers.AddQueryString(query, new Dictionary<string, string>
|
||||
{
|
||||
{"stderr", stderr ? "1" : "0"},
|
||||
{"stdin", stdin ? "1" : "0"},
|
||||
{"stdout", stdout ? "1" : "0"},
|
||||
{"tty", tty ? "1" : "0"}
|
||||
}).TrimStart('?');
|
||||
|
||||
uriBuilder.Query = query;
|
||||
query.Append("&stderr=").Append(stderr ? '1' : '0'); // the query string is guaranteed not to be empty here because it has a 'command' param
|
||||
query.Append("&stdin=").Append(stdin ? '1' : '0');
|
||||
query.Append("&stdout=").Append(stdout ? '1' : '0');
|
||||
query.Append("&tty=").Append(tty ? '1' : '0');
|
||||
uriBuilder.Query = query.ToString(1, query.Length-1); // UriBuilder.Query doesn't like leading '?' chars, so trim it
|
||||
|
||||
return this.StreamConnectAsync(uriBuilder.Uri, _invocationId, webSocketSubProtol, customHeaders, cancellationToken);
|
||||
}
|
||||
@@ -171,14 +168,13 @@ namespace k8s
|
||||
|
||||
uriBuilder.Path += $"api/v1/namespaces/{@namespace}/pods/{name}/portforward";
|
||||
|
||||
var q = "";
|
||||
var q = new StringBuilder();
|
||||
foreach (var port in ports)
|
||||
{
|
||||
q = QueryHelpers.AddQueryString(q, "ports", $"{port}");
|
||||
if (q.Length != 0) q.Append('&');
|
||||
q.Append("ports=").Append(port.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
uriBuilder.Query = q.TrimStart('?');
|
||||
|
||||
|
||||
uriBuilder.Query = q.ToString();
|
||||
|
||||
return StreamConnectAsync(uriBuilder.Uri, _invocationId, webSocketSubProtocol, customHeaders, cancellationToken);
|
||||
}
|
||||
@@ -226,14 +222,13 @@ namespace k8s
|
||||
|
||||
uriBuilder.Path += $"api/v1/namespaces/{@namespace}/pods/{name}/attach";
|
||||
|
||||
uriBuilder.Query = QueryHelpers.AddQueryString(string.Empty, new Dictionary<string, string>
|
||||
{
|
||||
{ "container", container},
|
||||
{ "stderr", stderr ? "1": "0"},
|
||||
{ "stdin", stdin ? "1": "0"},
|
||||
{ "stdout", stdout ? "1": "0"},
|
||||
{ "tty", tty ? "1": "0"}
|
||||
}).TrimStart('?');
|
||||
var query = new StringBuilder();
|
||||
query.Append("?stderr=").Append(stderr ? '1' : '0');
|
||||
query.Append("&stdin=").Append(stdin ? '1' : '0');
|
||||
query.Append("&stdout=").Append(stdout ? '1' : '0');
|
||||
query.Append("&tty=").Append(tty ? '1' : '0');
|
||||
Utilities.AddQueryParameter(query, "container", container);
|
||||
uriBuilder.Query = query.ToString(1, query.Length-1); // UriBuilder.Query doesn't like leading '?' chars, so trim it
|
||||
|
||||
return StreamConnectAsync(uriBuilder.Uri, _invocationId, webSocketSubProtol, customHeaders, cancellationToken);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user