shoko/Protocols/HttpProtoHandler.cs

33 lines
995 B
C#
Raw Normal View History

2023-10-02 18:49:24 +00:00
using System.Reflection;
namespace Shoko;
[Protocol("http")]
[Protocol("https")]
class HttpProtoHandler : ProtoHandler
{
public HttpProtoHandler(Uri url)
{
URL = url;
}
public override void Load()
{
HttpClient client = new(){
BaseAddress = URL
};
client.DefaultRequestHeaders.UserAgent.ParseAdd("Mozilla/5.0 shoko/" + Assembly.GetExecutingAssembly().GetName().Version.ToString());
var response = client.GetAsync(URL).Result;
Headers = response.Content.Headers;
Content = response.Content.ReadAsStream();
MediaType = response.Content.Headers.ContentType.MediaType ?? "text/html";
MediaTypeParams = response.Content.Headers.ContentType.Parameters.Select(x => new KeyValuePair<string, string>(x.Name, x.Value));
Status = string.Format("{0} {1}", (int)response.StatusCode, response.StatusCode.ToString());
Loaded = true;
}
public override void Render()
{
}
}