Updated Bnet Server.
Port From (https://github.com/TrinityCore/TrinityCore)
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
// Copyright (c) CypherCore <http://github.com/CypherCore> All rights reserved.
|
||||
// Licensed under the GNU GENERAL PUBLIC LICENSE. See LICENSE file in the project root for full license information.
|
||||
|
||||
using Framework.Networking.Http;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
@@ -15,14 +17,14 @@ namespace Framework.Web
|
||||
public string Method { get; set; }
|
||||
public string Path { get; set; }
|
||||
public string Type { get; set; }
|
||||
public string Host { get; set; }
|
||||
public string DeviceId { get; set; }
|
||||
public string Authorization { get; set; }
|
||||
public string ContentType { get; set; }
|
||||
public int ContentLength { get; set; }
|
||||
public string AcceptLanguage { get; set; }
|
||||
public string Accept { get; set; }
|
||||
public string UserAgent { get; set; }
|
||||
public string Content { get; set; }
|
||||
public string Content { get; set; } = "";
|
||||
public HttpStatusCode Status { get; set; } = HttpStatusCode.OK;
|
||||
public string Cookie { get; set; }
|
||||
public bool KeepAlive { get; set; }
|
||||
public string Host { get; set; }
|
||||
}
|
||||
|
||||
public enum HttpCode
|
||||
@@ -35,43 +37,41 @@ namespace Framework.Web
|
||||
|
||||
public class HttpHelper
|
||||
{
|
||||
public static byte[] CreateResponse(HttpCode httpCode, string content, bool closeConnection = false)
|
||||
public static byte[] CreateResponse(RequestContext requestContext)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
|
||||
using (var sw = new StringWriter(sb))
|
||||
{
|
||||
sw.WriteLine($"HTTP/1.1 {(int)httpCode} {httpCode}");
|
||||
sw.WriteLine($"HTTP/1.1 {(int)requestContext.response.Status} {requestContext.response.Status}");
|
||||
sw.WriteLine($"Content-Length: {requestContext.response.Content.Length}");
|
||||
|
||||
//sw.WriteLine($"Date: {DateTime.Now.ToUniversalTime():r}");
|
||||
//sw.WriteLine("Server: Arctium-Emulation");
|
||||
//sw.WriteLine("Retry-After: 600");
|
||||
sw.WriteLine($"Content-Length: {content.Length}");
|
||||
//sw.WriteLine("Vary: Accept-Encoding");
|
||||
|
||||
if (closeConnection)
|
||||
if (!requestContext.response.KeepAlive)
|
||||
sw.WriteLine("Connection: close");
|
||||
|
||||
sw.WriteLine("Content-Type: application/json;charset=UTF-8");
|
||||
if (!requestContext.response.Cookie.IsEmpty())
|
||||
sw.WriteLine($"Set-Cookie: {requestContext.response.Cookie}");
|
||||
|
||||
sw.WriteLine($"Content-Type: {requestContext.response.ContentType}");
|
||||
sw.WriteLine();
|
||||
|
||||
sw.WriteLine(content);
|
||||
sw.WriteLine(requestContext.response.Content);
|
||||
}
|
||||
|
||||
return Encoding.UTF8.GetBytes(sb.ToString());
|
||||
}
|
||||
|
||||
public static HttpHeader ParseRequest(byte[] data, int length)
|
||||
public static bool ParseRequest(byte[] data, int length, out HttpHeader httpHeader)
|
||||
{
|
||||
var headerValues = new Dictionary<string, object>();
|
||||
var header = new HttpHeader();
|
||||
httpHeader = new HttpHeader();
|
||||
|
||||
using (var sr = new StreamReader(new MemoryStream(data, 0, length)))
|
||||
{
|
||||
var info = sr.ReadLine().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
if (info.Length != 3)
|
||||
return null;
|
||||
return false;
|
||||
|
||||
headerValues.Add("method", info[0]);
|
||||
headerValues.Add("path", info[1]);
|
||||
@@ -113,13 +113,13 @@ namespace Framework.Web
|
||||
if (headerValues.TryGetValue(f.Name.ToLower(), out val))
|
||||
{
|
||||
if (f.PropertyType == typeof(int))
|
||||
f.SetValue(header, Convert.ChangeType(Convert.ToInt32(val), f.PropertyType));
|
||||
f.SetValue(httpHeader, Convert.ChangeType(Convert.ToInt32(val), f.PropertyType));
|
||||
else
|
||||
f.SetValue(header, Convert.ChangeType(val, f.PropertyType));
|
||||
f.SetValue(httpHeader, Convert.ChangeType(val, f.PropertyType));
|
||||
}
|
||||
}
|
||||
|
||||
return header;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user