Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Typesense/Setup/Node.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Linq;

namespace Typesense.Setup;
/// <summary>
Expand Down Expand Up @@ -60,7 +61,7 @@ public Node(string host, string port, string protocol = "http")
/// <param name="host">Hostname for the Typesense service.</param>
/// <param name="port">Port for the typesense service.</param>
/// <param name="protocol">Protocol for the Typesense service - defaults to http.</param>
/// <param name="additionalPath">additionalPath for the Typesense service - defaults to empty string.</param>
/// <param name="additionalPath">additionalPath (without trailing or leading '/') for the Typesense service - defaults to empty string.</param>
/// <exception cref="ArgumentException"></exception>
public Node(string host, string port, string protocol = "http", string additionalPath = "")
{
Expand All @@ -82,6 +83,6 @@ public Node(string host, string port, string protocol = "http", string additiona
Host = host;
Port = port;
Protocol = protocol;
AdditionalPath = additionalPath;
AdditionalPath = additionalPath + "/";
}
}
19 changes: 9 additions & 10 deletions src/Typesense/TypesenseClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public TypesenseClient(IOptions<Config> config, HttpClient httpClient)

_jsonOptionsCamelCaseIgnoreWritingNull = new JsonSerializerOptions(config.Value.JsonSerializerOptions)
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
};
}
Expand Down Expand Up @@ -122,7 +121,7 @@ private Task<T> PostDocuments<T>(string collection, HttpContent httpContent, boo
var path = upsert
? $"/collections/{collection}/documents?action=upsert"
: $"/collections/{collection}/documents";
return Post<T>(path, httpContent, _jsonNameCaseInsensitiveTrue);
return Post<T>(path.TrimStart('/'), httpContent, _jsonNameCaseInsensitiveTrue);
}

private Task<TResult> SearchInternal<TResult>(string collection,
Expand Down Expand Up @@ -156,7 +155,7 @@ public async Task<List<MultiSearchResult<T>>> MultiSearch<T>(ICollection<MultiSe
? "/multi_search"
: $"/multi_search?limit_multi_searches={limitMultiSearches}";

var response = await Post<JsonElement>(path, json, jsonSerializerOptions: null, ctk).ConfigureAwait(false);
var response = await Post<JsonElement>(path.TrimStart('/'), json, jsonSerializerOptions: null, ctk).ConfigureAwait(false);

return response.TryGetProperty("results", out var results)
? results.EnumerateArray().Select(HandleDeserializeMultiSearch<T>).ToList()
Expand Down Expand Up @@ -498,7 +497,7 @@ private async Task<List<ImportResponse>> ImportDocuments(
path += $"&return_id={returnId}";
}

using var response = await _httpClient.PostAsync(path, documents).ConfigureAwait(false);
using var response = await _httpClient.PostAsync(path.TrimStart('/'), documents).ConfigureAwait(false);
if (!response.IsSuccessStatusCode)
await GetException(response, CancellationToken.None).ConfigureAwait(false);

Expand Down Expand Up @@ -799,7 +798,7 @@ private static string CreateUrlParameters<T>(T queryParameters)

private async Task<T> Get<T>(string path, JsonSerializerOptions? jsonSerializerOptions, CancellationToken ctk = default)
{
using var response = await _httpClient.GetAsync(path, HttpCompletionOption.ResponseHeadersRead, ctk).ConfigureAwait(false);
using var response = await _httpClient.GetAsync(path.TrimStart('/'), HttpCompletionOption.ResponseHeadersRead, ctk).ConfigureAwait(false);
if (!response.IsSuccessStatusCode)
await GetException(response, ctk).ConfigureAwait(false);

Expand All @@ -808,7 +807,7 @@ private async Task<T> Get<T>(string path, JsonSerializerOptions? jsonSerializerO

private async IAsyncEnumerable<string> GetLines(string path, [EnumeratorCancellation] CancellationToken ctk = default)
{
using var response = await _httpClient.GetAsync(path, HttpCompletionOption.ResponseHeadersRead, ctk).ConfigureAwait(false);
using var response = await _httpClient.GetAsync(path.TrimStart('/'), HttpCompletionOption.ResponseHeadersRead, ctk).ConfigureAwait(false);
if (!response.IsSuccessStatusCode)
await GetException(response, ctk).ConfigureAwait(false);

Expand All @@ -832,7 +831,7 @@ private static async IAsyncEnumerable<string> GetLines(HttpResponseMessage respo

private async Task<T> Delete<T>(string path, JsonSerializerOptions? jsonSerializerOptions, CancellationToken ctk = default)
{
using var response = await _httpClient.DeleteAsync(path, ctk).ConfigureAwait(false);
using var response = await _httpClient.DeleteAsync(path.TrimStart('/'), ctk).ConfigureAwait(false);
if (!response.IsSuccessStatusCode)
await GetException(response, ctk).ConfigureAwait(false);

Expand All @@ -841,7 +840,7 @@ private async Task<T> Delete<T>(string path, JsonSerializerOptions? jsonSerializ

private async Task<T> Post<T>(string path, HttpContent? httpContent, JsonSerializerOptions? jsonSerializerOptions, CancellationToken ctk = default)
{
using var response = await _httpClient.PostAsync(path, httpContent, ctk).ConfigureAwait(false);
using var response = await _httpClient.PostAsync(path.TrimStart('/'), httpContent, ctk).ConfigureAwait(false);
if (!response.IsSuccessStatusCode)
await GetException(response, ctk).ConfigureAwait(false);

Expand All @@ -850,7 +849,7 @@ private async Task<T> Post<T>(string path, HttpContent? httpContent, JsonSeriali

private async Task<T> Patch<T>(string path, HttpContent? httpContent, JsonSerializerOptions? jsonSerializerOptions, CancellationToken ctk = default)
{
using var response = await _httpClient.PatchAsync(path, httpContent, ctk).ConfigureAwait(false);
using var response = await _httpClient.PatchAsync(path.TrimStart('/'), httpContent, ctk).ConfigureAwait(false);
if (!response.IsSuccessStatusCode)
await GetException(response, ctk).ConfigureAwait(false);

Expand All @@ -859,7 +858,7 @@ private async Task<T> Patch<T>(string path, HttpContent? httpContent, JsonSerial

private async Task<T> Put<T>(string path, HttpContent? httpContent, JsonSerializerOptions? jsonSerializerOptions, CancellationToken ctk = default)
{
using var response = await _httpClient.PutAsync(path, httpContent, ctk).ConfigureAwait(false);
using var response = await _httpClient.PutAsync(path.TrimStart('/'), httpContent, ctk).ConfigureAwait(false);
if (!response.IsSuccessStatusCode)
await GetException(response, ctk).ConfigureAwait(false);

Expand Down