Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't set Timeout via Microsofr Dependency Injection for sync methods #574

Open
petr-fleischmann opened this issue Nov 5, 2021 · 0 comments

Comments

@petr-fleischmann
Copy link

Hi,
I can't set Timeout interval when I initialize SOLR via Microsoft.Extensions.DependencyInjection (ASP.NET core)
as services.AddSolrNet<Person>("http://localhost:8983/solr/person");. Method AddSolrNet has second paremeter SolrNetOptions options but HttpClient.Timeout is used only for Async methods. How can I set Timeout for sync methods ? ? Maybe new property in SolrNetOptions.Timeout for SolrConnection ? Btw. default timeout is 100s.

file: AutoSolrConnection.cs:
Async:

` public async Task<Stream> PostStreamAsStreamAsync(string relativeUrl, string contentType, Stream content, IEnumerable<KeyValuePair<string, string>> getParameters, CancellationToken cancellationToken)
        {
            var u = new UriBuilder(ServerURL);
            u.Path += relativeUrl;
            u.Query = GetQuery(getParameters);

            var sc = new StreamContent(content);
            sc.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse(contentType);

            var response = await HttpClient.PostAsync(u.Uri, sc);

            if (!response.IsSuccessStatusCode)
                throw new SolrConnectionException($"{response.StatusCode}: {response.ReasonPhrase}", null, u.Uri.ToString());

            return await response.Content.ReadAsStreamAsync();
        }`

Sync: (Doesn't use HttpClient from SolrOptions)
public string PostStream(string relativeUrl, string contentType, Stream content, IEnumerable<KeyValuePair<string, string>> getParameters) => SyncFallbackConnection.PostStream(relativeUrl, contentType, content, getParameters);

Thank you for your help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant