Skip to content

Commit

Permalink
Use HttpUtility#UrlPathEncode instead of HttpUtility#UrlEncode to pro…
Browse files Browse the repository at this point in the history
…perly encode spaces.
  • Loading branch information
joerghartmann committed Mar 28, 2024
1 parent 6305d77 commit 3f0fea5
Show file tree
Hide file tree
Showing 31 changed files with 145 additions and 145 deletions.
4 changes: 2 additions & 2 deletions Client/Com/Cumulocity/Client/Api/AlarmsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public AlarmsApi(HttpClient httpClient)
/// <inheritdoc />
public async Task<TAlarm?> GetAlarm<TAlarm>(string id, CancellationToken cToken = default) where TAlarm : Alarm
{
string resourcePath = $"/alarm/alarms/{HttpUtility.UrlEncode(id.GetStringValue())}";
string resourcePath = $"/alarm/alarms/{HttpUtility.UrlPathEncode(id.GetStringValue())}";
var uriBuilder = new UriBuilder(new Uri(_httpClient.BaseAddress ?? new Uri(resourcePath), resourcePath));
using var request = new HttpRequestMessage
{
Expand All @@ -202,7 +202,7 @@ public AlarmsApi(HttpClient httpClient)
jsonNode?.RemoveFromNode("source");
jsonNode?.RemoveFromNode("time");
jsonNode?.RemoveFromNode("type");
string resourcePath = $"/alarm/alarms/{HttpUtility.UrlEncode(id.GetStringValue())}";
string resourcePath = $"/alarm/alarms/{HttpUtility.UrlPathEncode(id.GetStringValue())}";
var uriBuilder = new UriBuilder(new Uri(_httpClient.BaseAddress ?? new Uri(resourcePath), resourcePath));
using var request = new HttpRequestMessage
{
Expand Down
8 changes: 4 additions & 4 deletions Client/Com/Cumulocity/Client/Api/ApplicationBinariesApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public ApplicationBinariesApi(HttpClient httpClient)
/// <inheritdoc />
public async Task<ApplicationBinaries?> GetApplicationAttachments(string id, CancellationToken cToken = default)
{
string resourcePath = $"/application/applications/{HttpUtility.UrlEncode(id.GetStringValue())}/binaries";
string resourcePath = $"/application/applications/{HttpUtility.UrlPathEncode(id.GetStringValue())}/binaries";
var uriBuilder = new UriBuilder(new Uri(_httpClient.BaseAddress ?? new Uri(resourcePath), resourcePath));
using var request = new HttpRequestMessage
{
Expand All @@ -54,7 +54,7 @@ public ApplicationBinariesApi(HttpClient httpClient)
/// <inheritdoc />
public async Task<Application?> UploadApplicationAttachment(byte[] file, string id, CancellationToken cToken = default)
{
string resourcePath = $"/application/applications/{HttpUtility.UrlEncode(id.GetStringValue())}/binaries";
string resourcePath = $"/application/applications/{HttpUtility.UrlPathEncode(id.GetStringValue())}/binaries";
var uriBuilder = new UriBuilder(new Uri(_httpClient.BaseAddress ?? new Uri(resourcePath), resourcePath));
var requestContent = new MultipartFormDataContent();
var fileContentFile = new ByteArrayContent(file);
Expand All @@ -77,7 +77,7 @@ public ApplicationBinariesApi(HttpClient httpClient)
/// <inheritdoc />
public async Task<string?> GetApplicationAttachment(string id, string binaryId, CancellationToken cToken = default)
{
string resourcePath = $"/application/applications/{HttpUtility.UrlEncode(id.GetStringValue())}/binaries/{HttpUtility.UrlEncode(binaryId.GetStringValue())}";
string resourcePath = $"/application/applications/{HttpUtility.UrlPathEncode(id.GetStringValue())}/binaries/{HttpUtility.UrlPathEncode(binaryId.GetStringValue())}";
var uriBuilder = new UriBuilder(new Uri(_httpClient.BaseAddress ?? new Uri(resourcePath), resourcePath));
using var request = new HttpRequestMessage
{
Expand All @@ -93,7 +93,7 @@ public ApplicationBinariesApi(HttpClient httpClient)
/// <inheritdoc />
public async Task<string?> DeleteApplicationAttachment(string id, string binaryId, CancellationToken cToken = default)
{
string resourcePath = $"/application/applications/{HttpUtility.UrlEncode(id.GetStringValue())}/binaries/{HttpUtility.UrlEncode(binaryId.GetStringValue())}";
string resourcePath = $"/application/applications/{HttpUtility.UrlPathEncode(id.GetStringValue())}/binaries/{HttpUtility.UrlPathEncode(binaryId.GetStringValue())}";
var uriBuilder = new UriBuilder(new Uri(_httpClient.BaseAddress ?? new Uri(resourcePath), resourcePath));
using var request = new HttpRequestMessage
{
Expand Down
10 changes: 5 additions & 5 deletions Client/Com/Cumulocity/Client/Api/ApplicationVersionsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public ApplicationVersionsApi(HttpClient httpClient)
/// <inheritdoc />
public async Task<ApplicationVersion?> GetApplicationVersion(string id, string? version = null, string? tag = null, CancellationToken cToken = default)
{
string resourcePath = $"/application/applications/{HttpUtility.UrlEncode(id.GetStringValue())}/versions?version=1.0";
string resourcePath = $"/application/applications/{HttpUtility.UrlPathEncode(id.GetStringValue())}/versions?version=1.0";
var uriBuilder = new UriBuilder(new Uri(_httpClient.BaseAddress ?? new Uri(resourcePath), resourcePath));
var queryString = HttpUtility.ParseQueryString(uriBuilder.Query);
queryString.TryAdd("version", version);
Expand All @@ -58,7 +58,7 @@ public ApplicationVersionsApi(HttpClient httpClient)
/// <inheritdoc />
public async Task<ApplicationVersionCollection?> GetApplicationVersions(string id, CancellationToken cToken = default)
{
string resourcePath = $"/application/applications/{HttpUtility.UrlEncode(id.GetStringValue())}/versions";
string resourcePath = $"/application/applications/{HttpUtility.UrlPathEncode(id.GetStringValue())}/versions";
var uriBuilder = new UriBuilder(new Uri(_httpClient.BaseAddress ?? new Uri(resourcePath), resourcePath));
using var request = new HttpRequestMessage
{
Expand All @@ -75,7 +75,7 @@ public ApplicationVersionsApi(HttpClient httpClient)
/// <inheritdoc />
public async Task<ApplicationVersion?> CreateApplicationVersion(byte[] applicationBinary, string applicationVersion, string id, CancellationToken cToken = default)
{
string resourcePath = $"/application/applications/{HttpUtility.UrlEncode(id.GetStringValue())}/versions";
string resourcePath = $"/application/applications/{HttpUtility.UrlPathEncode(id.GetStringValue())}/versions";
var uriBuilder = new UriBuilder(new Uri(_httpClient.BaseAddress ?? new Uri(resourcePath), resourcePath));
var requestContent = new MultipartFormDataContent();
var fileContentApplicationBinary = new ByteArrayContent(applicationBinary);
Expand All @@ -101,7 +101,7 @@ public ApplicationVersionsApi(HttpClient httpClient)
/// <inheritdoc />
public async Task<string?> DeleteApplicationVersion(string id, string? version = null, string? tag = null, CancellationToken cToken = default)
{
string resourcePath = $"/application/applications/{HttpUtility.UrlEncode(id.GetStringValue())}/versions";
string resourcePath = $"/application/applications/{HttpUtility.UrlPathEncode(id.GetStringValue())}/versions";
var uriBuilder = new UriBuilder(new Uri(_httpClient.BaseAddress ?? new Uri(resourcePath), resourcePath));
var queryString = HttpUtility.ParseQueryString(uriBuilder.Query);
queryString.TryAdd("version", version);
Expand All @@ -122,7 +122,7 @@ public ApplicationVersionsApi(HttpClient httpClient)
public async Task<ApplicationVersion?> UpdateApplicationVersion(ApplicationVersionTag body, string id, string version, CancellationToken cToken = default)
{
var jsonNode = body.ToJsonNode<ApplicationVersionTag>();
string resourcePath = $"/application/applications/{HttpUtility.UrlEncode(id.GetStringValue())}/versions/{HttpUtility.UrlEncode(version.GetStringValue())}";
string resourcePath = $"/application/applications/{HttpUtility.UrlPathEncode(id.GetStringValue())}/versions/{HttpUtility.UrlPathEncode(version.GetStringValue())}";
var uriBuilder = new UriBuilder(new Uri(_httpClient.BaseAddress ?? new Uri(resourcePath), resourcePath));
using var request = new HttpRequestMessage
{
Expand Down
16 changes: 8 additions & 8 deletions Client/Com/Cumulocity/Client/Api/ApplicationsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public ApplicationsApi(HttpClient httpClient)
/// <inheritdoc />
public async Task<Application?> GetApplication(string id, CancellationToken cToken = default)
{
string resourcePath = $"/application/applications/{HttpUtility.UrlEncode(id.GetStringValue())}";
string resourcePath = $"/application/applications/{HttpUtility.UrlPathEncode(id.GetStringValue())}";
var uriBuilder = new UriBuilder(new Uri(_httpClient.BaseAddress ?? new Uri(resourcePath), resourcePath));
using var request = new HttpRequestMessage
{
Expand All @@ -122,7 +122,7 @@ public ApplicationsApi(HttpClient httpClient)
jsonNode?.RemoveFromNode("id");
jsonNode?.RemoveFromNode("type");
jsonNode?.RemoveFromNode("resourcesUrl");
string resourcePath = $"/application/applications/{HttpUtility.UrlEncode(id.GetStringValue())}";
string resourcePath = $"/application/applications/{HttpUtility.UrlPathEncode(id.GetStringValue())}";
var uriBuilder = new UriBuilder(new Uri(_httpClient.BaseAddress ?? new Uri(resourcePath), resourcePath));
using var request = new HttpRequestMessage
{
Expand All @@ -142,7 +142,7 @@ public ApplicationsApi(HttpClient httpClient)
/// <inheritdoc />
public async Task<string?> DeleteApplication(string id, bool? force = null, string? xCumulocityProcessingMode = null, CancellationToken cToken = default)
{
string resourcePath = $"/application/applications/{HttpUtility.UrlEncode(id.GetStringValue())}";
string resourcePath = $"/application/applications/{HttpUtility.UrlPathEncode(id.GetStringValue())}";
var uriBuilder = new UriBuilder(new Uri(_httpClient.BaseAddress ?? new Uri(resourcePath), resourcePath));
var queryString = HttpUtility.ParseQueryString(uriBuilder.Query);
queryString.TryAdd("force", force);
Expand All @@ -162,7 +162,7 @@ public ApplicationsApi(HttpClient httpClient)
/// <inheritdoc />
public async Task<Application?> CopyApplication(string id, string? version = null, string? tag = null, string? xCumulocityProcessingMode = null, CancellationToken cToken = default)
{
string resourcePath = $"/application/applications/{HttpUtility.UrlEncode(id.GetStringValue())}/clone";
string resourcePath = $"/application/applications/{HttpUtility.UrlPathEncode(id.GetStringValue())}/clone";
var uriBuilder = new UriBuilder(new Uri(_httpClient.BaseAddress ?? new Uri(resourcePath), resourcePath));
var queryString = HttpUtility.ParseQueryString(uriBuilder.Query);
queryString.TryAdd("version", version);
Expand All @@ -184,7 +184,7 @@ public ApplicationsApi(HttpClient httpClient)
/// <inheritdoc />
public async Task<ApplicationCollection?> GetApplicationsByName(string name, CancellationToken cToken = default)
{
string resourcePath = $"/application/applicationsByName/{HttpUtility.UrlEncode(name.GetStringValue())}";
string resourcePath = $"/application/applicationsByName/{HttpUtility.UrlPathEncode(name.GetStringValue())}";
var uriBuilder = new UriBuilder(new Uri(_httpClient.BaseAddress ?? new Uri(resourcePath), resourcePath));
using var request = new HttpRequestMessage
{
Expand All @@ -201,7 +201,7 @@ public ApplicationsApi(HttpClient httpClient)
/// <inheritdoc />
public async Task<ApplicationCollection?> GetApplicationsByTenant(string tenantId, CancellationToken cToken = default)
{
string resourcePath = $"/application/applicationsByTenant/{HttpUtility.UrlEncode(tenantId.GetStringValue())}";
string resourcePath = $"/application/applicationsByTenant/{HttpUtility.UrlPathEncode(tenantId.GetStringValue())}";
var uriBuilder = new UriBuilder(new Uri(_httpClient.BaseAddress ?? new Uri(resourcePath), resourcePath));
using var request = new HttpRequestMessage
{
Expand All @@ -218,7 +218,7 @@ public ApplicationsApi(HttpClient httpClient)
/// <inheritdoc />
public async Task<ApplicationCollection?> GetApplicationsByOwner(string tenantId, int? currentPage = null, int? pageSize = null, bool? withTotalElements = null, bool? withTotalPages = null, CancellationToken cToken = default)
{
string resourcePath = $"/application/applicationsByOwner/{HttpUtility.UrlEncode(tenantId.GetStringValue())}";
string resourcePath = $"/application/applicationsByOwner/{HttpUtility.UrlPathEncode(tenantId.GetStringValue())}";
var uriBuilder = new UriBuilder(new Uri(_httpClient.BaseAddress ?? new Uri(resourcePath), resourcePath));
var queryString = HttpUtility.ParseQueryString(uriBuilder.Query);
queryString.TryAdd("currentPage", currentPage);
Expand All @@ -241,7 +241,7 @@ public ApplicationsApi(HttpClient httpClient)
/// <inheritdoc />
public async Task<ApplicationCollection?> GetApplicationsByUser(string username, int? currentPage = null, int? pageSize = null, bool? withTotalElements = null, bool? withTotalPages = null, CancellationToken cToken = default)
{
string resourcePath = $"/application/applicationsByUser/{HttpUtility.UrlEncode(username.GetStringValue())}";
string resourcePath = $"/application/applicationsByUser/{HttpUtility.UrlPathEncode(username.GetStringValue())}";
var uriBuilder = new UriBuilder(new Uri(_httpClient.BaseAddress ?? new Uri(resourcePath), resourcePath));
var queryString = HttpUtility.ParseQueryString(uriBuilder.Query);
queryString.TryAdd("currentPage", currentPage);
Expand Down
10 changes: 5 additions & 5 deletions Client/Com/Cumulocity/Client/Api/AttachmentsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public AttachmentsApi(HttpClient httpClient)
/// <inheritdoc />
public async Task<string?> GetEventAttachment(string id, CancellationToken cToken = default)
{
string resourcePath = $"/event/events/{HttpUtility.UrlEncode(id.GetStringValue())}/binaries";
string resourcePath = $"/event/events/{HttpUtility.UrlPathEncode(id.GetStringValue())}/binaries";
var uriBuilder = new UriBuilder(new Uri(_httpClient.BaseAddress ?? new Uri(resourcePath), resourcePath));
using var request = new HttpRequestMessage
{
Expand All @@ -53,7 +53,7 @@ public AttachmentsApi(HttpClient httpClient)
/// <inheritdoc />
public async Task<EventBinary?> ReplaceEventAttachment(byte[] body, string id, CancellationToken cToken = default)
{
string resourcePath = $"/event/events/{HttpUtility.UrlEncode(id.GetStringValue())}/binaries";
string resourcePath = $"/event/events/{HttpUtility.UrlPathEncode(id.GetStringValue())}/binaries";
var uriBuilder = new UriBuilder(new Uri(_httpClient.BaseAddress ?? new Uri(resourcePath), resourcePath));
using var request = new HttpRequestMessage
{
Expand All @@ -72,7 +72,7 @@ public AttachmentsApi(HttpClient httpClient)
/// <inheritdoc />
public async Task<EventBinary?> UploadEventAttachment(byte[] body, string id, CancellationToken cToken = default)
{
string resourcePath = $"/event/events/{HttpUtility.UrlEncode(id.GetStringValue())}/binaries";
string resourcePath = $"/event/events/{HttpUtility.UrlPathEncode(id.GetStringValue())}/binaries";
var uriBuilder = new UriBuilder(new Uri(_httpClient.BaseAddress ?? new Uri(resourcePath), resourcePath));
using var request = new HttpRequestMessage
{
Expand All @@ -91,7 +91,7 @@ public AttachmentsApi(HttpClient httpClient)
/// <inheritdoc />
public async Task<EventBinary?> UploadEventAttachment(BinaryInfo pObject, byte[] file, string id, CancellationToken cToken = default)
{
string resourcePath = $"/event/events/{HttpUtility.UrlEncode(id.GetStringValue())}/binaries";
string resourcePath = $"/event/events/{HttpUtility.UrlPathEncode(id.GetStringValue())}/binaries";
var uriBuilder = new UriBuilder(new Uri(_httpClient.BaseAddress ?? new Uri(resourcePath), resourcePath));
var requestContent = new MultipartFormDataContent();
var fileContentObject = new StringContent(JsonSerializerWrapper.Serialize(pObject));
Expand All @@ -117,7 +117,7 @@ public AttachmentsApi(HttpClient httpClient)
/// <inheritdoc />
public async Task<string?> DeleteEventAttachment(string id, CancellationToken cToken = default)
{
string resourcePath = $"/event/events/{HttpUtility.UrlEncode(id.GetStringValue())}/binaries";
string resourcePath = $"/event/events/{HttpUtility.UrlPathEncode(id.GetStringValue())}/binaries";
var uriBuilder = new UriBuilder(new Uri(_httpClient.BaseAddress ?? new Uri(resourcePath), resourcePath));
using var request = new HttpRequestMessage
{
Expand Down
2 changes: 1 addition & 1 deletion Client/Com/Cumulocity/Client/Api/AuditsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public AuditsApi(HttpClient httpClient)
/// <inheritdoc />
public async Task<TAuditRecord?> GetAuditRecord<TAuditRecord>(string id, CancellationToken cToken = default) where TAuditRecord : AuditRecord
{
string resourcePath = $"/audit/auditRecords/{HttpUtility.UrlEncode(id.GetStringValue())}";
string resourcePath = $"/audit/auditRecords/{HttpUtility.UrlPathEncode(id.GetStringValue())}";
var uriBuilder = new UriBuilder(new Uri(_httpClient.BaseAddress ?? new Uri(resourcePath), resourcePath));
using var request = new HttpRequestMessage
{
Expand Down
6 changes: 3 additions & 3 deletions Client/Com/Cumulocity/Client/Api/BinariesApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public BinariesApi(HttpClient httpClient)
/// <inheritdoc />
public async Task<string?> GetBinary(string id, CancellationToken cToken = default)
{
string resourcePath = $"/inventory/binaries/{HttpUtility.UrlEncode(id.GetStringValue())}";
string resourcePath = $"/inventory/binaries/{HttpUtility.UrlPathEncode(id.GetStringValue())}";
var uriBuilder = new UriBuilder(new Uri(_httpClient.BaseAddress ?? new Uri(resourcePath), resourcePath));
using var request = new HttpRequestMessage
{
Expand All @@ -109,7 +109,7 @@ public BinariesApi(HttpClient httpClient)
/// <inheritdoc />
public async Task<Binary?> ReplaceBinary(byte[] body, string id, CancellationToken cToken = default)
{
string resourcePath = $"/inventory/binaries/{HttpUtility.UrlEncode(id.GetStringValue())}";
string resourcePath = $"/inventory/binaries/{HttpUtility.UrlPathEncode(id.GetStringValue())}";
var uriBuilder = new UriBuilder(new Uri(_httpClient.BaseAddress ?? new Uri(resourcePath), resourcePath));
using var request = new HttpRequestMessage
{
Expand All @@ -128,7 +128,7 @@ public BinariesApi(HttpClient httpClient)
/// <inheritdoc />
public async Task<string?> RemoveBinary(string id, CancellationToken cToken = default)
{
string resourcePath = $"/inventory/binaries/{HttpUtility.UrlEncode(id.GetStringValue())}";
string resourcePath = $"/inventory/binaries/{HttpUtility.UrlPathEncode(id.GetStringValue())}";
var uriBuilder = new UriBuilder(new Uri(_httpClient.BaseAddress ?? new Uri(resourcePath), resourcePath));
using var request = new HttpRequestMessage
{
Expand Down
2 changes: 1 addition & 1 deletion Client/Com/Cumulocity/Client/Api/BootstrapUserApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public BootstrapUserApi(HttpClient httpClient)
/// <inheritdoc />
public async Task<BootstrapUser?> GetBootstrapUser(string id, CancellationToken cToken = default)
{
string resourcePath = $"/application/applications/{HttpUtility.UrlEncode(id.GetStringValue())}/bootstrapUser";
string resourcePath = $"/application/applications/{HttpUtility.UrlPathEncode(id.GetStringValue())}/bootstrapUser";
var uriBuilder = new UriBuilder(new Uri(_httpClient.BaseAddress ?? new Uri(resourcePath), resourcePath));
using var request = new HttpRequestMessage
{
Expand Down
6 changes: 3 additions & 3 deletions Client/Com/Cumulocity/Client/Api/BulkOperationsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public BulkOperationsApi(HttpClient httpClient)
/// <inheritdoc />
public async Task<BulkOperation?> GetBulkOperation(string id, CancellationToken cToken = default)
{
string resourcePath = $"/devicecontrol/bulkoperations/{HttpUtility.UrlEncode(id.GetStringValue())}";
string resourcePath = $"/devicecontrol/bulkoperations/{HttpUtility.UrlPathEncode(id.GetStringValue())}";
var uriBuilder = new UriBuilder(new Uri(_httpClient.BaseAddress ?? new Uri(resourcePath), resourcePath));
using var request = new HttpRequestMessage
{
Expand All @@ -122,7 +122,7 @@ public BulkOperationsApi(HttpClient httpClient)
jsonNode?.RemoveFromNode("progress");
jsonNode?.RemoveFromNode("id");
jsonNode?.RemoveFromNode("status");
string resourcePath = $"/devicecontrol/bulkoperations/{HttpUtility.UrlEncode(id.GetStringValue())}";
string resourcePath = $"/devicecontrol/bulkoperations/{HttpUtility.UrlPathEncode(id.GetStringValue())}";
var uriBuilder = new UriBuilder(new Uri(_httpClient.BaseAddress ?? new Uri(resourcePath), resourcePath));
using var request = new HttpRequestMessage
{
Expand All @@ -142,7 +142,7 @@ public BulkOperationsApi(HttpClient httpClient)
/// <inheritdoc />
public async Task<string?> DeleteBulkOperation(string id, string? xCumulocityProcessingMode = null, CancellationToken cToken = default)
{
string resourcePath = $"/devicecontrol/bulkoperations/{HttpUtility.UrlEncode(id.GetStringValue())}";
string resourcePath = $"/devicecontrol/bulkoperations/{HttpUtility.UrlPathEncode(id.GetStringValue())}";
var uriBuilder = new UriBuilder(new Uri(_httpClient.BaseAddress ?? new Uri(resourcePath), resourcePath));
using var request = new HttpRequestMessage
{
Expand Down
Loading

0 comments on commit 3f0fea5

Please sign in to comment.