Describe the bug
In my company, we use a reverse-proxy to access external API like the DeepL API.
So our intern URL to access the Deepl API is 'https://external-api.company.com/deepl/', next the reverse proxy forwards the query to 'https://api.deepl.com/'.
To Reproduce
I use 'DeepLClientOptions.ServerUrl' to specify our custom url :
var options = new DeepLClientOptions { ServerUrl = "https://external-api.company.com/deepl/" };
var authKey = "***";
var client = new DeepLClient(authKey, options);
var translation = await client.TranslateTextAsync(
"Hello, world!",
LanguageCode.English,
LanguageCode.French
);
But the http request url is 'https://external-api.company.com/v2/translate'.
Expected behavior
I expect the http request url to be 'https://external-api.company.com/deepl/v2/translate'
Additional context
The class Uri follows the RFC 3986 - Uniform Resource Identifier (URI): Generic Syntax, so when a relative uri starts by /, then the relative path is considered to a absolute path.
See RFC 3986 - Section 5.2.2 : Transform References for more details
In this example :
Combine("https://external-api.company.com/deepl/", "/v2/translate");
Combine("https://external-api.company.com/deepl/", "v2/translate");
void Combine(string serverUrl,string relativePath)
{
var serverUri = new Uri(serverUrl);
var uri = new Uri(serverUri, relativePath);
Console.WriteLine($"{serverUrl} + {relativePath}");
Console.WriteLine(uri);
Console.WriteLine();
}
Output :
https://external-api.company.com/deepl/ + /v2/translate
https://external-api.company.com/v2/translate
https://external-api.company.com/deepl/ + v2/translate
https://external-api.company.com/deepl/v2/translate
In the DeepL SDK, all relative uris starts by / likes in Translator.cs :
using var responseMessage = await _client
.ApiPostAsync("/v2/translate", cancellationToken, bodyParams.Concat(textParams)).ConfigureAwait(false);
So the base path in the url reverse-proxy is ignored.
Can you remove the starting / in all relative uris?
So it's possible to use internal api gateway or reverse proxy.
If you agree, I can do the pull request.
Describe the bug
In my company, we use a reverse-proxy to access external API like the DeepL API.
So our intern URL to access the Deepl API is 'https://external-api.company.com/deepl/', next the reverse proxy forwards the query to 'https://api.deepl.com/'.
To Reproduce
I use 'DeepLClientOptions.ServerUrl' to specify our custom url :
But the http request url is 'https://external-api.company.com/v2/translate'.
Expected behavior
I expect the http request url to be 'https://external-api.company.com/deepl/v2/translate'
Additional context
The class Uri follows the RFC 3986 - Uniform Resource Identifier (URI): Generic Syntax, so when a relative uri starts by
/, then the relative path is considered to a absolute path.In this example :
Output :
In the DeepL SDK, all relative uris starts by
/likes in Translator.cs :So the base path in the url reverse-proxy is ignored.
Can you remove the starting
/in all relative uris?So it's possible to use internal api gateway or reverse proxy.
If you agree, I can do the pull request.