TorSharp
TorSharp copied to clipboard
Can't receive request body using TorSharp
Hello! I've a client-srver app, that using your component, and I faced a problem: I can't receive request body.
On a client side I 've:
private void InitHttpClient()
{
_logger.Info($"{nameof(InitHttpClient)}() started WebProxy...");
_webProxy = new WebProxy(new Uri($"http://localhost:{_settings.CurrentValue.InnerProxySettings.PrivoxySettings.Port}"))
{
BypassProxyOnLocal = false,
Credentials = null,
UseDefaultCredentials = true
};
var handler = new HttpClientHandler
{
Proxy = _webProxy,
MaxRequestContentBufferSize = 100000,
MaxResponseHeadersLength = 100000,
PreAuthenticate = false,
AutomaticDecompression = DecompressionMethods.All,
UseProxy = true,
UseDefaultCredentials = false
};
_httpClient = new HttpClient(handler, false)
{
Timeout = TimeSpan.FromMinutes(3),
DefaultVersionPolicy = HttpVersionPolicy.RequestVersionExact,
MaxResponseContentBufferSize = 1024576
};
}
private async Task<R> InnerSend<R>(string targetUri, HttpContent content) where R : class
{
try
{
var response = await _httpClient.PostAsJsonAsync(targetUri, content);
if (!response.IsSuccessStatusCode)
throw new OnionMessengerClientException(
$"Failed status code: {response.StatusCode} reason: {response.ReasonPhrase}!");
var respContent = await response.Content.ReadAsStringAsync();
if (string.IsNullOrWhiteSpace(respContent))
throw new OnionMessengerClientException("No content!");
return JsonConvert.DeserializeObject<R>(respContent);
}
catch (Exception ex) when (ex.GetType() != typeof(OnionMessengerClientException))
{
_logger.Error(ex, $"Exception was thrown! {ex.Message}");
}
return default;
}
on a server side I tried to make some workaround:
app.Use(async (context, next) =>
{
if (context.Request.Path.ToString().Contains("Ingress"))
{
var body = context.Request.Body.ContentToString();
}
await next.Invoke();
});
public static class StreamUtils
{
public static string ContentToString(this Stream source)
{
using var sr = new StreamReader(source);
return sr.ReadLine(); // READING stucks here
}
}
Does anybody knows any Solution?
TorSharp v.2.8.1/.Net Core 6/Windows 10
Could you provide a full repro in a Gist or GitHub repo? This will help us understand.