Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sunxiaotianmg
Mozi.HttpEmbedded
提交
c9619c0f
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,体验更适合开发者的 AI 搜索 >>
提交
c9619c0f
编写于
5月 13, 2021
作者:
JasonWcx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
加入默认首页
上级
ce766dae
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
120 addition
and
20 deletion
+120
-20
Mozi.HttpEmbedded/AccessManager.cs
Mozi.HttpEmbedded/AccessManager.cs
+1
-1
Mozi.HttpEmbedded/Document/DefaultHome.html
Mozi.HttpEmbedded/Document/DefaultHome.html
+6
-3
Mozi.HttpEmbedded/Document/DocLoader.cs
Mozi.HttpEmbedded/Document/DocLoader.cs
+19
-0
Mozi.HttpEmbedded/Document/Error.html
Mozi.HttpEmbedded/Document/Error.html
+4
-1
Mozi.HttpEmbedded/Document/ExamplePage.html
Mozi.HttpEmbedded/Document/ExamplePage.html
+0
-0
Mozi.HttpEmbedded/HttpRequest.cs
Mozi.HttpEmbedded/HttpRequest.cs
+1
-0
Mozi.HttpEmbedded/HttpServer.cs
Mozi.HttpEmbedded/HttpServer.cs
+20
-9
Mozi.HttpEmbedded/Mozi.HttpEmbedded.csproj
Mozi.HttpEmbedded/Mozi.HttpEmbedded.csproj
+4
-3
Mozi.HttpEmbedded/Page/AbsPage.cs
Mozi.HttpEmbedded/Page/AbsPage.cs
+5
-0
Mozi.HttpEmbedded/Page/Global.cs
Mozi.HttpEmbedded/Page/Global.cs
+43
-3
Mozi.HttpEmbedded/Page/PageCreator.cs
Mozi.HttpEmbedded/Page/PageCreator.cs
+17
-0
未找到文件。
Mozi.HttpEmbedded/AccessManager.cs
浏览文件 @
c9619c0f
...
...
@@ -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
{
...
...
Mozi.HttpEmbedded/Docment/DefaultHome.html
→
Mozi.HttpEmbedded/Doc
u
ment/DefaultHome.html
浏览文件 @
c9619c0f
<!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
Mozi.HttpEmbedded/Document/DocLoader.cs
0 → 100644
浏览文件 @
c9619c0f
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
);
}
}
}
Mozi.HttpEmbedded/Docment/Error.html
→
Mozi.HttpEmbedded/Doc
u
ment/Error.html
浏览文件 @
c9619c0f
...
...
@@ -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>
...
...
Mozi.HttpEmbedded/Docment/ExamplePage.html
→
Mozi.HttpEmbedded/Doc
u
ment/ExamplePage.html
浏览文件 @
c9619c0f
文件已移动
Mozi.HttpEmbedded/HttpRequest.cs
浏览文件 @
c9619c0f
...
...
@@ -206,6 +206,7 @@ namespace Mozi.HttpEmbedded
{
req
.
Post
=
UrlEncoder
.
ParseQuery
(
StringEncoder
.
Decode
(
data
));
}
//TODO 文件流应写入缓冲区
/// <summary>
/// 分析请求体 multipart/form-data
/// </summary>
...
...
Mozi.HttpEmbedded/HttpServer.cs
浏览文件 @
c9619c0f
...
...
@@ -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
());
...
...
Mozi.HttpEmbedded/Mozi.HttpEmbedded.csproj
浏览文件 @
c9619c0f
...
...
@@ -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=
"Doc
ment\DefaultHome.html"
/>
<
Content
Include=
"Doc
ment\Error.html"
/>
<
Content
Include=
"Doc
ment\ExamplePage.html"
/>
<
EmbeddedResource
Include=
"Docu
ment\DefaultHome.html"
/>
<
EmbeddedResource
Include=
"Docu
ment\Error.html"
/>
<
EmbeddedResource
Include=
"Docu
ment\ExamplePage.html"
/>
<Content
Include=
"Source\mime.data"
/>
<Content
Include=
"WebDav\Icon.png"
/>
</ItemGroup>
...
...
Mozi.HttpEmbedded/Page/AbsPage.cs
浏览文件 @
c9619c0f
...
...
@@ -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
();
...
...
Mozi.HttpEmbedded/Page/Global.cs
浏览文件 @
c9619c0f
...
...
@@ -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
);
}
}
}
}
Mozi.HttpEmbedded/Page/PageCreator.cs
浏览文件 @
c9619c0f
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录