提交 c9619c0f 编写于 作者: JasonWcx's avatar JasonWcx

加入默认首页

上级 ce766dae
......@@ -9,7 +9,7 @@ namespace Mozi.HttpEmbedded
{
public static AccessManager _access;
private List<string> _blacklist = new List<string>();
private readonly List<string> _blacklist = new List<string>();
public static AccessManager Instance
{
......
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<title>模板示例页面</title>
<title>HomePage</title>
<meta http-equiv="content-type" charset="UTF-8">
<meta http-equiv="Authorization" content="Jason" />
<meta name="viewport" content="width=device-width,height=device-height,initial-scale=1,maximum-scale=1,user-scalable=no">
......@@ -39,10 +39,13 @@
h4 {
font-size: 0.67rem;
}
p, p > * {
font-size: 0.78rem;
}
</style>
</head>
<body>
<h1 style="text-align:center;display:block">欢迎使用Mozi.HttpEmbedded${Info.VersionName}</h1>
<hr style="height:1px;">
<h1 style="text-align:center;display:block;color:brown;line-height:2rem;vertical-align:central;">欢迎使用 Mozi.HttpEmbedded${Info.VersionName} </h1>
<hr style="border:0;border-bottom:1px solid #dedede;margin:0 0.89rem;">
</body>
</html>
\ No newline at end of file
using Mozi.HttpEmbedded.Encode;
using System.Reflection;
namespace Mozi.HttpEmbedded.Docment
{
public class DocLoader
{
public static string Load(string docName)
{
Assembly ass = Assembly.GetExecutingAssembly();
var resName = ass.GetName().Name + ".Document." + docName;
var stream=ass.GetManifestResourceStream(resName);
byte[] buffer = new byte[stream.Length];
stream.Read(buffer, 0, buffer.Length);
stream.Close();
return StringEncoder.Decode(buffer);
}
}
}
......@@ -36,11 +36,14 @@
h4 {
font-size: 0.67rem;
}
p, p > * {
font-size: 0.78rem;
}
</style>
</head>
<body style="padding:0 0.6rem;">
<h1 style="color: brown">${Error.Code}-${Error.Title}</h1>
<hr style="color:#dedede;"/>
<hr style="border: 0; border-bottom: 1px solid #dedede;"/>
<p><strong>时间:</strong>${Error.Time}</p>
<p><strong>内容:</strong>${Error.Description}</p>
<p><strong>源:</strong>${Error.Source}</p>
......
......@@ -206,6 +206,7 @@ namespace Mozi.HttpEmbedded
{
req.Post=UrlEncoder.ParseQuery(StringEncoder.Decode(data));
}
//TODO 文件流应写入缓冲区
/// <summary>
/// 分析请求体 multipart/form-data
/// </summary>
......
......@@ -4,6 +4,7 @@ using Mozi.HttpEmbedded.Auth;
using Mozi.HttpEmbedded.Cert;
using Mozi.HttpEmbedded.Common;
using Mozi.HttpEmbedded.Compress;
using Mozi.HttpEmbedded.Docment;
using Mozi.HttpEmbedded.Page;
using Mozi.HttpEmbedded.Source;
......@@ -161,7 +162,8 @@ namespace Mozi.HttpEmbedded
{
context.Request = HttpRequest.Parse(args.Data);
//TODO HTTP/1.1 通过Connection控制连接 服务器同时对连接进行监测 保证服务器效率
//TODO 此处应判断Content-Length然后继续读流
//DONE 此处应判断Content-Length然后继续读流
//TODO 如何解决文件传输内存占用过大的问题
long contentLength = -1;
if (context.Request.Headers.Contains(HeaderProperty.ContentLength.PropertyName)){
......@@ -190,6 +192,14 @@ namespace Mozi.HttpEmbedded
}
catch (Exception ex)
{
#region 测试片段,模板引擎开发好以后注释掉
string doc = DocLoader.Load("Error.html");
doc = doc.Replace("${Error.Code}", StatusCode.InternalServerError.Code.ToString());
doc=doc.Replace("${Error.Description}", ex.StackTrace ?? ex.StackTrace.ToString());
#endregion
context.Response.Write(doc);
context.Response.Headers.Add(HeaderProperty.ContentType, Mime.GetContentType("html"));
sc = StatusCode.InternalServerError;
Log.Error(ex.Message+":"+ex.StackTrace??"");
}
......@@ -198,7 +208,7 @@ namespace Mozi.HttpEmbedded
}
//最后响应数据
//if (args.Socket != null && args.Socket.Connected)
if (args.Socket != null && args.Socket.Connected)
{
context.Response.AddHeader(HeaderProperty.Server, ServerName);
context.Response.SetStatus(sc);
......@@ -248,8 +258,14 @@ namespace Mozi.HttpEmbedded
//判断资源类型
bool isStatic = st.IsStatic(fileext);
context.Response.Headers.Add(HeaderProperty.ContentType, contenttype);
if (context.Request.Path == "/")
{
context.Response.Write(DocLoader.Load("DefaultHome.html"));
context.Response.Headers.Add(HeaderProperty.ContentType, Mime.GetContentType("html"));
return StatusCode.Success;
}
//静态文件处理
if (st.Enabled && isStatic)
else if (st.Enabled && isStatic)
{
//响应静态文件
if (st.Exists(path, ""))
......@@ -340,12 +356,7 @@ namespace Mozi.HttpEmbedded
if (router.Match(context.Request.Path) != null)
{
object result=null;
try
{
result = router.Invoke(context);
}catch(Exception ex){
}
result = router.Invoke(context);
if (result != null)
{
context.Response.Write(result.ToString());
......
......@@ -70,6 +70,7 @@
<Compile Include="Cert\TransmitionCryptType.cs" />
<Compile Include="Common\UrlTree.cs" />
<Compile Include="Cookie\CookieManager.cs" />
<Compile Include="Document\DocLoader.cs" />
<Compile Include="Encode\HtmlEncoder.cs" />
<Compile Include="Page\SystemApi.cs" />
<Compile Include="Serialize\ISerializer.cs" />
......@@ -152,9 +153,9 @@
<Compile Include="WebService\SOAP.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Docment\DefaultHome.html" />
<Content Include="Docment\Error.html" />
<Content Include="Docment\ExamplePage.html" />
<EmbeddedResource Include="Document\DefaultHome.html" />
<EmbeddedResource Include="Document\Error.html" />
<EmbeddedResource Include="Document\ExamplePage.html" />
<Content Include="Source\mime.data" />
<Content Include="WebDav\Icon.png" />
</ItemGroup>
......
......@@ -10,6 +10,11 @@
protected HttpResponse Response { get; set; }
protected HttpContext Context { get; set; }
/// <summary>
/// 重定向
/// </summary>
/// <param name="url"></param>
public abstract void RedirectTo(string url);
public abstract void Get();
......
......@@ -8,11 +8,51 @@ namespace Mozi.HttpEmbedded.Page
/// </summary>
public class Global
{
public Dictionary<string,object> _data=new Dictionary<string, object>();
public Global Set()
private static Global _global;
private Dictionary<string, object> _data = new Dictionary<string, object>();
/// <summary>
/// 设置键值
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns></returns>
public Global Set(string key, object value)
{
if (_data.ContainsKey(key))
{
_data[key] = value;
}
else
{
_data.Add(key, value);
}
return this;
}
/// <summary>
/// 获取键值
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public object Get(string key)
{
return _data[key];
}
/// <summary>
/// 索引器
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public object this[string key]{
get
{
return Get(key);
}
set
{
Set(key, value);
}
}
}
}
......@@ -21,6 +21,13 @@ namespace Mozi.HttpEmbedded.Page
public PageCreator LoadFromStream(Stream stream)
{
Prepare();
return this;
}
public PageCreator Prepare()
{
InjectGlobal();
InjectValues();
return this;
}
/// <summary>
......@@ -39,5 +46,15 @@ namespace Mozi.HttpEmbedded.Page
{
return null;
}
public byte[] GetBuffer()
{
return new byte[]{ };
}
public string GetPage()
{
return "";
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册