diff --git a/ExpandedSearchInfo/Providers/IProvider.cs b/ExpandedSearchInfo/Providers/IProvider.cs index dfa2dd1..eea6fe9 100644 --- a/ExpandedSearchInfo/Providers/IProvider.cs +++ b/ExpandedSearchInfo/Providers/IProvider.cs @@ -45,5 +45,12 @@ namespace ExpandedSearchInfo.Providers { /// HTTP response from a Uri /// null if search info could not be extracted or the search info as a string if it could Task ExtractInfo(HttpResponseMessage response); + + /// + /// Modify any requests made for this provider before they are sent. + /// + /// HTTP request about to be sent + void ModifyRequest(HttpRequestMessage request) { + } } } diff --git a/ExpandedSearchInfo/Providers/PlainTextProvider.cs b/ExpandedSearchInfo/Providers/PlainTextProvider.cs index c4d9b28..559f4aa 100644 --- a/ExpandedSearchInfo/Providers/PlainTextProvider.cs +++ b/ExpandedSearchInfo/Providers/PlainTextProvider.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Net.Http; +using System.Net.Http.Headers; using System.Threading.Tasks; using ExpandedSearchInfo.Configs; using ExpandedSearchInfo.Sections; @@ -38,5 +39,9 @@ namespace ExpandedSearchInfo.Providers { var uri = response.RequestMessage!.RequestUri!; return new TextSection(this, $"Text##{uri}", uri, info); } + + public void ModifyRequest(HttpRequestMessage request) { + request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("text/plain")); + } } } diff --git a/ExpandedSearchInfo/SearchInfoRepository.cs b/ExpandedSearchInfo/SearchInfoRepository.cs index ca2b1af..2673eb5 100644 --- a/ExpandedSearchInfo/SearchInfoRepository.cs +++ b/ExpandedSearchInfo/SearchInfoRepository.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; +using System.Net.Http.Headers; using System.Threading.Tasks; using Dalamud.Game.Text.SeStringHandling; using Dalamud.Logging; @@ -142,13 +143,19 @@ namespace ExpandedSearchInfo { MaxAutomaticRedirections = 5, }; handler.CookieContainer.Add(new Cookie("warning", "1", "/", "www.f-list.net")); - var client = new HttpClient(handler); + + var version = this.GetType().Assembly.GetName().Version?.ToString(3) ?? "unknown"; + var client = new HttpClient(handler) { + DefaultRequestHeaders = { + UserAgent = { new ProductInfoHeaderValue("ExpandedSearchInfo", version) }, + }, + }; var sections = new List(); // run through each extracted uri foreach (var uri in uris) { - if (uri.Scheme != "http" && uri.Scheme != "https") { + if (uri.Scheme is not ("http" or "https")) { continue; } @@ -163,7 +170,12 @@ namespace ExpandedSearchInfo { } // get the http response from the uri and make sure it's ok - var resp = await client.GetAsync(uri, HttpCompletionOption.ResponseHeadersRead); + var req = new HttpRequestMessage(HttpMethod.Get, uri); + foreach (var provider in matching) { + provider.ModifyRequest(req); + } + + var resp = await client.SendAsync(req); if (resp.StatusCode != HttpStatusCode.OK) { continue; }