We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d452661 commit 57351d3Copy full SHA for 57351d3
Netkan/Processors/Inflator.cs
@@ -42,7 +42,7 @@ internal Inflator(bool overwriteCache,
42
IGame game,
43
NetFileCache cache)
44
: this(githubToken, gitlabToken,
45
- userAgent, prerelease, game,
+ prerelease, game,
46
cache,
47
new CachingHttpService(cache, overwriteCache, userAgent),
48
new ModuleService(game),
@@ -52,7 +52,6 @@ internal Inflator(bool overwriteCache,
52
53
internal Inflator(string? githubToken,
54
string? gitlabToken,
55
- string? userAgent,
56
bool? prerelease,
57
58
NetFileCache cache,
@@ -65,7 +64,7 @@ internal Inflator(string? githubToken,
65
64
this.http = http;
66
ckanValidator = new CkanValidator(http, moduleService, game, githubToken);
67
transformer = new NetkanTransformer(http, fileService, moduleService,
68
- githubToken, gitlabToken, userAgent,
+ githubToken, gitlabToken,
69
prerelease, game, netkanValidator);
70
}
71
Netkan/Services/CachingHttpService.cs
@@ -149,8 +149,11 @@ public void ClearRequestedURLs()
149
_requestedURLs.Clear();
150
151
152
- public Uri? ResolveRedirect(Uri url, string? userAgent)
153
- => Net.ResolveRedirect(url, userAgent);
+ public Uri? ResolveRedirect(Uri url)
+ => Net.ResolveRedirect(url, _userAgent);
154
+
155
+ public bool HasRedirect(Uri url)
156
+ => ResolveRedirect(url) != url;
157
158
private readonly NetFileCache _cache;
159
private readonly string? _userAgent;
Netkan/Services/IHttpService.cs
@@ -9,7 +9,8 @@ internal interface IHttpService
9
string? DownloadModule(Metadata metadata);
10
string? DownloadText(Uri url, string? authToken = null, string? mimeType = null);
11
12
- Uri? ResolveRedirect(Uri url, string? userAgent);
+ Uri? ResolveRedirect(Uri url);
13
+ bool HasRedirect(Uri url);
14
15
IEnumerable<Uri> RequestedURLs { get; }
16
void ClearRequestedURLs();
Netkan/Sources/Github/GithubApi.cs
@@ -108,8 +108,8 @@ public List<GithubUser> getOrgMembers(GithubUser organization)
108
109
110
private bool ActuallyHasWiki(GithubRef reference)
111
- // If no wiki pages have been created, the /wiki route redirects and this is null
112
- => _http.DownloadText(new Uri($"https://github.com/{reference.Account}/{reference.Project}/wiki")) != null;
+ // If no wiki pages have been created, the /wiki route redirects
+ => !_http.HasRedirect(new Uri($"https://github.com/{reference.Account}/{reference.Project}/wiki"));
113
114
/// <summary>
115
/// Download a URL via the GitHubAPI.
Netkan/Transformers/HttpTransformer.cs
@@ -13,9 +13,8 @@ namespace CKAN.NetKAN.Transformers
/// </summary>
internal sealed class HttpTransformer : ITransformer
{
- public HttpTransformer(IHttpService httpSvc, string? userAgent = null)
+ public HttpTransformer(IHttpService httpSvc)
17
18
- this.userAgent = userAgent;
19
http = httpSvc;
20
21
@@ -30,7 +29,7 @@ public IEnumerable<Metadata> Transform(Metadata metadata, TransformOptions opts)
30
29
31
if (Uri.IsWellFormedUriString(metadata.Kref.Id, UriKind.Absolute))
32
33
- var resolvedUri = http.ResolveRedirect(new Uri(metadata.Kref.Id), userAgent);
+ var resolvedUri = http.ResolveRedirect(new Uri(metadata.Kref.Id));
34
35
Log.InfoFormat("URL {0} resolved to {1}", metadata.Kref.Id, resolvedUri);
36
@@ -58,7 +57,6 @@ public IEnumerable<Metadata> Transform(Metadata metadata, TransformOptions opts)
yield return metadata;
59
60
61
- private readonly string? userAgent;
62
private readonly IHttpService http;
63
private static readonly ILog Log = LogManager.GetLogger(typeof(HttpTransformer));
Netkan/Transformers/NetkanTransformer.cs
@@ -25,7 +25,6 @@ public NetkanTransformer(IHttpService http,
25
IModuleService moduleService,
26
string? githubToken,
27
28
IValidator validator)
@@ -45,7 +44,7 @@ public NetkanTransformer(IHttpService http,
new GitlabTransformer(glApi),
new GiteaTransformer(giteaAPi),
new SourceForgeTransformer(sfApi),
- new HttpTransformer(http, userAgent),
+ new HttpTransformer(http),
49
new JenkinsTransformer(new JenkinsApi(http)),
50
new AvcKrefTransformer(http, ghApi),
51
new InternalCkanTransformer(http, moduleService),
Tests/NetKAN/Processors/InflatorTests.cs
@@ -29,7 +29,7 @@ public void Inflate_WithTestNetkan_Inflates()
var game = new KerbalSpaceProgram();
var modSvc = new ModuleService(game);
var fileSvc = new FileService(cache);
- var sut = new Inflator(null, null, null, null,
+ var sut = new Inflator(null, null, null,
game, cache, http.Object, modSvc, fileSvc);
var filename = TestData.TestNetkanPath();
var netkans = YamlExtensions.Parse(TestData.TestNetkanContents())
@@ -91,7 +91,7 @@ public void ValidateCkan_ValidModule_DoesNotThrow()
91
var http = new Mock<IHttpService>();
92
93
94
95
96
var ckans = YamlExtensions.Parse(TestData.DogeCoinPlugin())
97
.Select(yaml => new Metadata(yaml))
Tests/NetKAN/Transformers/HttpTransformerTests.cs
@@ -45,7 +45,7 @@ public void Transform_HttpKref_ResolvesRedirect()
// Arrange
- http.Setup(h => h.ResolveRedirect(It.IsAny<Uri>(), It.IsAny<string?>()))
+ http.Setup(h => h.ResolveRedirect(It.IsAny<Uri>()))
.Returns(new Uri("https://fake-web-site.com/redirected"));
var sut = new HttpTransformer(http.Object);
var opts = new TransformOptions(1, null, null, null, false, null);
0 commit comments