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

再次修改If-Modified-Since判断条件

上级 13dfea83
......@@ -57,7 +57,7 @@
</div>
</div>
<div class="text-center">
<a href="index.html" class="btn btn-primary">Login</a>
<a href="index.html" class="btn btn-primary">登陆</a>
</div>
</form>
</div>
......@@ -65,8 +65,8 @@
</div>
<div class="d-flex justify-content-center">
<span class="mr-2">Don't have an account?</span>
<a href="signup.html">Sign Up</a>
<span class="mr-2">没有账户?</span>
<a href="signup.html">注册</a>
</div>
</div>
......
<!DOCTYPE html>
<!DOCTYPE html>
<html lang="en" dir="rtl">
<head>
......
......@@ -163,11 +163,11 @@ namespace Mozi.HttpEmbedded
{
//响应静态文件
if (st.Exists(path, ""))
{
DateTime dtModified = st.GetLastModified(path).ToUniversalTime();
{
string ifmodifiedsince =context.Request.Headers.GetValue(HeaderProperty.IfModifiedSince.PropertyTag);
if (st.CheckIfModified(path, ifmodifiedsince))
{
DateTime dtModified = st.GetLastModified(path).ToUniversalTime();
context.Response.Headers.Add(HeaderProperty.LastModified, dtModified.ToString("r"));
context.Response.Write(st.Load(path, ""));
}
......
......@@ -144,37 +144,21 @@ namespace Mozi.HttpEmbedded
{
StateObject so = (StateObject)iar.AsyncState;
Socket client = so.WorkSocket;
if (client.Connected)
{
int iByteRead = client.EndReceive(iar);
if (client.Connected)
{
int iByteRead = client.EndReceive(iar);
if (iByteRead >0)
if (iByteRead >0)
{
//置空数据连接
so.ResetBuffer(iByteRead);
if (client.Available > 0)
{
//置空数据连接
so.ResetBuffer(iByteRead);
if (client.Available > 0)
{
//Thread.Sleep(10);
client.BeginReceive(so.Buffer, 0, StateObject.BufferSize, 0, CallbackReceive, so);
}
else
{
_socketDocker.Remove(client);
if (AfterReceiveEnd != null)
{
AfterReceiveEnd(this,
new DataTransferArgs()
{
Data = so.Data.ToArray(),
IP = so.IP,
Port = so.RemotePort,
Socket = so.WorkSocket
});
}
}
//Thread.Sleep(10);
client.BeginReceive(so.Buffer, 0, StateObject.BufferSize, 0, CallbackReceive, so);
}
else
{
else
{
_socketDocker.Remove(client);
if (AfterReceiveEnd != null)
{
......@@ -190,7 +174,7 @@ namespace Mozi.HttpEmbedded
}
}
else
{
{
_socketDocker.Remove(client);
if (AfterReceiveEnd != null)
{
......@@ -203,8 +187,24 @@ namespace Mozi.HttpEmbedded
Socket = so.WorkSocket
});
}
client.Dispose();
}
}
else
{
_socketDocker.Remove(client);
if (AfterReceiveEnd != null)
{
AfterReceiveEnd(this,
new DataTransferArgs()
{
Data = so.Data.ToArray(),
IP = so.IP,
Port = so.RemotePort,
Socket = so.WorkSocket
});
}
client.Dispose();
}
}
}
}
......@@ -68,7 +68,7 @@ namespace Mozi.HttpEmbedded.Source
/// </summary>
/// <param name="path"></param>
/// <param name="ifModifiedSince"></param>
/// <returns></returns>
/// <returns><see cref="Boolean:true">Modified</see></returns>
public bool CheckIfModified(string path, string ifModifiedSince)
{
DateTime dtModified=System.IO.File.GetLastWriteTime(_root + "\\" + path);
......@@ -79,7 +79,7 @@ namespace Mozi.HttpEmbedded.Source
DateTime dtSince = DateTime.ParseExact(ifModifiedSince, "ddd, dd MMM yyyy HH:mm:ss GMT",
CultureInfo.InvariantCulture,
DateTimeStyles.AdjustToUniversal).ToLocalTime();
if (dtModified <= dtSince)
if ((dtModified - dtSince).TotalSeconds<1)
{
return false;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册