0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 08:50:43 -05:00

156 lines
4.6 KiB
C#
Raw Normal View History

Modernize HTTP v2 (!104) This PR won't affect modders who have already updated their mods to 3.8.0. They just need to re-compile. This is a resubmission of my previous PR (https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/99) with additional code cleanup and fixes. Instead of outright removing the functionality, this time I deprecate it instead (marked for removal in next release). Requires https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/274 to function. ## Overview - HTTP modernization - Adds `Aki.Common.Http.Client`, a replacement for `Aki.Common.Http.Request` and builds on top of `System.Net.Http.HttpClient` - Implements failsafe retries when requesting during busy connections - Improved debugging - Improved performance - Deprecades old request code - Bundle system - Fixes remote downloaded bundles using external IP - Implements functional bundle caching from remote sources - Implements multi-threaded bundle downloads - Implements Unity-compatible bundle format support - Extensive cleanup - Deprecated unneccecary models ## Why? In it's current state, the bundle system is ducktaped together in 2021, fundumentally broken and in desperate need of a cleanup and fixes. The HTTP code hasn't been updated since 2021, and `HttpWebRequest` has been deprecated by Microsoft for a while now. There was also a lot of opportunity left for simple performance gains that even reduces the complexity of the code. As for why not two separate PRs (HTTP modernization, bundle rework): both were deeply interconnected. A change in one requires modification in the other. Hence the current approach. ## Testing The code has been validated and tested by @TheSparta and me. A large section of the code has been implemented and tested extensively by modders. ### Local 1. Start the game from 127.0.0.1 2. The game starts loading bundles from the mods path ### Remote, full re-aquire 1. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 2. Start the game from LAN IP 3. A folder named `user/cache/bundles` is created ### Remote, partial-aquire (deleted) 1. Ensure all bundles are cached 2. Delete one of the aquired bundles from cache 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, partial-aquire (invalid crc) 1. Ensure all bundles are cached 2. Update a bundle mod with a new bundle on the same path 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, use cache 1. Ensure all bundles are cached 2. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 3. Start the game from LAN IP 4. The game starts loading bundles from the cache path ## Risk assessment In order to reduce friction between releases, this PR introduces a deprecation system. Obsolete classes and methods have been marked deprecated. These will remain available for the current release and continue to function as normal for this release. A warning will be displayed during build when a modder relies on the deprecated functionality. The marked classes and methods are to be removed in the next release. The server-side changes have no impact on modders. ## Deprecation The following classes are affected: - `Aki.Common.Http.Request`: Replaced by `Aki.Common.Http.Request` - `Aki.Common.Http.WebConstants`: Replaced by functionality from `System.Net.Http` - `Aki.Custom.Models.BundleInfo`: Replaced by `Aki.Custom.Models.BundleItem` The following methods are affected: - `Aki.Common.Http.RequestHandler.GetData(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.GetJson(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PostJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PutJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. The deprecated methods and `Aki.Custom.Models.BundleInfo` are self-contained and can be removed independently. The deprecated classes require removal of all deprecated code at once. Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/104 Reviewed-by: TheSparta <thesparta@noreply.dev.sp-tarkov.com> Co-authored-by: Merijn Hendriks <merijn.d.hendriks@gmail.com> Co-committed-by: Merijn Hendriks <merijn.d.hendriks@gmail.com>
2024-03-29 18:43:46 +00:00
using System;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
2024-05-21 19:10:17 +01:00
using SPT.Common.Utils;
Modernize HTTP v2 (!104) This PR won't affect modders who have already updated their mods to 3.8.0. They just need to re-compile. This is a resubmission of my previous PR (https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/99) with additional code cleanup and fixes. Instead of outright removing the functionality, this time I deprecate it instead (marked for removal in next release). Requires https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/274 to function. ## Overview - HTTP modernization - Adds `Aki.Common.Http.Client`, a replacement for `Aki.Common.Http.Request` and builds on top of `System.Net.Http.HttpClient` - Implements failsafe retries when requesting during busy connections - Improved debugging - Improved performance - Deprecades old request code - Bundle system - Fixes remote downloaded bundles using external IP - Implements functional bundle caching from remote sources - Implements multi-threaded bundle downloads - Implements Unity-compatible bundle format support - Extensive cleanup - Deprecated unneccecary models ## Why? In it's current state, the bundle system is ducktaped together in 2021, fundumentally broken and in desperate need of a cleanup and fixes. The HTTP code hasn't been updated since 2021, and `HttpWebRequest` has been deprecated by Microsoft for a while now. There was also a lot of opportunity left for simple performance gains that even reduces the complexity of the code. As for why not two separate PRs (HTTP modernization, bundle rework): both were deeply interconnected. A change in one requires modification in the other. Hence the current approach. ## Testing The code has been validated and tested by @TheSparta and me. A large section of the code has been implemented and tested extensively by modders. ### Local 1. Start the game from 127.0.0.1 2. The game starts loading bundles from the mods path ### Remote, full re-aquire 1. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 2. Start the game from LAN IP 3. A folder named `user/cache/bundles` is created ### Remote, partial-aquire (deleted) 1. Ensure all bundles are cached 2. Delete one of the aquired bundles from cache 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, partial-aquire (invalid crc) 1. Ensure all bundles are cached 2. Update a bundle mod with a new bundle on the same path 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, use cache 1. Ensure all bundles are cached 2. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 3. Start the game from LAN IP 4. The game starts loading bundles from the cache path ## Risk assessment In order to reduce friction between releases, this PR introduces a deprecation system. Obsolete classes and methods have been marked deprecated. These will remain available for the current release and continue to function as normal for this release. A warning will be displayed during build when a modder relies on the deprecated functionality. The marked classes and methods are to be removed in the next release. The server-side changes have no impact on modders. ## Deprecation The following classes are affected: - `Aki.Common.Http.Request`: Replaced by `Aki.Common.Http.Request` - `Aki.Common.Http.WebConstants`: Replaced by functionality from `System.Net.Http` - `Aki.Custom.Models.BundleInfo`: Replaced by `Aki.Custom.Models.BundleItem` The following methods are affected: - `Aki.Common.Http.RequestHandler.GetData(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.GetJson(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PostJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PutJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. The deprecated methods and `Aki.Custom.Models.BundleInfo` are self-contained and can be removed independently. The deprecated classes require removal of all deprecated code at once. Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/104 Reviewed-by: TheSparta <thesparta@noreply.dev.sp-tarkov.com> Co-authored-by: Merijn Hendriks <merijn.d.hendriks@gmail.com> Co-committed-by: Merijn Hendriks <merijn.d.hendriks@gmail.com>
2024-03-29 18:43:46 +00:00
2024-05-21 19:10:17 +01:00
namespace SPT.Common.Http
Modernize HTTP v2 (!104) This PR won't affect modders who have already updated their mods to 3.8.0. They just need to re-compile. This is a resubmission of my previous PR (https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/99) with additional code cleanup and fixes. Instead of outright removing the functionality, this time I deprecate it instead (marked for removal in next release). Requires https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/274 to function. ## Overview - HTTP modernization - Adds `Aki.Common.Http.Client`, a replacement for `Aki.Common.Http.Request` and builds on top of `System.Net.Http.HttpClient` - Implements failsafe retries when requesting during busy connections - Improved debugging - Improved performance - Deprecades old request code - Bundle system - Fixes remote downloaded bundles using external IP - Implements functional bundle caching from remote sources - Implements multi-threaded bundle downloads - Implements Unity-compatible bundle format support - Extensive cleanup - Deprecated unneccecary models ## Why? In it's current state, the bundle system is ducktaped together in 2021, fundumentally broken and in desperate need of a cleanup and fixes. The HTTP code hasn't been updated since 2021, and `HttpWebRequest` has been deprecated by Microsoft for a while now. There was also a lot of opportunity left for simple performance gains that even reduces the complexity of the code. As for why not two separate PRs (HTTP modernization, bundle rework): both were deeply interconnected. A change in one requires modification in the other. Hence the current approach. ## Testing The code has been validated and tested by @TheSparta and me. A large section of the code has been implemented and tested extensively by modders. ### Local 1. Start the game from 127.0.0.1 2. The game starts loading bundles from the mods path ### Remote, full re-aquire 1. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 2. Start the game from LAN IP 3. A folder named `user/cache/bundles` is created ### Remote, partial-aquire (deleted) 1. Ensure all bundles are cached 2. Delete one of the aquired bundles from cache 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, partial-aquire (invalid crc) 1. Ensure all bundles are cached 2. Update a bundle mod with a new bundle on the same path 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, use cache 1. Ensure all bundles are cached 2. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 3. Start the game from LAN IP 4. The game starts loading bundles from the cache path ## Risk assessment In order to reduce friction between releases, this PR introduces a deprecation system. Obsolete classes and methods have been marked deprecated. These will remain available for the current release and continue to function as normal for this release. A warning will be displayed during build when a modder relies on the deprecated functionality. The marked classes and methods are to be removed in the next release. The server-side changes have no impact on modders. ## Deprecation The following classes are affected: - `Aki.Common.Http.Request`: Replaced by `Aki.Common.Http.Request` - `Aki.Common.Http.WebConstants`: Replaced by functionality from `System.Net.Http` - `Aki.Custom.Models.BundleInfo`: Replaced by `Aki.Custom.Models.BundleItem` The following methods are affected: - `Aki.Common.Http.RequestHandler.GetData(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.GetJson(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PostJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PutJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. The deprecated methods and `Aki.Custom.Models.BundleInfo` are self-contained and can be removed independently. The deprecated classes require removal of all deprecated code at once. Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/104 Reviewed-by: TheSparta <thesparta@noreply.dev.sp-tarkov.com> Co-authored-by: Merijn Hendriks <merijn.d.hendriks@gmail.com> Co-committed-by: Merijn Hendriks <merijn.d.hendriks@gmail.com>
2024-03-29 18:43:46 +00:00
{
// NOTE: Don't dispose this, keep a reference for the lifetime of the
// application.
Modernize HTTP v2 (!104) This PR won't affect modders who have already updated their mods to 3.8.0. They just need to re-compile. This is a resubmission of my previous PR (https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/99) with additional code cleanup and fixes. Instead of outright removing the functionality, this time I deprecate it instead (marked for removal in next release). Requires https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/274 to function. ## Overview - HTTP modernization - Adds `Aki.Common.Http.Client`, a replacement for `Aki.Common.Http.Request` and builds on top of `System.Net.Http.HttpClient` - Implements failsafe retries when requesting during busy connections - Improved debugging - Improved performance - Deprecades old request code - Bundle system - Fixes remote downloaded bundles using external IP - Implements functional bundle caching from remote sources - Implements multi-threaded bundle downloads - Implements Unity-compatible bundle format support - Extensive cleanup - Deprecated unneccecary models ## Why? In it's current state, the bundle system is ducktaped together in 2021, fundumentally broken and in desperate need of a cleanup and fixes. The HTTP code hasn't been updated since 2021, and `HttpWebRequest` has been deprecated by Microsoft for a while now. There was also a lot of opportunity left for simple performance gains that even reduces the complexity of the code. As for why not two separate PRs (HTTP modernization, bundle rework): both were deeply interconnected. A change in one requires modification in the other. Hence the current approach. ## Testing The code has been validated and tested by @TheSparta and me. A large section of the code has been implemented and tested extensively by modders. ### Local 1. Start the game from 127.0.0.1 2. The game starts loading bundles from the mods path ### Remote, full re-aquire 1. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 2. Start the game from LAN IP 3. A folder named `user/cache/bundles` is created ### Remote, partial-aquire (deleted) 1. Ensure all bundles are cached 2. Delete one of the aquired bundles from cache 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, partial-aquire (invalid crc) 1. Ensure all bundles are cached 2. Update a bundle mod with a new bundle on the same path 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, use cache 1. Ensure all bundles are cached 2. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 3. Start the game from LAN IP 4. The game starts loading bundles from the cache path ## Risk assessment In order to reduce friction between releases, this PR introduces a deprecation system. Obsolete classes and methods have been marked deprecated. These will remain available for the current release and continue to function as normal for this release. A warning will be displayed during build when a modder relies on the deprecated functionality. The marked classes and methods are to be removed in the next release. The server-side changes have no impact on modders. ## Deprecation The following classes are affected: - `Aki.Common.Http.Request`: Replaced by `Aki.Common.Http.Request` - `Aki.Common.Http.WebConstants`: Replaced by functionality from `System.Net.Http` - `Aki.Custom.Models.BundleInfo`: Replaced by `Aki.Custom.Models.BundleItem` The following methods are affected: - `Aki.Common.Http.RequestHandler.GetData(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.GetJson(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PostJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PutJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. The deprecated methods and `Aki.Custom.Models.BundleInfo` are self-contained and can be removed independently. The deprecated classes require removal of all deprecated code at once. Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/104 Reviewed-by: TheSparta <thesparta@noreply.dev.sp-tarkov.com> Co-authored-by: Merijn Hendriks <merijn.d.hendriks@gmail.com> Co-committed-by: Merijn Hendriks <merijn.d.hendriks@gmail.com>
2024-03-29 18:43:46 +00:00
public class Client : IDisposable
{
protected readonly HttpClient _httpv;
protected readonly string _address;
protected readonly string _accountId;
protected readonly int _retries;
public Client(string address, string accountId, int retries = 3)
{
_address = address;
_accountId = accountId;
_retries = retries;
var handler = new HttpClientHandler
Modernize HTTP v2 (!104) This PR won't affect modders who have already updated their mods to 3.8.0. They just need to re-compile. This is a resubmission of my previous PR (https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/99) with additional code cleanup and fixes. Instead of outright removing the functionality, this time I deprecate it instead (marked for removal in next release). Requires https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/274 to function. ## Overview - HTTP modernization - Adds `Aki.Common.Http.Client`, a replacement for `Aki.Common.Http.Request` and builds on top of `System.Net.Http.HttpClient` - Implements failsafe retries when requesting during busy connections - Improved debugging - Improved performance - Deprecades old request code - Bundle system - Fixes remote downloaded bundles using external IP - Implements functional bundle caching from remote sources - Implements multi-threaded bundle downloads - Implements Unity-compatible bundle format support - Extensive cleanup - Deprecated unneccecary models ## Why? In it's current state, the bundle system is ducktaped together in 2021, fundumentally broken and in desperate need of a cleanup and fixes. The HTTP code hasn't been updated since 2021, and `HttpWebRequest` has been deprecated by Microsoft for a while now. There was also a lot of opportunity left for simple performance gains that even reduces the complexity of the code. As for why not two separate PRs (HTTP modernization, bundle rework): both were deeply interconnected. A change in one requires modification in the other. Hence the current approach. ## Testing The code has been validated and tested by @TheSparta and me. A large section of the code has been implemented and tested extensively by modders. ### Local 1. Start the game from 127.0.0.1 2. The game starts loading bundles from the mods path ### Remote, full re-aquire 1. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 2. Start the game from LAN IP 3. A folder named `user/cache/bundles` is created ### Remote, partial-aquire (deleted) 1. Ensure all bundles are cached 2. Delete one of the aquired bundles from cache 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, partial-aquire (invalid crc) 1. Ensure all bundles are cached 2. Update a bundle mod with a new bundle on the same path 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, use cache 1. Ensure all bundles are cached 2. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 3. Start the game from LAN IP 4. The game starts loading bundles from the cache path ## Risk assessment In order to reduce friction between releases, this PR introduces a deprecation system. Obsolete classes and methods have been marked deprecated. These will remain available for the current release and continue to function as normal for this release. A warning will be displayed during build when a modder relies on the deprecated functionality. The marked classes and methods are to be removed in the next release. The server-side changes have no impact on modders. ## Deprecation The following classes are affected: - `Aki.Common.Http.Request`: Replaced by `Aki.Common.Http.Request` - `Aki.Common.Http.WebConstants`: Replaced by functionality from `System.Net.Http` - `Aki.Custom.Models.BundleInfo`: Replaced by `Aki.Custom.Models.BundleItem` The following methods are affected: - `Aki.Common.Http.RequestHandler.GetData(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.GetJson(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PostJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PutJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. The deprecated methods and `Aki.Custom.Models.BundleInfo` are self-contained and can be removed independently. The deprecated classes require removal of all deprecated code at once. Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/104 Reviewed-by: TheSparta <thesparta@noreply.dev.sp-tarkov.com> Co-authored-by: Merijn Hendriks <merijn.d.hendriks@gmail.com> Co-committed-by: Merijn Hendriks <merijn.d.hendriks@gmail.com>
2024-03-29 18:43:46 +00:00
{
// set cookies in header instead
Modernize HTTP v2 (!104) This PR won't affect modders who have already updated their mods to 3.8.0. They just need to re-compile. This is a resubmission of my previous PR (https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/99) with additional code cleanup and fixes. Instead of outright removing the functionality, this time I deprecate it instead (marked for removal in next release). Requires https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/274 to function. ## Overview - HTTP modernization - Adds `Aki.Common.Http.Client`, a replacement for `Aki.Common.Http.Request` and builds on top of `System.Net.Http.HttpClient` - Implements failsafe retries when requesting during busy connections - Improved debugging - Improved performance - Deprecades old request code - Bundle system - Fixes remote downloaded bundles using external IP - Implements functional bundle caching from remote sources - Implements multi-threaded bundle downloads - Implements Unity-compatible bundle format support - Extensive cleanup - Deprecated unneccecary models ## Why? In it's current state, the bundle system is ducktaped together in 2021, fundumentally broken and in desperate need of a cleanup and fixes. The HTTP code hasn't been updated since 2021, and `HttpWebRequest` has been deprecated by Microsoft for a while now. There was also a lot of opportunity left for simple performance gains that even reduces the complexity of the code. As for why not two separate PRs (HTTP modernization, bundle rework): both were deeply interconnected. A change in one requires modification in the other. Hence the current approach. ## Testing The code has been validated and tested by @TheSparta and me. A large section of the code has been implemented and tested extensively by modders. ### Local 1. Start the game from 127.0.0.1 2. The game starts loading bundles from the mods path ### Remote, full re-aquire 1. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 2. Start the game from LAN IP 3. A folder named `user/cache/bundles` is created ### Remote, partial-aquire (deleted) 1. Ensure all bundles are cached 2. Delete one of the aquired bundles from cache 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, partial-aquire (invalid crc) 1. Ensure all bundles are cached 2. Update a bundle mod with a new bundle on the same path 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, use cache 1. Ensure all bundles are cached 2. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 3. Start the game from LAN IP 4. The game starts loading bundles from the cache path ## Risk assessment In order to reduce friction between releases, this PR introduces a deprecation system. Obsolete classes and methods have been marked deprecated. These will remain available for the current release and continue to function as normal for this release. A warning will be displayed during build when a modder relies on the deprecated functionality. The marked classes and methods are to be removed in the next release. The server-side changes have no impact on modders. ## Deprecation The following classes are affected: - `Aki.Common.Http.Request`: Replaced by `Aki.Common.Http.Request` - `Aki.Common.Http.WebConstants`: Replaced by functionality from `System.Net.Http` - `Aki.Custom.Models.BundleInfo`: Replaced by `Aki.Custom.Models.BundleItem` The following methods are affected: - `Aki.Common.Http.RequestHandler.GetData(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.GetJson(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PostJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PutJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. The deprecated methods and `Aki.Custom.Models.BundleInfo` are self-contained and can be removed independently. The deprecated classes require removal of all deprecated code at once. Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/104 Reviewed-by: TheSparta <thesparta@noreply.dev.sp-tarkov.com> Co-authored-by: Merijn Hendriks <merijn.d.hendriks@gmail.com> Co-committed-by: Merijn Hendriks <merijn.d.hendriks@gmail.com>
2024-03-29 18:43:46 +00:00
UseCookies = false
};
_httpv = new HttpClient(handler);
}
private HttpRequestMessage GetNewRequest(HttpMethod method, string path)
{
return new HttpRequestMessage()
{
Method = method,
RequestUri = new Uri(_address + path),
Headers = {
{ "Cookie", $"PHPSESSID={_accountId}" }
}
};
}
protected async Task<byte[]> SendAsync(HttpMethod method, string path, byte[] data, bool zipped = true)
Modernize HTTP v2 (!104) This PR won't affect modders who have already updated their mods to 3.8.0. They just need to re-compile. This is a resubmission of my previous PR (https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/99) with additional code cleanup and fixes. Instead of outright removing the functionality, this time I deprecate it instead (marked for removal in next release). Requires https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/274 to function. ## Overview - HTTP modernization - Adds `Aki.Common.Http.Client`, a replacement for `Aki.Common.Http.Request` and builds on top of `System.Net.Http.HttpClient` - Implements failsafe retries when requesting during busy connections - Improved debugging - Improved performance - Deprecades old request code - Bundle system - Fixes remote downloaded bundles using external IP - Implements functional bundle caching from remote sources - Implements multi-threaded bundle downloads - Implements Unity-compatible bundle format support - Extensive cleanup - Deprecated unneccecary models ## Why? In it's current state, the bundle system is ducktaped together in 2021, fundumentally broken and in desperate need of a cleanup and fixes. The HTTP code hasn't been updated since 2021, and `HttpWebRequest` has been deprecated by Microsoft for a while now. There was also a lot of opportunity left for simple performance gains that even reduces the complexity of the code. As for why not two separate PRs (HTTP modernization, bundle rework): both were deeply interconnected. A change in one requires modification in the other. Hence the current approach. ## Testing The code has been validated and tested by @TheSparta and me. A large section of the code has been implemented and tested extensively by modders. ### Local 1. Start the game from 127.0.0.1 2. The game starts loading bundles from the mods path ### Remote, full re-aquire 1. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 2. Start the game from LAN IP 3. A folder named `user/cache/bundles` is created ### Remote, partial-aquire (deleted) 1. Ensure all bundles are cached 2. Delete one of the aquired bundles from cache 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, partial-aquire (invalid crc) 1. Ensure all bundles are cached 2. Update a bundle mod with a new bundle on the same path 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, use cache 1. Ensure all bundles are cached 2. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 3. Start the game from LAN IP 4. The game starts loading bundles from the cache path ## Risk assessment In order to reduce friction between releases, this PR introduces a deprecation system. Obsolete classes and methods have been marked deprecated. These will remain available for the current release and continue to function as normal for this release. A warning will be displayed during build when a modder relies on the deprecated functionality. The marked classes and methods are to be removed in the next release. The server-side changes have no impact on modders. ## Deprecation The following classes are affected: - `Aki.Common.Http.Request`: Replaced by `Aki.Common.Http.Request` - `Aki.Common.Http.WebConstants`: Replaced by functionality from `System.Net.Http` - `Aki.Custom.Models.BundleInfo`: Replaced by `Aki.Custom.Models.BundleItem` The following methods are affected: - `Aki.Common.Http.RequestHandler.GetData(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.GetJson(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PostJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PutJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. The deprecated methods and `Aki.Custom.Models.BundleInfo` are self-contained and can be removed independently. The deprecated classes require removal of all deprecated code at once. Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/104 Reviewed-by: TheSparta <thesparta@noreply.dev.sp-tarkov.com> Co-authored-by: Merijn Hendriks <merijn.d.hendriks@gmail.com> Co-committed-by: Merijn Hendriks <merijn.d.hendriks@gmail.com>
2024-03-29 18:43:46 +00:00
{
HttpResponseMessage response = null;
using (var request = GetNewRequest(method, path))
{
if (data != null)
{
// add payload to request
if (zipped)
{
data = Zlib.Compress(data, ZlibCompression.Maximum);
}
request.Content = new ByteArrayContent(data);
Modernize HTTP v2 (!104) This PR won't affect modders who have already updated their mods to 3.8.0. They just need to re-compile. This is a resubmission of my previous PR (https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/99) with additional code cleanup and fixes. Instead of outright removing the functionality, this time I deprecate it instead (marked for removal in next release). Requires https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/274 to function. ## Overview - HTTP modernization - Adds `Aki.Common.Http.Client`, a replacement for `Aki.Common.Http.Request` and builds on top of `System.Net.Http.HttpClient` - Implements failsafe retries when requesting during busy connections - Improved debugging - Improved performance - Deprecades old request code - Bundle system - Fixes remote downloaded bundles using external IP - Implements functional bundle caching from remote sources - Implements multi-threaded bundle downloads - Implements Unity-compatible bundle format support - Extensive cleanup - Deprecated unneccecary models ## Why? In it's current state, the bundle system is ducktaped together in 2021, fundumentally broken and in desperate need of a cleanup and fixes. The HTTP code hasn't been updated since 2021, and `HttpWebRequest` has been deprecated by Microsoft for a while now. There was also a lot of opportunity left for simple performance gains that even reduces the complexity of the code. As for why not two separate PRs (HTTP modernization, bundle rework): both were deeply interconnected. A change in one requires modification in the other. Hence the current approach. ## Testing The code has been validated and tested by @TheSparta and me. A large section of the code has been implemented and tested extensively by modders. ### Local 1. Start the game from 127.0.0.1 2. The game starts loading bundles from the mods path ### Remote, full re-aquire 1. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 2. Start the game from LAN IP 3. A folder named `user/cache/bundles` is created ### Remote, partial-aquire (deleted) 1. Ensure all bundles are cached 2. Delete one of the aquired bundles from cache 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, partial-aquire (invalid crc) 1. Ensure all bundles are cached 2. Update a bundle mod with a new bundle on the same path 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, use cache 1. Ensure all bundles are cached 2. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 3. Start the game from LAN IP 4. The game starts loading bundles from the cache path ## Risk assessment In order to reduce friction between releases, this PR introduces a deprecation system. Obsolete classes and methods have been marked deprecated. These will remain available for the current release and continue to function as normal for this release. A warning will be displayed during build when a modder relies on the deprecated functionality. The marked classes and methods are to be removed in the next release. The server-side changes have no impact on modders. ## Deprecation The following classes are affected: - `Aki.Common.Http.Request`: Replaced by `Aki.Common.Http.Request` - `Aki.Common.Http.WebConstants`: Replaced by functionality from `System.Net.Http` - `Aki.Custom.Models.BundleInfo`: Replaced by `Aki.Custom.Models.BundleItem` The following methods are affected: - `Aki.Common.Http.RequestHandler.GetData(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.GetJson(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PostJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PutJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. The deprecated methods and `Aki.Custom.Models.BundleInfo` are self-contained and can be removed independently. The deprecated classes require removal of all deprecated code at once. Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/104 Reviewed-by: TheSparta <thesparta@noreply.dev.sp-tarkov.com> Co-authored-by: Merijn Hendriks <merijn.d.hendriks@gmail.com> Co-committed-by: Merijn Hendriks <merijn.d.hendriks@gmail.com>
2024-03-29 18:43:46 +00:00
}
// send request
response = await _httpv.SendAsync(request);
Modernize HTTP v2 (!104) This PR won't affect modders who have already updated their mods to 3.8.0. They just need to re-compile. This is a resubmission of my previous PR (https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/99) with additional code cleanup and fixes. Instead of outright removing the functionality, this time I deprecate it instead (marked for removal in next release). Requires https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/274 to function. ## Overview - HTTP modernization - Adds `Aki.Common.Http.Client`, a replacement for `Aki.Common.Http.Request` and builds on top of `System.Net.Http.HttpClient` - Implements failsafe retries when requesting during busy connections - Improved debugging - Improved performance - Deprecades old request code - Bundle system - Fixes remote downloaded bundles using external IP - Implements functional bundle caching from remote sources - Implements multi-threaded bundle downloads - Implements Unity-compatible bundle format support - Extensive cleanup - Deprecated unneccecary models ## Why? In it's current state, the bundle system is ducktaped together in 2021, fundumentally broken and in desperate need of a cleanup and fixes. The HTTP code hasn't been updated since 2021, and `HttpWebRequest` has been deprecated by Microsoft for a while now. There was also a lot of opportunity left for simple performance gains that even reduces the complexity of the code. As for why not two separate PRs (HTTP modernization, bundle rework): both were deeply interconnected. A change in one requires modification in the other. Hence the current approach. ## Testing The code has been validated and tested by @TheSparta and me. A large section of the code has been implemented and tested extensively by modders. ### Local 1. Start the game from 127.0.0.1 2. The game starts loading bundles from the mods path ### Remote, full re-aquire 1. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 2. Start the game from LAN IP 3. A folder named `user/cache/bundles` is created ### Remote, partial-aquire (deleted) 1. Ensure all bundles are cached 2. Delete one of the aquired bundles from cache 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, partial-aquire (invalid crc) 1. Ensure all bundles are cached 2. Update a bundle mod with a new bundle on the same path 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, use cache 1. Ensure all bundles are cached 2. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 3. Start the game from LAN IP 4. The game starts loading bundles from the cache path ## Risk assessment In order to reduce friction between releases, this PR introduces a deprecation system. Obsolete classes and methods have been marked deprecated. These will remain available for the current release and continue to function as normal for this release. A warning will be displayed during build when a modder relies on the deprecated functionality. The marked classes and methods are to be removed in the next release. The server-side changes have no impact on modders. ## Deprecation The following classes are affected: - `Aki.Common.Http.Request`: Replaced by `Aki.Common.Http.Request` - `Aki.Common.Http.WebConstants`: Replaced by functionality from `System.Net.Http` - `Aki.Custom.Models.BundleInfo`: Replaced by `Aki.Custom.Models.BundleItem` The following methods are affected: - `Aki.Common.Http.RequestHandler.GetData(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.GetJson(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PostJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PutJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. The deprecated methods and `Aki.Custom.Models.BundleInfo` are self-contained and can be removed independently. The deprecated classes require removal of all deprecated code at once. Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/104 Reviewed-by: TheSparta <thesparta@noreply.dev.sp-tarkov.com> Co-authored-by: Merijn Hendriks <merijn.d.hendriks@gmail.com> Co-committed-by: Merijn Hendriks <merijn.d.hendriks@gmail.com>
2024-03-29 18:43:46 +00:00
}
if (!response.IsSuccessStatusCode)
{
// response error
throw new Exception($"Code {response.StatusCode}");
}
using (var ms = new MemoryStream())
{
using (var stream = await response.Content.ReadAsStreamAsync())
Modernize HTTP v2 (!104) This PR won't affect modders who have already updated their mods to 3.8.0. They just need to re-compile. This is a resubmission of my previous PR (https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/99) with additional code cleanup and fixes. Instead of outright removing the functionality, this time I deprecate it instead (marked for removal in next release). Requires https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/274 to function. ## Overview - HTTP modernization - Adds `Aki.Common.Http.Client`, a replacement for `Aki.Common.Http.Request` and builds on top of `System.Net.Http.HttpClient` - Implements failsafe retries when requesting during busy connections - Improved debugging - Improved performance - Deprecades old request code - Bundle system - Fixes remote downloaded bundles using external IP - Implements functional bundle caching from remote sources - Implements multi-threaded bundle downloads - Implements Unity-compatible bundle format support - Extensive cleanup - Deprecated unneccecary models ## Why? In it's current state, the bundle system is ducktaped together in 2021, fundumentally broken and in desperate need of a cleanup and fixes. The HTTP code hasn't been updated since 2021, and `HttpWebRequest` has been deprecated by Microsoft for a while now. There was also a lot of opportunity left for simple performance gains that even reduces the complexity of the code. As for why not two separate PRs (HTTP modernization, bundle rework): both were deeply interconnected. A change in one requires modification in the other. Hence the current approach. ## Testing The code has been validated and tested by @TheSparta and me. A large section of the code has been implemented and tested extensively by modders. ### Local 1. Start the game from 127.0.0.1 2. The game starts loading bundles from the mods path ### Remote, full re-aquire 1. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 2. Start the game from LAN IP 3. A folder named `user/cache/bundles` is created ### Remote, partial-aquire (deleted) 1. Ensure all bundles are cached 2. Delete one of the aquired bundles from cache 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, partial-aquire (invalid crc) 1. Ensure all bundles are cached 2. Update a bundle mod with a new bundle on the same path 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, use cache 1. Ensure all bundles are cached 2. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 3. Start the game from LAN IP 4. The game starts loading bundles from the cache path ## Risk assessment In order to reduce friction between releases, this PR introduces a deprecation system. Obsolete classes and methods have been marked deprecated. These will remain available for the current release and continue to function as normal for this release. A warning will be displayed during build when a modder relies on the deprecated functionality. The marked classes and methods are to be removed in the next release. The server-side changes have no impact on modders. ## Deprecation The following classes are affected: - `Aki.Common.Http.Request`: Replaced by `Aki.Common.Http.Request` - `Aki.Common.Http.WebConstants`: Replaced by functionality from `System.Net.Http` - `Aki.Custom.Models.BundleInfo`: Replaced by `Aki.Custom.Models.BundleItem` The following methods are affected: - `Aki.Common.Http.RequestHandler.GetData(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.GetJson(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PostJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PutJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. The deprecated methods and `Aki.Custom.Models.BundleInfo` are self-contained and can be removed independently. The deprecated classes require removal of all deprecated code at once. Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/104 Reviewed-by: TheSparta <thesparta@noreply.dev.sp-tarkov.com> Co-authored-by: Merijn Hendriks <merijn.d.hendriks@gmail.com> Co-committed-by: Merijn Hendriks <merijn.d.hendriks@gmail.com>
2024-03-29 18:43:46 +00:00
{
// grap response payload
await stream.CopyToAsync(ms);
var body = ms.ToArray();
Modernize HTTP v2 (!104) This PR won't affect modders who have already updated their mods to 3.8.0. They just need to re-compile. This is a resubmission of my previous PR (https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/99) with additional code cleanup and fixes. Instead of outright removing the functionality, this time I deprecate it instead (marked for removal in next release). Requires https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/274 to function. ## Overview - HTTP modernization - Adds `Aki.Common.Http.Client`, a replacement for `Aki.Common.Http.Request` and builds on top of `System.Net.Http.HttpClient` - Implements failsafe retries when requesting during busy connections - Improved debugging - Improved performance - Deprecades old request code - Bundle system - Fixes remote downloaded bundles using external IP - Implements functional bundle caching from remote sources - Implements multi-threaded bundle downloads - Implements Unity-compatible bundle format support - Extensive cleanup - Deprecated unneccecary models ## Why? In it's current state, the bundle system is ducktaped together in 2021, fundumentally broken and in desperate need of a cleanup and fixes. The HTTP code hasn't been updated since 2021, and `HttpWebRequest` has been deprecated by Microsoft for a while now. There was also a lot of opportunity left for simple performance gains that even reduces the complexity of the code. As for why not two separate PRs (HTTP modernization, bundle rework): both were deeply interconnected. A change in one requires modification in the other. Hence the current approach. ## Testing The code has been validated and tested by @TheSparta and me. A large section of the code has been implemented and tested extensively by modders. ### Local 1. Start the game from 127.0.0.1 2. The game starts loading bundles from the mods path ### Remote, full re-aquire 1. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 2. Start the game from LAN IP 3. A folder named `user/cache/bundles` is created ### Remote, partial-aquire (deleted) 1. Ensure all bundles are cached 2. Delete one of the aquired bundles from cache 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, partial-aquire (invalid crc) 1. Ensure all bundles are cached 2. Update a bundle mod with a new bundle on the same path 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, use cache 1. Ensure all bundles are cached 2. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 3. Start the game from LAN IP 4. The game starts loading bundles from the cache path ## Risk assessment In order to reduce friction between releases, this PR introduces a deprecation system. Obsolete classes and methods have been marked deprecated. These will remain available for the current release and continue to function as normal for this release. A warning will be displayed during build when a modder relies on the deprecated functionality. The marked classes and methods are to be removed in the next release. The server-side changes have no impact on modders. ## Deprecation The following classes are affected: - `Aki.Common.Http.Request`: Replaced by `Aki.Common.Http.Request` - `Aki.Common.Http.WebConstants`: Replaced by functionality from `System.Net.Http` - `Aki.Custom.Models.BundleInfo`: Replaced by `Aki.Custom.Models.BundleItem` The following methods are affected: - `Aki.Common.Http.RequestHandler.GetData(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.GetJson(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PostJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PutJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. The deprecated methods and `Aki.Custom.Models.BundleInfo` are self-contained and can be removed independently. The deprecated classes require removal of all deprecated code at once. Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/104 Reviewed-by: TheSparta <thesparta@noreply.dev.sp-tarkov.com> Co-authored-by: Merijn Hendriks <merijn.d.hendriks@gmail.com> Co-committed-by: Merijn Hendriks <merijn.d.hendriks@gmail.com>
2024-03-29 18:43:46 +00:00
if (Zlib.IsCompressed(body))
Modernize HTTP v2 (!104) This PR won't affect modders who have already updated their mods to 3.8.0. They just need to re-compile. This is a resubmission of my previous PR (https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/99) with additional code cleanup and fixes. Instead of outright removing the functionality, this time I deprecate it instead (marked for removal in next release). Requires https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/274 to function. ## Overview - HTTP modernization - Adds `Aki.Common.Http.Client`, a replacement for `Aki.Common.Http.Request` and builds on top of `System.Net.Http.HttpClient` - Implements failsafe retries when requesting during busy connections - Improved debugging - Improved performance - Deprecades old request code - Bundle system - Fixes remote downloaded bundles using external IP - Implements functional bundle caching from remote sources - Implements multi-threaded bundle downloads - Implements Unity-compatible bundle format support - Extensive cleanup - Deprecated unneccecary models ## Why? In it's current state, the bundle system is ducktaped together in 2021, fundumentally broken and in desperate need of a cleanup and fixes. The HTTP code hasn't been updated since 2021, and `HttpWebRequest` has been deprecated by Microsoft for a while now. There was also a lot of opportunity left for simple performance gains that even reduces the complexity of the code. As for why not two separate PRs (HTTP modernization, bundle rework): both were deeply interconnected. A change in one requires modification in the other. Hence the current approach. ## Testing The code has been validated and tested by @TheSparta and me. A large section of the code has been implemented and tested extensively by modders. ### Local 1. Start the game from 127.0.0.1 2. The game starts loading bundles from the mods path ### Remote, full re-aquire 1. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 2. Start the game from LAN IP 3. A folder named `user/cache/bundles` is created ### Remote, partial-aquire (deleted) 1. Ensure all bundles are cached 2. Delete one of the aquired bundles from cache 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, partial-aquire (invalid crc) 1. Ensure all bundles are cached 2. Update a bundle mod with a new bundle on the same path 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, use cache 1. Ensure all bundles are cached 2. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 3. Start the game from LAN IP 4. The game starts loading bundles from the cache path ## Risk assessment In order to reduce friction between releases, this PR introduces a deprecation system. Obsolete classes and methods have been marked deprecated. These will remain available for the current release and continue to function as normal for this release. A warning will be displayed during build when a modder relies on the deprecated functionality. The marked classes and methods are to be removed in the next release. The server-side changes have no impact on modders. ## Deprecation The following classes are affected: - `Aki.Common.Http.Request`: Replaced by `Aki.Common.Http.Request` - `Aki.Common.Http.WebConstants`: Replaced by functionality from `System.Net.Http` - `Aki.Custom.Models.BundleInfo`: Replaced by `Aki.Custom.Models.BundleItem` The following methods are affected: - `Aki.Common.Http.RequestHandler.GetData(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.GetJson(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PostJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PutJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. The deprecated methods and `Aki.Custom.Models.BundleInfo` are self-contained and can be removed independently. The deprecated classes require removal of all deprecated code at once. Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/104 Reviewed-by: TheSparta <thesparta@noreply.dev.sp-tarkov.com> Co-authored-by: Merijn Hendriks <merijn.d.hendriks@gmail.com> Co-committed-by: Merijn Hendriks <merijn.d.hendriks@gmail.com>
2024-03-29 18:43:46 +00:00
{
body = Zlib.Decompress(body);
Modernize HTTP v2 (!104) This PR won't affect modders who have already updated their mods to 3.8.0. They just need to re-compile. This is a resubmission of my previous PR (https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/99) with additional code cleanup and fixes. Instead of outright removing the functionality, this time I deprecate it instead (marked for removal in next release). Requires https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/274 to function. ## Overview - HTTP modernization - Adds `Aki.Common.Http.Client`, a replacement for `Aki.Common.Http.Request` and builds on top of `System.Net.Http.HttpClient` - Implements failsafe retries when requesting during busy connections - Improved debugging - Improved performance - Deprecades old request code - Bundle system - Fixes remote downloaded bundles using external IP - Implements functional bundle caching from remote sources - Implements multi-threaded bundle downloads - Implements Unity-compatible bundle format support - Extensive cleanup - Deprecated unneccecary models ## Why? In it's current state, the bundle system is ducktaped together in 2021, fundumentally broken and in desperate need of a cleanup and fixes. The HTTP code hasn't been updated since 2021, and `HttpWebRequest` has been deprecated by Microsoft for a while now. There was also a lot of opportunity left for simple performance gains that even reduces the complexity of the code. As for why not two separate PRs (HTTP modernization, bundle rework): both were deeply interconnected. A change in one requires modification in the other. Hence the current approach. ## Testing The code has been validated and tested by @TheSparta and me. A large section of the code has been implemented and tested extensively by modders. ### Local 1. Start the game from 127.0.0.1 2. The game starts loading bundles from the mods path ### Remote, full re-aquire 1. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 2. Start the game from LAN IP 3. A folder named `user/cache/bundles` is created ### Remote, partial-aquire (deleted) 1. Ensure all bundles are cached 2. Delete one of the aquired bundles from cache 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, partial-aquire (invalid crc) 1. Ensure all bundles are cached 2. Update a bundle mod with a new bundle on the same path 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, use cache 1. Ensure all bundles are cached 2. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 3. Start the game from LAN IP 4. The game starts loading bundles from the cache path ## Risk assessment In order to reduce friction between releases, this PR introduces a deprecation system. Obsolete classes and methods have been marked deprecated. These will remain available for the current release and continue to function as normal for this release. A warning will be displayed during build when a modder relies on the deprecated functionality. The marked classes and methods are to be removed in the next release. The server-side changes have no impact on modders. ## Deprecation The following classes are affected: - `Aki.Common.Http.Request`: Replaced by `Aki.Common.Http.Request` - `Aki.Common.Http.WebConstants`: Replaced by functionality from `System.Net.Http` - `Aki.Custom.Models.BundleInfo`: Replaced by `Aki.Custom.Models.BundleItem` The following methods are affected: - `Aki.Common.Http.RequestHandler.GetData(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.GetJson(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PostJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PutJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. The deprecated methods and `Aki.Custom.Models.BundleInfo` are self-contained and can be removed independently. The deprecated classes require removal of all deprecated code at once. Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/104 Reviewed-by: TheSparta <thesparta@noreply.dev.sp-tarkov.com> Co-authored-by: Merijn Hendriks <merijn.d.hendriks@gmail.com> Co-committed-by: Merijn Hendriks <merijn.d.hendriks@gmail.com>
2024-03-29 18:43:46 +00:00
}
if (body == null)
{
// payload doesn't contains data
var code = response.StatusCode.ToString();
body = Encoding.UTF8.GetBytes(code);
}
return body;
Modernize HTTP v2 (!104) This PR won't affect modders who have already updated their mods to 3.8.0. They just need to re-compile. This is a resubmission of my previous PR (https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/99) with additional code cleanup and fixes. Instead of outright removing the functionality, this time I deprecate it instead (marked for removal in next release). Requires https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/274 to function. ## Overview - HTTP modernization - Adds `Aki.Common.Http.Client`, a replacement for `Aki.Common.Http.Request` and builds on top of `System.Net.Http.HttpClient` - Implements failsafe retries when requesting during busy connections - Improved debugging - Improved performance - Deprecades old request code - Bundle system - Fixes remote downloaded bundles using external IP - Implements functional bundle caching from remote sources - Implements multi-threaded bundle downloads - Implements Unity-compatible bundle format support - Extensive cleanup - Deprecated unneccecary models ## Why? In it's current state, the bundle system is ducktaped together in 2021, fundumentally broken and in desperate need of a cleanup and fixes. The HTTP code hasn't been updated since 2021, and `HttpWebRequest` has been deprecated by Microsoft for a while now. There was also a lot of opportunity left for simple performance gains that even reduces the complexity of the code. As for why not two separate PRs (HTTP modernization, bundle rework): both were deeply interconnected. A change in one requires modification in the other. Hence the current approach. ## Testing The code has been validated and tested by @TheSparta and me. A large section of the code has been implemented and tested extensively by modders. ### Local 1. Start the game from 127.0.0.1 2. The game starts loading bundles from the mods path ### Remote, full re-aquire 1. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 2. Start the game from LAN IP 3. A folder named `user/cache/bundles` is created ### Remote, partial-aquire (deleted) 1. Ensure all bundles are cached 2. Delete one of the aquired bundles from cache 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, partial-aquire (invalid crc) 1. Ensure all bundles are cached 2. Update a bundle mod with a new bundle on the same path 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, use cache 1. Ensure all bundles are cached 2. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 3. Start the game from LAN IP 4. The game starts loading bundles from the cache path ## Risk assessment In order to reduce friction between releases, this PR introduces a deprecation system. Obsolete classes and methods have been marked deprecated. These will remain available for the current release and continue to function as normal for this release. A warning will be displayed during build when a modder relies on the deprecated functionality. The marked classes and methods are to be removed in the next release. The server-side changes have no impact on modders. ## Deprecation The following classes are affected: - `Aki.Common.Http.Request`: Replaced by `Aki.Common.Http.Request` - `Aki.Common.Http.WebConstants`: Replaced by functionality from `System.Net.Http` - `Aki.Custom.Models.BundleInfo`: Replaced by `Aki.Custom.Models.BundleItem` The following methods are affected: - `Aki.Common.Http.RequestHandler.GetData(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.GetJson(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PostJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PutJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. The deprecated methods and `Aki.Custom.Models.BundleInfo` are self-contained and can be removed independently. The deprecated classes require removal of all deprecated code at once. Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/104 Reviewed-by: TheSparta <thesparta@noreply.dev.sp-tarkov.com> Co-authored-by: Merijn Hendriks <merijn.d.hendriks@gmail.com> Co-committed-by: Merijn Hendriks <merijn.d.hendriks@gmail.com>
2024-03-29 18:43:46 +00:00
}
}
}
protected async Task<byte[]> SendWithRetriesAsync(HttpMethod method, string path, byte[] data, bool compress = true)
Modernize HTTP v2 (!104) This PR won't affect modders who have already updated their mods to 3.8.0. They just need to re-compile. This is a resubmission of my previous PR (https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/99) with additional code cleanup and fixes. Instead of outright removing the functionality, this time I deprecate it instead (marked for removal in next release). Requires https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/274 to function. ## Overview - HTTP modernization - Adds `Aki.Common.Http.Client`, a replacement for `Aki.Common.Http.Request` and builds on top of `System.Net.Http.HttpClient` - Implements failsafe retries when requesting during busy connections - Improved debugging - Improved performance - Deprecades old request code - Bundle system - Fixes remote downloaded bundles using external IP - Implements functional bundle caching from remote sources - Implements multi-threaded bundle downloads - Implements Unity-compatible bundle format support - Extensive cleanup - Deprecated unneccecary models ## Why? In it's current state, the bundle system is ducktaped together in 2021, fundumentally broken and in desperate need of a cleanup and fixes. The HTTP code hasn't been updated since 2021, and `HttpWebRequest` has been deprecated by Microsoft for a while now. There was also a lot of opportunity left for simple performance gains that even reduces the complexity of the code. As for why not two separate PRs (HTTP modernization, bundle rework): both were deeply interconnected. A change in one requires modification in the other. Hence the current approach. ## Testing The code has been validated and tested by @TheSparta and me. A large section of the code has been implemented and tested extensively by modders. ### Local 1. Start the game from 127.0.0.1 2. The game starts loading bundles from the mods path ### Remote, full re-aquire 1. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 2. Start the game from LAN IP 3. A folder named `user/cache/bundles` is created ### Remote, partial-aquire (deleted) 1. Ensure all bundles are cached 2. Delete one of the aquired bundles from cache 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, partial-aquire (invalid crc) 1. Ensure all bundles are cached 2. Update a bundle mod with a new bundle on the same path 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, use cache 1. Ensure all bundles are cached 2. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 3. Start the game from LAN IP 4. The game starts loading bundles from the cache path ## Risk assessment In order to reduce friction between releases, this PR introduces a deprecation system. Obsolete classes and methods have been marked deprecated. These will remain available for the current release and continue to function as normal for this release. A warning will be displayed during build when a modder relies on the deprecated functionality. The marked classes and methods are to be removed in the next release. The server-side changes have no impact on modders. ## Deprecation The following classes are affected: - `Aki.Common.Http.Request`: Replaced by `Aki.Common.Http.Request` - `Aki.Common.Http.WebConstants`: Replaced by functionality from `System.Net.Http` - `Aki.Custom.Models.BundleInfo`: Replaced by `Aki.Custom.Models.BundleItem` The following methods are affected: - `Aki.Common.Http.RequestHandler.GetData(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.GetJson(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PostJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PutJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. The deprecated methods and `Aki.Custom.Models.BundleInfo` are self-contained and can be removed independently. The deprecated classes require removal of all deprecated code at once. Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/104 Reviewed-by: TheSparta <thesparta@noreply.dev.sp-tarkov.com> Co-authored-by: Merijn Hendriks <merijn.d.hendriks@gmail.com> Co-committed-by: Merijn Hendriks <merijn.d.hendriks@gmail.com>
2024-03-29 18:43:46 +00:00
{
var error = new Exception("Internal error");
// NOTE: <= is intentional. 0 is send, 1/2/3 is retry
Modernize HTTP v2 (!104) This PR won't affect modders who have already updated their mods to 3.8.0. They just need to re-compile. This is a resubmission of my previous PR (https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/99) with additional code cleanup and fixes. Instead of outright removing the functionality, this time I deprecate it instead (marked for removal in next release). Requires https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/274 to function. ## Overview - HTTP modernization - Adds `Aki.Common.Http.Client`, a replacement for `Aki.Common.Http.Request` and builds on top of `System.Net.Http.HttpClient` - Implements failsafe retries when requesting during busy connections - Improved debugging - Improved performance - Deprecades old request code - Bundle system - Fixes remote downloaded bundles using external IP - Implements functional bundle caching from remote sources - Implements multi-threaded bundle downloads - Implements Unity-compatible bundle format support - Extensive cleanup - Deprecated unneccecary models ## Why? In it's current state, the bundle system is ducktaped together in 2021, fundumentally broken and in desperate need of a cleanup and fixes. The HTTP code hasn't been updated since 2021, and `HttpWebRequest` has been deprecated by Microsoft for a while now. There was also a lot of opportunity left for simple performance gains that even reduces the complexity of the code. As for why not two separate PRs (HTTP modernization, bundle rework): both were deeply interconnected. A change in one requires modification in the other. Hence the current approach. ## Testing The code has been validated and tested by @TheSparta and me. A large section of the code has been implemented and tested extensively by modders. ### Local 1. Start the game from 127.0.0.1 2. The game starts loading bundles from the mods path ### Remote, full re-aquire 1. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 2. Start the game from LAN IP 3. A folder named `user/cache/bundles` is created ### Remote, partial-aquire (deleted) 1. Ensure all bundles are cached 2. Delete one of the aquired bundles from cache 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, partial-aquire (invalid crc) 1. Ensure all bundles are cached 2. Update a bundle mod with a new bundle on the same path 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, use cache 1. Ensure all bundles are cached 2. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 3. Start the game from LAN IP 4. The game starts loading bundles from the cache path ## Risk assessment In order to reduce friction between releases, this PR introduces a deprecation system. Obsolete classes and methods have been marked deprecated. These will remain available for the current release and continue to function as normal for this release. A warning will be displayed during build when a modder relies on the deprecated functionality. The marked classes and methods are to be removed in the next release. The server-side changes have no impact on modders. ## Deprecation The following classes are affected: - `Aki.Common.Http.Request`: Replaced by `Aki.Common.Http.Request` - `Aki.Common.Http.WebConstants`: Replaced by functionality from `System.Net.Http` - `Aki.Custom.Models.BundleInfo`: Replaced by `Aki.Custom.Models.BundleItem` The following methods are affected: - `Aki.Common.Http.RequestHandler.GetData(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.GetJson(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PostJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PutJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. The deprecated methods and `Aki.Custom.Models.BundleInfo` are self-contained and can be removed independently. The deprecated classes require removal of all deprecated code at once. Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/104 Reviewed-by: TheSparta <thesparta@noreply.dev.sp-tarkov.com> Co-authored-by: Merijn Hendriks <merijn.d.hendriks@gmail.com> Co-committed-by: Merijn Hendriks <merijn.d.hendriks@gmail.com>
2024-03-29 18:43:46 +00:00
for (var i = 0; i <= _retries; ++i)
{
try
{
return await SendAsync(method, path, data, compress);
Modernize HTTP v2 (!104) This PR won't affect modders who have already updated their mods to 3.8.0. They just need to re-compile. This is a resubmission of my previous PR (https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/99) with additional code cleanup and fixes. Instead of outright removing the functionality, this time I deprecate it instead (marked for removal in next release). Requires https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/274 to function. ## Overview - HTTP modernization - Adds `Aki.Common.Http.Client`, a replacement for `Aki.Common.Http.Request` and builds on top of `System.Net.Http.HttpClient` - Implements failsafe retries when requesting during busy connections - Improved debugging - Improved performance - Deprecades old request code - Bundle system - Fixes remote downloaded bundles using external IP - Implements functional bundle caching from remote sources - Implements multi-threaded bundle downloads - Implements Unity-compatible bundle format support - Extensive cleanup - Deprecated unneccecary models ## Why? In it's current state, the bundle system is ducktaped together in 2021, fundumentally broken and in desperate need of a cleanup and fixes. The HTTP code hasn't been updated since 2021, and `HttpWebRequest` has been deprecated by Microsoft for a while now. There was also a lot of opportunity left for simple performance gains that even reduces the complexity of the code. As for why not two separate PRs (HTTP modernization, bundle rework): both were deeply interconnected. A change in one requires modification in the other. Hence the current approach. ## Testing The code has been validated and tested by @TheSparta and me. A large section of the code has been implemented and tested extensively by modders. ### Local 1. Start the game from 127.0.0.1 2. The game starts loading bundles from the mods path ### Remote, full re-aquire 1. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 2. Start the game from LAN IP 3. A folder named `user/cache/bundles` is created ### Remote, partial-aquire (deleted) 1. Ensure all bundles are cached 2. Delete one of the aquired bundles from cache 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, partial-aquire (invalid crc) 1. Ensure all bundles are cached 2. Update a bundle mod with a new bundle on the same path 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, use cache 1. Ensure all bundles are cached 2. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 3. Start the game from LAN IP 4. The game starts loading bundles from the cache path ## Risk assessment In order to reduce friction between releases, this PR introduces a deprecation system. Obsolete classes and methods have been marked deprecated. These will remain available for the current release and continue to function as normal for this release. A warning will be displayed during build when a modder relies on the deprecated functionality. The marked classes and methods are to be removed in the next release. The server-side changes have no impact on modders. ## Deprecation The following classes are affected: - `Aki.Common.Http.Request`: Replaced by `Aki.Common.Http.Request` - `Aki.Common.Http.WebConstants`: Replaced by functionality from `System.Net.Http` - `Aki.Custom.Models.BundleInfo`: Replaced by `Aki.Custom.Models.BundleItem` The following methods are affected: - `Aki.Common.Http.RequestHandler.GetData(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.GetJson(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PostJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PutJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. The deprecated methods and `Aki.Custom.Models.BundleInfo` are self-contained and can be removed independently. The deprecated classes require removal of all deprecated code at once. Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/104 Reviewed-by: TheSparta <thesparta@noreply.dev.sp-tarkov.com> Co-authored-by: Merijn Hendriks <merijn.d.hendriks@gmail.com> Co-committed-by: Merijn Hendriks <merijn.d.hendriks@gmail.com>
2024-03-29 18:43:46 +00:00
}
catch (Exception ex)
{
error = ex;
}
}
throw error;
}
public async Task<byte[]> GetAsync(string path)
Modernize HTTP v2 (!104) This PR won't affect modders who have already updated their mods to 3.8.0. They just need to re-compile. This is a resubmission of my previous PR (https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/99) with additional code cleanup and fixes. Instead of outright removing the functionality, this time I deprecate it instead (marked for removal in next release). Requires https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/274 to function. ## Overview - HTTP modernization - Adds `Aki.Common.Http.Client`, a replacement for `Aki.Common.Http.Request` and builds on top of `System.Net.Http.HttpClient` - Implements failsafe retries when requesting during busy connections - Improved debugging - Improved performance - Deprecades old request code - Bundle system - Fixes remote downloaded bundles using external IP - Implements functional bundle caching from remote sources - Implements multi-threaded bundle downloads - Implements Unity-compatible bundle format support - Extensive cleanup - Deprecated unneccecary models ## Why? In it's current state, the bundle system is ducktaped together in 2021, fundumentally broken and in desperate need of a cleanup and fixes. The HTTP code hasn't been updated since 2021, and `HttpWebRequest` has been deprecated by Microsoft for a while now. There was also a lot of opportunity left for simple performance gains that even reduces the complexity of the code. As for why not two separate PRs (HTTP modernization, bundle rework): both were deeply interconnected. A change in one requires modification in the other. Hence the current approach. ## Testing The code has been validated and tested by @TheSparta and me. A large section of the code has been implemented and tested extensively by modders. ### Local 1. Start the game from 127.0.0.1 2. The game starts loading bundles from the mods path ### Remote, full re-aquire 1. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 2. Start the game from LAN IP 3. A folder named `user/cache/bundles` is created ### Remote, partial-aquire (deleted) 1. Ensure all bundles are cached 2. Delete one of the aquired bundles from cache 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, partial-aquire (invalid crc) 1. Ensure all bundles are cached 2. Update a bundle mod with a new bundle on the same path 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, use cache 1. Ensure all bundles are cached 2. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 3. Start the game from LAN IP 4. The game starts loading bundles from the cache path ## Risk assessment In order to reduce friction between releases, this PR introduces a deprecation system. Obsolete classes and methods have been marked deprecated. These will remain available for the current release and continue to function as normal for this release. A warning will be displayed during build when a modder relies on the deprecated functionality. The marked classes and methods are to be removed in the next release. The server-side changes have no impact on modders. ## Deprecation The following classes are affected: - `Aki.Common.Http.Request`: Replaced by `Aki.Common.Http.Request` - `Aki.Common.Http.WebConstants`: Replaced by functionality from `System.Net.Http` - `Aki.Custom.Models.BundleInfo`: Replaced by `Aki.Custom.Models.BundleItem` The following methods are affected: - `Aki.Common.Http.RequestHandler.GetData(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.GetJson(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PostJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PutJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. The deprecated methods and `Aki.Custom.Models.BundleInfo` are self-contained and can be removed independently. The deprecated classes require removal of all deprecated code at once. Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/104 Reviewed-by: TheSparta <thesparta@noreply.dev.sp-tarkov.com> Co-authored-by: Merijn Hendriks <merijn.d.hendriks@gmail.com> Co-committed-by: Merijn Hendriks <merijn.d.hendriks@gmail.com>
2024-03-29 18:43:46 +00:00
{
return await SendWithRetriesAsync(HttpMethod.Get, path, null);
}
Modernize HTTP v2 (!104) This PR won't affect modders who have already updated their mods to 3.8.0. They just need to re-compile. This is a resubmission of my previous PR (https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/99) with additional code cleanup and fixes. Instead of outright removing the functionality, this time I deprecate it instead (marked for removal in next release). Requires https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/274 to function. ## Overview - HTTP modernization - Adds `Aki.Common.Http.Client`, a replacement for `Aki.Common.Http.Request` and builds on top of `System.Net.Http.HttpClient` - Implements failsafe retries when requesting during busy connections - Improved debugging - Improved performance - Deprecades old request code - Bundle system - Fixes remote downloaded bundles using external IP - Implements functional bundle caching from remote sources - Implements multi-threaded bundle downloads - Implements Unity-compatible bundle format support - Extensive cleanup - Deprecated unneccecary models ## Why? In it's current state, the bundle system is ducktaped together in 2021, fundumentally broken and in desperate need of a cleanup and fixes. The HTTP code hasn't been updated since 2021, and `HttpWebRequest` has been deprecated by Microsoft for a while now. There was also a lot of opportunity left for simple performance gains that even reduces the complexity of the code. As for why not two separate PRs (HTTP modernization, bundle rework): both were deeply interconnected. A change in one requires modification in the other. Hence the current approach. ## Testing The code has been validated and tested by @TheSparta and me. A large section of the code has been implemented and tested extensively by modders. ### Local 1. Start the game from 127.0.0.1 2. The game starts loading bundles from the mods path ### Remote, full re-aquire 1. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 2. Start the game from LAN IP 3. A folder named `user/cache/bundles` is created ### Remote, partial-aquire (deleted) 1. Ensure all bundles are cached 2. Delete one of the aquired bundles from cache 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, partial-aquire (invalid crc) 1. Ensure all bundles are cached 2. Update a bundle mod with a new bundle on the same path 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, use cache 1. Ensure all bundles are cached 2. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 3. Start the game from LAN IP 4. The game starts loading bundles from the cache path ## Risk assessment In order to reduce friction between releases, this PR introduces a deprecation system. Obsolete classes and methods have been marked deprecated. These will remain available for the current release and continue to function as normal for this release. A warning will be displayed during build when a modder relies on the deprecated functionality. The marked classes and methods are to be removed in the next release. The server-side changes have no impact on modders. ## Deprecation The following classes are affected: - `Aki.Common.Http.Request`: Replaced by `Aki.Common.Http.Request` - `Aki.Common.Http.WebConstants`: Replaced by functionality from `System.Net.Http` - `Aki.Custom.Models.BundleInfo`: Replaced by `Aki.Custom.Models.BundleItem` The following methods are affected: - `Aki.Common.Http.RequestHandler.GetData(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.GetJson(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PostJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PutJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. The deprecated methods and `Aki.Custom.Models.BundleInfo` are self-contained and can be removed independently. The deprecated classes require removal of all deprecated code at once. Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/104 Reviewed-by: TheSparta <thesparta@noreply.dev.sp-tarkov.com> Co-authored-by: Merijn Hendriks <merijn.d.hendriks@gmail.com> Co-committed-by: Merijn Hendriks <merijn.d.hendriks@gmail.com>
2024-03-29 18:43:46 +00:00
public byte[] Get(string path)
{
return Task.Run(() => GetAsync(path)).Result;
}
Modernize HTTP v2 (!104) This PR won't affect modders who have already updated their mods to 3.8.0. They just need to re-compile. This is a resubmission of my previous PR (https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/99) with additional code cleanup and fixes. Instead of outright removing the functionality, this time I deprecate it instead (marked for removal in next release). Requires https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/274 to function. ## Overview - HTTP modernization - Adds `Aki.Common.Http.Client`, a replacement for `Aki.Common.Http.Request` and builds on top of `System.Net.Http.HttpClient` - Implements failsafe retries when requesting during busy connections - Improved debugging - Improved performance - Deprecades old request code - Bundle system - Fixes remote downloaded bundles using external IP - Implements functional bundle caching from remote sources - Implements multi-threaded bundle downloads - Implements Unity-compatible bundle format support - Extensive cleanup - Deprecated unneccecary models ## Why? In it's current state, the bundle system is ducktaped together in 2021, fundumentally broken and in desperate need of a cleanup and fixes. The HTTP code hasn't been updated since 2021, and `HttpWebRequest` has been deprecated by Microsoft for a while now. There was also a lot of opportunity left for simple performance gains that even reduces the complexity of the code. As for why not two separate PRs (HTTP modernization, bundle rework): both were deeply interconnected. A change in one requires modification in the other. Hence the current approach. ## Testing The code has been validated and tested by @TheSparta and me. A large section of the code has been implemented and tested extensively by modders. ### Local 1. Start the game from 127.0.0.1 2. The game starts loading bundles from the mods path ### Remote, full re-aquire 1. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 2. Start the game from LAN IP 3. A folder named `user/cache/bundles` is created ### Remote, partial-aquire (deleted) 1. Ensure all bundles are cached 2. Delete one of the aquired bundles from cache 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, partial-aquire (invalid crc) 1. Ensure all bundles are cached 2. Update a bundle mod with a new bundle on the same path 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, use cache 1. Ensure all bundles are cached 2. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 3. Start the game from LAN IP 4. The game starts loading bundles from the cache path ## Risk assessment In order to reduce friction between releases, this PR introduces a deprecation system. Obsolete classes and methods have been marked deprecated. These will remain available for the current release and continue to function as normal for this release. A warning will be displayed during build when a modder relies on the deprecated functionality. The marked classes and methods are to be removed in the next release. The server-side changes have no impact on modders. ## Deprecation The following classes are affected: - `Aki.Common.Http.Request`: Replaced by `Aki.Common.Http.Request` - `Aki.Common.Http.WebConstants`: Replaced by functionality from `System.Net.Http` - `Aki.Custom.Models.BundleInfo`: Replaced by `Aki.Custom.Models.BundleItem` The following methods are affected: - `Aki.Common.Http.RequestHandler.GetData(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.GetJson(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PostJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PutJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. The deprecated methods and `Aki.Custom.Models.BundleInfo` are self-contained and can be removed independently. The deprecated classes require removal of all deprecated code at once. Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/104 Reviewed-by: TheSparta <thesparta@noreply.dev.sp-tarkov.com> Co-authored-by: Merijn Hendriks <merijn.d.hendriks@gmail.com> Co-committed-by: Merijn Hendriks <merijn.d.hendriks@gmail.com>
2024-03-29 18:43:46 +00:00
public async Task<byte[]> PostAsync(string path, byte[] data, bool compress = true)
{
return await SendWithRetriesAsync(HttpMethod.Post, path, data, compress);
Modernize HTTP v2 (!104) This PR won't affect modders who have already updated their mods to 3.8.0. They just need to re-compile. This is a resubmission of my previous PR (https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/99) with additional code cleanup and fixes. Instead of outright removing the functionality, this time I deprecate it instead (marked for removal in next release). Requires https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/274 to function. ## Overview - HTTP modernization - Adds `Aki.Common.Http.Client`, a replacement for `Aki.Common.Http.Request` and builds on top of `System.Net.Http.HttpClient` - Implements failsafe retries when requesting during busy connections - Improved debugging - Improved performance - Deprecades old request code - Bundle system - Fixes remote downloaded bundles using external IP - Implements functional bundle caching from remote sources - Implements multi-threaded bundle downloads - Implements Unity-compatible bundle format support - Extensive cleanup - Deprecated unneccecary models ## Why? In it's current state, the bundle system is ducktaped together in 2021, fundumentally broken and in desperate need of a cleanup and fixes. The HTTP code hasn't been updated since 2021, and `HttpWebRequest` has been deprecated by Microsoft for a while now. There was also a lot of opportunity left for simple performance gains that even reduces the complexity of the code. As for why not two separate PRs (HTTP modernization, bundle rework): both were deeply interconnected. A change in one requires modification in the other. Hence the current approach. ## Testing The code has been validated and tested by @TheSparta and me. A large section of the code has been implemented and tested extensively by modders. ### Local 1. Start the game from 127.0.0.1 2. The game starts loading bundles from the mods path ### Remote, full re-aquire 1. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 2. Start the game from LAN IP 3. A folder named `user/cache/bundles` is created ### Remote, partial-aquire (deleted) 1. Ensure all bundles are cached 2. Delete one of the aquired bundles from cache 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, partial-aquire (invalid crc) 1. Ensure all bundles are cached 2. Update a bundle mod with a new bundle on the same path 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, use cache 1. Ensure all bundles are cached 2. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 3. Start the game from LAN IP 4. The game starts loading bundles from the cache path ## Risk assessment In order to reduce friction between releases, this PR introduces a deprecation system. Obsolete classes and methods have been marked deprecated. These will remain available for the current release and continue to function as normal for this release. A warning will be displayed during build when a modder relies on the deprecated functionality. The marked classes and methods are to be removed in the next release. The server-side changes have no impact on modders. ## Deprecation The following classes are affected: - `Aki.Common.Http.Request`: Replaced by `Aki.Common.Http.Request` - `Aki.Common.Http.WebConstants`: Replaced by functionality from `System.Net.Http` - `Aki.Custom.Models.BundleInfo`: Replaced by `Aki.Custom.Models.BundleItem` The following methods are affected: - `Aki.Common.Http.RequestHandler.GetData(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.GetJson(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PostJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PutJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. The deprecated methods and `Aki.Custom.Models.BundleInfo` are self-contained and can be removed independently. The deprecated classes require removal of all deprecated code at once. Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/104 Reviewed-by: TheSparta <thesparta@noreply.dev.sp-tarkov.com> Co-authored-by: Merijn Hendriks <merijn.d.hendriks@gmail.com> Co-committed-by: Merijn Hendriks <merijn.d.hendriks@gmail.com>
2024-03-29 18:43:46 +00:00
}
public byte[] Post(string path, byte[] data, bool compress = true)
Modernize HTTP v2 (!104) This PR won't affect modders who have already updated their mods to 3.8.0. They just need to re-compile. This is a resubmission of my previous PR (https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/99) with additional code cleanup and fixes. Instead of outright removing the functionality, this time I deprecate it instead (marked for removal in next release). Requires https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/274 to function. ## Overview - HTTP modernization - Adds `Aki.Common.Http.Client`, a replacement for `Aki.Common.Http.Request` and builds on top of `System.Net.Http.HttpClient` - Implements failsafe retries when requesting during busy connections - Improved debugging - Improved performance - Deprecades old request code - Bundle system - Fixes remote downloaded bundles using external IP - Implements functional bundle caching from remote sources - Implements multi-threaded bundle downloads - Implements Unity-compatible bundle format support - Extensive cleanup - Deprecated unneccecary models ## Why? In it's current state, the bundle system is ducktaped together in 2021, fundumentally broken and in desperate need of a cleanup and fixes. The HTTP code hasn't been updated since 2021, and `HttpWebRequest` has been deprecated by Microsoft for a while now. There was also a lot of opportunity left for simple performance gains that even reduces the complexity of the code. As for why not two separate PRs (HTTP modernization, bundle rework): both were deeply interconnected. A change in one requires modification in the other. Hence the current approach. ## Testing The code has been validated and tested by @TheSparta and me. A large section of the code has been implemented and tested extensively by modders. ### Local 1. Start the game from 127.0.0.1 2. The game starts loading bundles from the mods path ### Remote, full re-aquire 1. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 2. Start the game from LAN IP 3. A folder named `user/cache/bundles` is created ### Remote, partial-aquire (deleted) 1. Ensure all bundles are cached 2. Delete one of the aquired bundles from cache 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, partial-aquire (invalid crc) 1. Ensure all bundles are cached 2. Update a bundle mod with a new bundle on the same path 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, use cache 1. Ensure all bundles are cached 2. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 3. Start the game from LAN IP 4. The game starts loading bundles from the cache path ## Risk assessment In order to reduce friction between releases, this PR introduces a deprecation system. Obsolete classes and methods have been marked deprecated. These will remain available for the current release and continue to function as normal for this release. A warning will be displayed during build when a modder relies on the deprecated functionality. The marked classes and methods are to be removed in the next release. The server-side changes have no impact on modders. ## Deprecation The following classes are affected: - `Aki.Common.Http.Request`: Replaced by `Aki.Common.Http.Request` - `Aki.Common.Http.WebConstants`: Replaced by functionality from `System.Net.Http` - `Aki.Custom.Models.BundleInfo`: Replaced by `Aki.Custom.Models.BundleItem` The following methods are affected: - `Aki.Common.Http.RequestHandler.GetData(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.GetJson(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PostJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PutJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. The deprecated methods and `Aki.Custom.Models.BundleInfo` are self-contained and can be removed independently. The deprecated classes require removal of all deprecated code at once. Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/104 Reviewed-by: TheSparta <thesparta@noreply.dev.sp-tarkov.com> Co-authored-by: Merijn Hendriks <merijn.d.hendriks@gmail.com> Co-committed-by: Merijn Hendriks <merijn.d.hendriks@gmail.com>
2024-03-29 18:43:46 +00:00
{
return Task.Run(() => PostAsync(path, data, compress)).Result;
}
Modernize HTTP v2 (!104) This PR won't affect modders who have already updated their mods to 3.8.0. They just need to re-compile. This is a resubmission of my previous PR (https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/99) with additional code cleanup and fixes. Instead of outright removing the functionality, this time I deprecate it instead (marked for removal in next release). Requires https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/274 to function. ## Overview - HTTP modernization - Adds `Aki.Common.Http.Client`, a replacement for `Aki.Common.Http.Request` and builds on top of `System.Net.Http.HttpClient` - Implements failsafe retries when requesting during busy connections - Improved debugging - Improved performance - Deprecades old request code - Bundle system - Fixes remote downloaded bundles using external IP - Implements functional bundle caching from remote sources - Implements multi-threaded bundle downloads - Implements Unity-compatible bundle format support - Extensive cleanup - Deprecated unneccecary models ## Why? In it's current state, the bundle system is ducktaped together in 2021, fundumentally broken and in desperate need of a cleanup and fixes. The HTTP code hasn't been updated since 2021, and `HttpWebRequest` has been deprecated by Microsoft for a while now. There was also a lot of opportunity left for simple performance gains that even reduces the complexity of the code. As for why not two separate PRs (HTTP modernization, bundle rework): both were deeply interconnected. A change in one requires modification in the other. Hence the current approach. ## Testing The code has been validated and tested by @TheSparta and me. A large section of the code has been implemented and tested extensively by modders. ### Local 1. Start the game from 127.0.0.1 2. The game starts loading bundles from the mods path ### Remote, full re-aquire 1. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 2. Start the game from LAN IP 3. A folder named `user/cache/bundles` is created ### Remote, partial-aquire (deleted) 1. Ensure all bundles are cached 2. Delete one of the aquired bundles from cache 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, partial-aquire (invalid crc) 1. Ensure all bundles are cached 2. Update a bundle mod with a new bundle on the same path 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, use cache 1. Ensure all bundles are cached 2. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 3. Start the game from LAN IP 4. The game starts loading bundles from the cache path ## Risk assessment In order to reduce friction between releases, this PR introduces a deprecation system. Obsolete classes and methods have been marked deprecated. These will remain available for the current release and continue to function as normal for this release. A warning will be displayed during build when a modder relies on the deprecated functionality. The marked classes and methods are to be removed in the next release. The server-side changes have no impact on modders. ## Deprecation The following classes are affected: - `Aki.Common.Http.Request`: Replaced by `Aki.Common.Http.Request` - `Aki.Common.Http.WebConstants`: Replaced by functionality from `System.Net.Http` - `Aki.Custom.Models.BundleInfo`: Replaced by `Aki.Custom.Models.BundleItem` The following methods are affected: - `Aki.Common.Http.RequestHandler.GetData(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.GetJson(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PostJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PutJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. The deprecated methods and `Aki.Custom.Models.BundleInfo` are self-contained and can be removed independently. The deprecated classes require removal of all deprecated code at once. Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/104 Reviewed-by: TheSparta <thesparta@noreply.dev.sp-tarkov.com> Co-authored-by: Merijn Hendriks <merijn.d.hendriks@gmail.com> Co-committed-by: Merijn Hendriks <merijn.d.hendriks@gmail.com>
2024-03-29 18:43:46 +00:00
// NOTE: returns status code as bytes
public async Task<byte[]> PutAsync(string path, byte[] data, bool compress = true)
{
return await SendWithRetriesAsync(HttpMethod.Post, path, data, compress);
}
Modernize HTTP v2 (!104) This PR won't affect modders who have already updated their mods to 3.8.0. They just need to re-compile. This is a resubmission of my previous PR (https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/99) with additional code cleanup and fixes. Instead of outright removing the functionality, this time I deprecate it instead (marked for removal in next release). Requires https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/274 to function. ## Overview - HTTP modernization - Adds `Aki.Common.Http.Client`, a replacement for `Aki.Common.Http.Request` and builds on top of `System.Net.Http.HttpClient` - Implements failsafe retries when requesting during busy connections - Improved debugging - Improved performance - Deprecades old request code - Bundle system - Fixes remote downloaded bundles using external IP - Implements functional bundle caching from remote sources - Implements multi-threaded bundle downloads - Implements Unity-compatible bundle format support - Extensive cleanup - Deprecated unneccecary models ## Why? In it's current state, the bundle system is ducktaped together in 2021, fundumentally broken and in desperate need of a cleanup and fixes. The HTTP code hasn't been updated since 2021, and `HttpWebRequest` has been deprecated by Microsoft for a while now. There was also a lot of opportunity left for simple performance gains that even reduces the complexity of the code. As for why not two separate PRs (HTTP modernization, bundle rework): both were deeply interconnected. A change in one requires modification in the other. Hence the current approach. ## Testing The code has been validated and tested by @TheSparta and me. A large section of the code has been implemented and tested extensively by modders. ### Local 1. Start the game from 127.0.0.1 2. The game starts loading bundles from the mods path ### Remote, full re-aquire 1. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 2. Start the game from LAN IP 3. A folder named `user/cache/bundles` is created ### Remote, partial-aquire (deleted) 1. Ensure all bundles are cached 2. Delete one of the aquired bundles from cache 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, partial-aquire (invalid crc) 1. Ensure all bundles are cached 2. Update a bundle mod with a new bundle on the same path 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, use cache 1. Ensure all bundles are cached 2. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 3. Start the game from LAN IP 4. The game starts loading bundles from the cache path ## Risk assessment In order to reduce friction between releases, this PR introduces a deprecation system. Obsolete classes and methods have been marked deprecated. These will remain available for the current release and continue to function as normal for this release. A warning will be displayed during build when a modder relies on the deprecated functionality. The marked classes and methods are to be removed in the next release. The server-side changes have no impact on modders. ## Deprecation The following classes are affected: - `Aki.Common.Http.Request`: Replaced by `Aki.Common.Http.Request` - `Aki.Common.Http.WebConstants`: Replaced by functionality from `System.Net.Http` - `Aki.Custom.Models.BundleInfo`: Replaced by `Aki.Custom.Models.BundleItem` The following methods are affected: - `Aki.Common.Http.RequestHandler.GetData(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.GetJson(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PostJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PutJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. The deprecated methods and `Aki.Custom.Models.BundleInfo` are self-contained and can be removed independently. The deprecated classes require removal of all deprecated code at once. Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/104 Reviewed-by: TheSparta <thesparta@noreply.dev.sp-tarkov.com> Co-authored-by: Merijn Hendriks <merijn.d.hendriks@gmail.com> Co-committed-by: Merijn Hendriks <merijn.d.hendriks@gmail.com>
2024-03-29 18:43:46 +00:00
// NOTE: returns status code as bytes
public byte[] Put(string path, byte[] data, bool compress = true)
{
return Task.Run(() => PutAsync(path, data, compress)).Result;
Modernize HTTP v2 (!104) This PR won't affect modders who have already updated their mods to 3.8.0. They just need to re-compile. This is a resubmission of my previous PR (https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/99) with additional code cleanup and fixes. Instead of outright removing the functionality, this time I deprecate it instead (marked for removal in next release). Requires https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/274 to function. ## Overview - HTTP modernization - Adds `Aki.Common.Http.Client`, a replacement for `Aki.Common.Http.Request` and builds on top of `System.Net.Http.HttpClient` - Implements failsafe retries when requesting during busy connections - Improved debugging - Improved performance - Deprecades old request code - Bundle system - Fixes remote downloaded bundles using external IP - Implements functional bundle caching from remote sources - Implements multi-threaded bundle downloads - Implements Unity-compatible bundle format support - Extensive cleanup - Deprecated unneccecary models ## Why? In it's current state, the bundle system is ducktaped together in 2021, fundumentally broken and in desperate need of a cleanup and fixes. The HTTP code hasn't been updated since 2021, and `HttpWebRequest` has been deprecated by Microsoft for a while now. There was also a lot of opportunity left for simple performance gains that even reduces the complexity of the code. As for why not two separate PRs (HTTP modernization, bundle rework): both were deeply interconnected. A change in one requires modification in the other. Hence the current approach. ## Testing The code has been validated and tested by @TheSparta and me. A large section of the code has been implemented and tested extensively by modders. ### Local 1. Start the game from 127.0.0.1 2. The game starts loading bundles from the mods path ### Remote, full re-aquire 1. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 2. Start the game from LAN IP 3. A folder named `user/cache/bundles` is created ### Remote, partial-aquire (deleted) 1. Ensure all bundles are cached 2. Delete one of the aquired bundles from cache 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, partial-aquire (invalid crc) 1. Ensure all bundles are cached 2. Update a bundle mod with a new bundle on the same path 3. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 4. Start the game from LAN IP 5. The bundle is redownloaded ### Remote, use cache 1. Ensure all bundles are cached 2. Start the server from LAN IP (http.json, set host to `cmd > ipconfig` address, example: `192.168.178.32`) 3. Start the game from LAN IP 4. The game starts loading bundles from the cache path ## Risk assessment In order to reduce friction between releases, this PR introduces a deprecation system. Obsolete classes and methods have been marked deprecated. These will remain available for the current release and continue to function as normal for this release. A warning will be displayed during build when a modder relies on the deprecated functionality. The marked classes and methods are to be removed in the next release. The server-side changes have no impact on modders. ## Deprecation The following classes are affected: - `Aki.Common.Http.Request`: Replaced by `Aki.Common.Http.Request` - `Aki.Common.Http.WebConstants`: Replaced by functionality from `System.Net.Http` - `Aki.Custom.Models.BundleInfo`: Replaced by `Aki.Custom.Models.BundleItem` The following methods are affected: - `Aki.Common.Http.RequestHandler.GetData(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.GetJson(path, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PostJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. - `Aki.Common.Http.RequestHandler.PutJson(path, json, hasHost)`: `hasHost` enables connection outside intended host. The deprecated methods and `Aki.Custom.Models.BundleInfo` are self-contained and can be removed independently. The deprecated classes require removal of all deprecated code at once. Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/104 Reviewed-by: TheSparta <thesparta@noreply.dev.sp-tarkov.com> Co-authored-by: Merijn Hendriks <merijn.d.hendriks@gmail.com> Co-committed-by: Merijn Hendriks <merijn.d.hendriks@gmail.com>
2024-03-29 18:43:46 +00:00
}
public void Dispose()
{
_httpv.Dispose();
}
}
}