Files
SPT-Server-Build/Libraries/SPTarkov.Server.Core/Helpers/HttpServerHelper.cs
T
Cj 628a31f07f Helper warning fixes (#545)
* Helper warning fixes

* Make AI happy
2025-08-12 19:06:46 +00:00

70 lines
1.9 KiB
C#

using System.Collections.Frozen;
using Microsoft.AspNetCore.Http;
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Models.Spt.Config;
using SPTarkov.Server.Core.Servers;
namespace SPTarkov.Server.Core.Helpers;
[Injectable(InjectionType.Singleton)]
public class HttpServerHelper(ConfigServer configServer)
{
protected readonly HttpConfig HttpConfig = configServer.GetConfig<HttpConfig>();
protected readonly FrozenDictionary<string, string> Mime = new Dictionary<string, string>
{
{ "css", "text/css" },
{ "bin", "application/octet-stream" },
{ "html", "text/html" },
{ "jpg", "image/jpeg" },
{ "js", "text/javascript" },
{ "json", "application/json" },
{ "png", "image/png" },
{ "svg", "image/svg+xml" },
{ "txt", "text/plain" },
}.ToFrozenDictionary();
public string? GetMimeText(string key)
{
return Mime.GetValueOrDefault(key);
}
/// <summary>
/// Combine ip and port into address
/// </summary>
/// <returns>URI</returns>
public string BuildUrl()
{
return $"{HttpConfig.BackendIp}:{HttpConfig.BackendPort}";
}
/// <summary>
/// Prepend http to the url:port
/// </summary>
/// <returns>URI</returns>
public string GetBackendUrl()
{
return $"https://{BuildUrl()}";
}
/// <summary>
/// Get websocket url + port
/// </summary>
/// <returns>wss:// address</returns>
public string GetWebsocketUrl()
{
return $"wss://{BuildUrl()}";
}
public void SendTextJson(HttpResponse resp, object output)
{
resp.Headers.Append("Content-Type", Mime["json"]);
resp.StatusCode = 200;
// TODO: figure this one out
// resp.writeHead(200, "OK", {
// "Content-Type": this.mime.json
// });
// resp.end(output);
}
}