mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 16:42:57 +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:
commit
c3024e68f5
@ -54,6 +54,6 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="ppy.osu.Game.Resources" Version="2019.1230.0" />
|
<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>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -123,8 +123,6 @@ namespace osu.Game.Graphics.Containers
|
|||||||
|
|
||||||
Masking = true;
|
Masking = true;
|
||||||
Child = box = new Box { RelativeSizeAxes = Axes.Both };
|
Child = box = new Box { RelativeSizeAxes = Axes.Both };
|
||||||
|
|
||||||
ResizeTo(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
|
@ -14,7 +14,7 @@ namespace osu.Game.Online.API
|
|||||||
/// <typeparam name="T">Type of the response (used for deserialisation).</typeparam>
|
/// <typeparam name="T">Type of the response (used for deserialisation).</typeparam>
|
||||||
public abstract class APIRequest<T> : APIRequest
|
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;
|
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).
|
/// This will be scheduled to the API's internal scheduler (run on update thread automatically).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public new event APISuccessHandler<T> Success;
|
public new event APISuccessHandler<T> Success;
|
||||||
|
|
||||||
|
private class OsuJsonWebRequest<U> : JsonWebRequest<U>
|
||||||
|
{
|
||||||
|
public OsuJsonWebRequest(string uri)
|
||||||
|
: base(uri)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string UserAgent => "osu!";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -39,7 +49,7 @@ namespace osu.Game.Online.API
|
|||||||
{
|
{
|
||||||
protected abstract string Target { get; }
|
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}";
|
protected virtual string Uri => $@"{API.Endpoint}/api/v2/{Target}";
|
||||||
|
|
||||||
@ -152,6 +162,16 @@ namespace osu.Game.Online.API
|
|||||||
[JsonProperty("error")]
|
[JsonProperty("error")]
|
||||||
public string ErrorMessage { get; set; }
|
public string ErrorMessage { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class OsuWebRequest : WebRequest
|
||||||
|
{
|
||||||
|
public OsuWebRequest(string uri)
|
||||||
|
: base(uri)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string UserAgent => "osu!";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class APIException : InvalidOperationException
|
public class APIException : InvalidOperationException
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.6" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.6" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||||
<PackageReference Include="ppy.osu.Game.Resources" Version="2019.1230.0" />
|
<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="Sentry" Version="1.2.0" />
|
||||||
<PackageReference Include="SharpCompress" Version="0.24.0" />
|
<PackageReference Include="SharpCompress" Version="0.24.0" />
|
||||||
<PackageReference Include="NUnit" Version="3.12.0" />
|
<PackageReference Include="NUnit" Version="3.12.0" />
|
||||||
|
@ -74,7 +74,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup Label="Package References">
|
<ItemGroup Label="Package References">
|
||||||
<PackageReference Include="ppy.osu.Game.Resources" Version="2019.1230.0" />
|
<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>
|
</ItemGroup>
|
||||||
<!-- Xamarin.iOS does not automatically handle transitive dependencies from NuGet packages. -->
|
<!-- Xamarin.iOS does not automatically handle transitive dependencies from NuGet packages. -->
|
||||||
<ItemGroup Label="Transitive Dependencies">
|
<ItemGroup Label="Transitive Dependencies">
|
||||||
@ -82,7 +82,7 @@
|
|||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.6" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.6" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.6" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.6" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
<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="SharpCompress" Version="0.24.0" />
|
||||||
<PackageReference Include="NUnit" Version="3.12.0" />
|
<PackageReference Include="NUnit" Version="3.12.0" />
|
||||||
<PackageReference Include="SharpRaven" Version="2.4.0" />
|
<PackageReference Include="SharpRaven" Version="2.4.0" />
|
||||||
|
Loading…
Reference in New Issue
Block a user