1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 11:20:04 +08:00

Set UserAgent for API requests (#7384)

Set UserAgent for API requests

Co-authored-by: Dean Herbert <pe@ppy.sh>
This commit is contained in:
Dean Herbert 2020-01-07 17:31:25 +09:00 committed by GitHub
commit c3024e68f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 8 deletions

View File

@ -54,6 +54,6 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="ppy.osu.Game.Resources" Version="2019.1230.0" />
<PackageReference Include="ppy.osu.Framework.Android" Version="2019.1227.1" />
<PackageReference Include="ppy.osu.Framework.Android" Version="2020.103.0" />
</ItemGroup>
</Project>

View File

@ -123,8 +123,6 @@ namespace osu.Game.Graphics.Containers
Masking = true;
Child = box = new Box { RelativeSizeAxes = Axes.Both };
ResizeTo(1);
}
[BackgroundDependencyLoader]

View File

@ -14,7 +14,7 @@ namespace osu.Game.Online.API
/// <typeparam name="T">Type of the response (used for deserialisation).</typeparam>
public abstract class APIRequest<T> : APIRequest
{
protected override WebRequest CreateWebRequest() => new JsonWebRequest<T>(Uri);
protected override WebRequest CreateWebRequest() => new OsuJsonWebRequest<T>(Uri);
public T Result => ((JsonWebRequest<T>)WebRequest).ResponseObject;
@ -30,6 +30,16 @@ namespace osu.Game.Online.API
/// This will be scheduled to the API's internal scheduler (run on update thread automatically).
/// </summary>
public new event APISuccessHandler<T> Success;
private class OsuJsonWebRequest<U> : JsonWebRequest<U>
{
public OsuJsonWebRequest(string uri)
: base(uri)
{
}
protected override string UserAgent => "osu!";
}
}
/// <summary>
@ -39,7 +49,7 @@ namespace osu.Game.Online.API
{
protected abstract string Target { get; }
protected virtual WebRequest CreateWebRequest() => new WebRequest(Uri);
protected virtual WebRequest CreateWebRequest() => new OsuWebRequest(Uri);
protected virtual string Uri => $@"{API.Endpoint}/api/v2/{Target}";
@ -152,6 +162,16 @@ namespace osu.Game.Online.API
[JsonProperty("error")]
public string ErrorMessage { get; set; }
}
private class OsuWebRequest : WebRequest
{
public OsuWebRequest(string uri)
: base(uri)
{
}
protected override string UserAgent => "osu!";
}
}
public class APIException : InvalidOperationException

View File

@ -23,7 +23,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.6" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2019.1230.0" />
<PackageReference Include="ppy.osu.Framework" Version="2019.1227.1" />
<PackageReference Include="ppy.osu.Framework" Version="2020.103.0" />
<PackageReference Include="Sentry" Version="1.2.0" />
<PackageReference Include="SharpCompress" Version="0.24.0" />
<PackageReference Include="NUnit" Version="3.12.0" />

View File

@ -74,7 +74,7 @@
</ItemGroup>
<ItemGroup Label="Package References">
<PackageReference Include="ppy.osu.Game.Resources" Version="2019.1230.0" />
<PackageReference Include="ppy.osu.Framework.iOS" Version="2019.1227.1" />
<PackageReference Include="ppy.osu.Framework.iOS" Version="2020.103.0" />
</ItemGroup>
<!-- Xamarin.iOS does not automatically handle transitive dependencies from NuGet packages. -->
<ItemGroup Label="Transitive Dependencies">
@ -82,7 +82,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.6" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="ppy.osu.Framework" Version="2019.1227.1" />
<PackageReference Include="ppy.osu.Framework" Version="2020.103.0" />
<PackageReference Include="SharpCompress" Version="0.24.0" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="SharpRaven" Version="2.4.0" />