Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sunxiaotianmg
Mozi.HttpEmbedded
提交
dc0a9da3
M
Mozi.HttpEmbedded
项目概览
sunxiaotianmg
/
Mozi.HttpEmbedded
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
Mozi.HttpEmbedded
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
dc0a9da3
编写于
7月 13, 2021
作者:
JasonWcx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化部分代码
上级
c1491ff2
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
128 addition
and
129 deletion
+128
-129
Mozi.HttpEmbedded.Test/Test.cs
Mozi.HttpEmbedded.Test/Test.cs
+1
-5
Mozi.HttpEmbedded/Document/DocLoader.cs
Mozi.HttpEmbedded/Document/DocLoader.cs
+3
-0
Mozi.HttpEmbedded/Document/Error.html
Mozi.HttpEmbedded/Document/Error.html
+11
-54
Mozi.HttpEmbedded/Document/Home.html
Mozi.HttpEmbedded/Document/Home.html
+8
-35
Mozi.HttpEmbedded/Generic/AbsClassEnum.cs
Mozi.HttpEmbedded/Generic/AbsClassEnum.cs
+1
-1
Mozi.HttpEmbedded/HttpServer.cs
Mozi.HttpEmbedded/HttpServer.cs
+57
-21
Mozi.HttpEmbedded/Middleware/IMiddleware.cs
Mozi.HttpEmbedded/Middleware/IMiddleware.cs
+1
-1
Mozi.HttpEmbedded/Page/BaseApi.cs
Mozi.HttpEmbedded/Page/BaseApi.cs
+3
-1
Mozi.HttpEmbedded/Page/BasePage.cs
Mozi.HttpEmbedded/Page/BasePage.cs
+9
-2
Mozi.HttpEmbedded/Page/Router.cs
Mozi.HttpEmbedded/Page/Router.cs
+7
-3
Mozi.HttpEmbedded/Page/RuntimeApi.cs
Mozi.HttpEmbedded/Page/RuntimeApi.cs
+5
-5
Mozi.HttpEmbedded/Template/PageEngine.cs
Mozi.HttpEmbedded/Template/PageEngine.cs
+22
-1
未找到文件。
Mozi.HttpEmbedded.Test/Test.cs
浏览文件 @
dc0a9da3
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
Mozi.HttpEmbedded.Page
;
using
Mozi.HttpEmbedded.Page
;
namespace
Mozi.HttpEmbedded.Test
{
...
...
Mozi.HttpEmbedded/Document/DocLoader.cs
浏览文件 @
dc0a9da3
...
...
@@ -3,6 +3,9 @@ using System.Reflection;
namespace
Mozi.HttpEmbedded.Docment
{
/// <summary>
/// 文档载入器
/// </summary>
public
class
DocLoader
{
public
static
string
Load
(
string
docName
)
...
...
Mozi.HttpEmbedded/Document/Error.html
浏览文件 @
dc0a9da3
...
...
@@ -7,60 +7,17 @@
<meta
name=
"Authorization"
content=
"Jason"
>
<meta
name=
"viewport"
content=
"width=device-width,height=device-height,initial-scale=1,maximum-scale=1,user-scalable=no"
>
<style
type=
"text/css"
>
*
{
font-size
:
18px
;
box-sizing
:
border-box
;
-webkit-box-sizing
:
border-box
;
color
:
#212121
;
-moz-box-sizing
:
border-box
;
-webkit-user-drag
:
none
;
}
body
{
padding
:
0
;
margin
:
0
;
}
ul
{
list-style-type
:
none
;
padding
:
0
;
margin
:
0
;
}
body
{
padding
:
0
;
margin
:
0
;
}
ul
{
list-style-type
:
none
;
padding
:
0
;
margin
:
0
;
}
h1
{
font-size
:
1.22rem
;
}
h2
{
font-size
:
1rem
;
}
h3
{
font-size
:
0.89rem
;
}
h4
{
font-size
:
0.78rem
;
}
h5
{
font-size
:
0.67rem
;
}
p
,
p
>
*,
pre
{
font-size
:
0.78rem
;
}
*
{
font-size
:
18px
;
box-sizing
:
border-box
;
-webkit-box-sizing
:
border-box
;
color
:
#212121
;
-moz-box-sizing
:
border-box
;
-webkit-user-drag
:
none
;}
body
{
padding
:
0
;
margin
:
0
;}
ul
{
list-style-type
:
none
;
padding
:
0
;
margin
:
0
;
}
body
{
padding
:
0
;
margin
:
0
;}
ul
{
list-style-type
:
none
;
padding
:
0
;
margin
:
0
;
}
h1
{
font-size
:
1.22rem
;
}
h2
{
font-size
:
1rem
;}
h3
{
font-size
:
0.89rem
;}
h4
{
font-size
:
0.78rem
;}
h5
{
font-size
:
0.67rem
;}
p
,
p
>
*
{
font-size
:
0.78rem
;
line-height
:
1.22rem
;}
</style>
</head>
<body
style=
"padding:0 0.6rem;"
>
...
...
Mozi.HttpEmbedded/Document/Home.html
浏览文件 @
dc0a9da3
...
...
@@ -10,41 +10,14 @@
*
{
font-size
:
18px
;
box-sizing
:
border-box
;
-webkit-box-sizing
:
border-box
;
color
:
#212121
;
-moz-box-sizing
:
border-box
;
-webkit-user-drag
:
none
;}
body
{
padding
:
0
;
margin
:
0
;}
ul
{
list-style-type
:
none
;
padding
:
0
;
margin
:
0
;
}
body
{
padding
:
0
;
margin
:
0
;
}
ul
{
list-style-type
:
none
;
padding
:
0
;
margin
:
0
;
}
h1
{
font-size
:
1.22rem
;
}
h2
{
font-size
:
1rem
;
}
h3
{
font-size
:
0.89rem
;
}
h4
{
font-size
:
0.78rem
;
}
h5
{
font-size
:
0.67rem
;
}
p
,
p
>
*
{
font-size
:
0.78rem
;
line-height
:
1.22rem
;
}
body
{
padding
:
0
;
margin
:
0
;}
ul
{
list-style-type
:
none
;
padding
:
0
;
margin
:
0
;
}
h1
{
font-size
:
1.22rem
;
}
h2
{
font-size
:
1rem
;
}
h3
{
font-size
:
0.89rem
;
}
h4
{
font-size
:
0.78rem
;
}
h5
{
font-size
:
0.67rem
;
}
p
,
p
>
*
{
font-size
:
0.78rem
;
line-height
:
1.22rem
;}
</style>
</head>
<body
style=
"width:640px;margin:0 auto;"
>
...
...
Mozi.HttpEmbedded/Generic/AbsClassEnum.cs
浏览文件 @
dc0a9da3
...
...
@@ -4,7 +4,7 @@ using System.Reflection;
namespace
Mozi.HttpEmbedded.Generic
{
/// <summary>
/// 仿枚举
/// 仿
枚
举 抽象类
/// </summary>
public
abstract
class
AbsClassEnum
{
...
...
Mozi.HttpEmbedded/HttpServer.cs
浏览文件 @
dc0a9da3
...
...
@@ -60,11 +60,20 @@ namespace Mozi.HttpEmbedded
private
string
_serverName
=
"HttpEmbedded"
;
//默认首页为index.html,index.htm
p
rivate
string
_indexPageMatchPattern
=
"index.html,index.htm"
;
p
ublic
string
[]
_indexPages
=
new
string
[]
{
"index.html"
,
"index.htm"
}
;
//允许和公开的方法
private
RequestMethod
[]
MethodAllow
=
new
RequestMethod
[]
{
RequestMethod
.
OPTIONS
,
RequestMethod
.
TRACE
,
RequestMethod
.
GET
,
RequestMethod
.
HEAD
,
RequestMethod
.
POST
,
RequestMethod
.
COPY
,
RequestMethod
.
PROPFIND
,
RequestMethod
.
LOCK
,
RequestMethod
.
UNLOCK
};
/// <summary>
/// 默认首页
/// </summary>
public
string
IndexPages
{
get
{
return
string
.
Join
(
","
,
_indexPages
);
}
}
/// <summary>
/// 允许的方法
/// </summary>
private
RequestMethod
[]
MethodAllow
=
new
RequestMethod
[]
{
RequestMethod
.
OPTIONS
,
RequestMethod
.
TRACE
,
RequestMethod
.
GET
,
RequestMethod
.
HEAD
,
RequestMethod
.
POST
,
RequestMethod
.
COPY
,
RequestMethod
.
PROPFIND
,
RequestMethod
.
LOCK
,
RequestMethod
.
UNLOCK
};
/// <summary>
/// 公开的方法
/// </summary>
private
RequestMethod
[]
MethodPublic
=
new
RequestMethod
[]
{
RequestMethod
.
OPTIONS
,
RequestMethod
.
GET
,
RequestMethod
.
HEAD
,
RequestMethod
.
PROPFIND
,
RequestMethod
.
PROPPATCH
,
RequestMethod
.
MKCOL
,
RequestMethod
.
PUT
,
RequestMethod
.
DELETE
,
RequestMethod
.
COPY
,
RequestMethod
.
MOVE
,
RequestMethod
.
LOCK
,
RequestMethod
.
UNLOCK
};
//证书管理器
...
...
@@ -358,33 +367,60 @@ namespace Mozi.HttpEmbedded
bool
isStatic
=
st
.
IsStatic
(
fileext
);
context
.
Response
.
SetContentType
(
contenttype
);
if
(
path
==
"/"
)
var
pathReal
=
path
;
if
(
pathReal
==
"/"
)
{
var
doc
=
DocLoader
.
Load
(
"Home.html"
);
PageEngine
pc
=
new
PageEngine
();
pc
.
LoadFromText
(
doc
);
pc
.
Set
(
"Info"
,
new
{
VersionName
=
System
.
Reflection
.
Assembly
.
GetExecutingAssembly
().
GetName
().
Version
.
ToString
(),
});
pc
.
Prepare
();
context
.
Response
.
Write
(
pc
.
GetBuffer
());
context
.
Response
.
SetContentType
(
Mime
.
GetContentType
(
"html"
));
return
StatusCode
.
Success
;
//var existsIndex = false;
//foreach(var r in _indexPages)
//{
// if (st.Exists(path+r, ""))
// {
// string ifmodifiedsince = context.Request.Headers.GetValue(HeaderProperty.IfModifiedSince.PropertyName);
// if (st.CheckIfModified(path, ifmodifiedsince))
// {
// DateTime dtModified = st.GetLastModifiedTime(path).ToUniversalTime();
// context.Response.AddHeader(HeaderProperty.LastModified, dtModified.ToString("r"));
// context.Response.Write(st.Load(path, ""));
// //ETag 仅测试 不具备判断缓存的能力
// context.Response.AddHeader(HeaderProperty.ETag, String.Format("{0:x2}:{1:x2}", dtModified.ToUniversalTime().Ticks, context.Response.ContentLength));
// return StatusCode.Success;
// }
// }
//}
//if (!existsIndex)
//{
//优先加载
var
doc
=
DocLoader
.
Load
(
"Home.html"
);
PageEngine
pc
=
new
PageEngine
();
pc
.
LoadFromText
(
doc
);
pc
.
Set
(
"Info"
,
new
{
VersionName
=
System
.
Reflection
.
Assembly
.
GetExecutingAssembly
().
GetName
().
Version
.
ToString
(),
});
pc
.
Prepare
();
context
.
Response
.
Write
(
pc
.
GetBuffer
());
context
.
Response
.
SetContentType
(
Mime
.
GetContentType
(
"html"
));
return
StatusCode
.
Success
;
//}
}
//静态文件处理
else
if
(
st
.
Enabled
&&
isStatic
)
{
//if (pathReal.EndsWith("/"))
//{
//}
//响应静态文件
if
(
st
.
Exists
(
path
,
""
))
if
(
st
.
Exists
(
path
Real
,
""
))
{
string
ifmodifiedsince
=
context
.
Request
.
Headers
.
GetValue
(
HeaderProperty
.
IfModifiedSince
.
PropertyName
);
if
(
st
.
CheckIfModified
(
path
,
ifmodifiedsince
))
if
(
st
.
CheckIfModified
(
path
Real
,
ifmodifiedsince
))
{
DateTime
dtModified
=
st
.
GetLastModifiedTime
(
path
).
ToUniversalTime
();
DateTime
dtModified
=
st
.
GetLastModifiedTime
(
path
Real
).
ToUniversalTime
();
context
.
Response
.
AddHeader
(
HeaderProperty
.
LastModified
,
dtModified
.
ToString
(
"r"
));
context
.
Response
.
Write
(
st
.
Load
(
path
,
""
));
context
.
Response
.
Write
(
st
.
Load
(
path
Real
,
""
));
//ETag 仅测试 不具备判断缓存的能力
context
.
Response
.
AddHeader
(
HeaderProperty
.
ETag
,
String
.
Format
(
"{0:x2}:{1:x2}"
,
dtModified
.
ToUniversalTime
().
Ticks
,
context
.
Response
.
ContentLength
));
...
...
@@ -688,7 +724,7 @@ namespace Mozi.HttpEmbedded
/// <param name="filePath"></param>
public
void
SetIndexPage
(
string
pattern
)
{
_indexPage
MatchPattern
=
pattern
;
_indexPage
s
=
pattern
.
Split
(
new
char
[]
{
','
})
;
}
/// <summary>
/// 关闭服务器
...
...
Mozi.HttpEmbedded/Middleware/IMiddleware.cs
浏览文件 @
dc0a9da3
...
...
@@ -3,7 +3,7 @@
/// <summary>
/// 中间件 接入多层次逻辑处理
/// </summary>
public
interface
IMiddleware
internal
interface
IMiddleware
{
void
Invoke
();
}
...
...
Mozi.HttpEmbedded/Page/BaseApi.cs
浏览文件 @
dc0a9da3
...
...
@@ -5,7 +5,9 @@
/// </summary>
public
abstract
class
BaseApi
{
/// <summary>
/// 绑定的上下文对象
/// </summary>
public
HttpContext
Context
{
get
;
internal
set
;
}
}
}
Mozi.HttpEmbedded/Page/BasePage.cs
浏览文件 @
dc0a9da3
...
...
@@ -5,15 +5,22 @@
/// </summary>
public
abstract
class
BasePage
{
/// <summary>
/// 上下文对象
/// </summary>
protected
HttpContext
Context
{
get
;
set
;
}
/// <summary>
/// 重定向
/// </summary>
/// <param name="url"></param>
public
abstract
void
RedirectTo
(
string
url
);
/// <summary>
/// GET方法
/// </summary>
public
abstract
void
Get
();
/// <summary>
/// POST方法
/// </summary>
public
abstract
void
Post
();
}
...
...
Mozi.HttpEmbedded/Page/Router.cs
浏览文件 @
dc0a9da3
...
...
@@ -10,7 +10,7 @@ namespace Mozi.HttpEmbedded.Page
{
//TODO 增加API下载的功能,允许客户端提取所有API,同时加入鉴权机制
/// <summary>
/// 全局路由
/// 全局路由
单例模式
/// </summary>
/// <remarks>
/// 实例化Router时会自动扫描此程序集内部的API
...
...
@@ -321,14 +321,18 @@ namespace Mozi.HttpEmbedded.Page
return
ap
;
}
}
/// <summary>
/// 访问域
/// </summary>
public
class
AccessPoint
{
public
string
Domain
{
get
;
set
;
}
public
string
Controller
{
get
;
set
;
}
public
string
Action
{
get
;
set
;
}
}
/// <summary>
/// 访问对象
/// </summary>
public
class
AccessObject
{
public
Type
Target
{
get
;
set
;
}
...
...
Mozi.HttpEmbedded/Page/RuntimeApi.cs
浏览文件 @
dc0a9da3
...
...
@@ -33,12 +33,12 @@ namespace Mozi.HttpEmbedded.Page
public
RuntimeInfo
Info
()
{
RuntimeInfo
info
=
new
RuntimeInfo
();
var
exeAssembly
=
Assembly
.
GetExecutingAssembly
();
info
.
Name
=
exeAssembly
.
GetName
().
Name
;
info
.
VersionName
=
exeAssembly
.
GetName
().
Version
.
ToString
();
info
.
PlatformName
=
exeAssembly
.
ImageRuntimeVersion
;
var
ass
=
Assembly
.
GetExecutingAssembly
();
info
.
Name
=
ass
.
GetName
().
Name
;
info
.
VersionName
=
ass
.
GetName
().
Version
.
ToString
();
info
.
PlatformName
=
ass
.
ImageRuntimeVersion
;
info
.
StartupTime
=
Context
.
Server
.
StartTime
.
ToUniversalTime
().
ToString
(
"r"
);
Module
[]
modules
=
exeAssembly
.
GetLoadedModules
();
Module
[]
modules
=
ass
.
GetLoadedModules
();
foreach
(
var
m
in
modules
)
{
info
.
LoadedModules
.
Add
(
new
LoadedModuleInfo
()
...
...
Mozi.HttpEmbedded/Template/PageEngine.cs
浏览文件 @
dc0a9da3
...
...
@@ -144,12 +144,33 @@ namespace Mozi.HttpEmbedded.Template
}
/// <summary>
/// $define表达式
/// <para>
/// $define 用于定义常量
/// </para>
/// </summary>
/// <returns></returns>
private
PageEngine
InflateStatementDefine
()
{
throw
new
NotImplementedException
();
}
/// <summary>
/// $undef 表达式
/// <para>
/// $undef 用于删除常量定义
/// </para>
/// </summary>
/// <returns></returns>
private
PageEngine
InflateStatementUndef
()
{
throw
new
NotImplementedException
();
}
/// <summary>
/// $set表达式
/// <para>
/// $set 用于定义变量
/// </para>
/// </summary>
/// <returns></returns>
private
PageEngine
InflateStatementSet
()
{
throw
new
NotImplementedException
();
...
...
@@ -222,7 +243,7 @@ namespace Mozi.HttpEmbedded.Template
return
this
;
}
/// <summary>
/// == != <>
&& ||
/// == != <>
> < >= <=, && || ,+ - * / %
/// </summary>
/// <returns></returns>
private
PageEngine
ParseOperator
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录