Modified cookies validation, and added origin header validation

This commit is contained in:
sta
2014-03-07 21:15:55 +09:00
parent 12efc99805
commit 048627b4f9
5 changed files with 175 additions and 56 deletions

View File

@@ -16,16 +16,5 @@ namespace Example2
Send (msg);
}
protected override bool ValidateCookies (
CookieCollection request, CookieCollection response)
{
foreach (Cookie cookie in request) {
cookie.Expired = true;
response.Add (cookie);
}
return true;
}
}
}

View File

@@ -41,9 +41,48 @@ namespace Example2
wssv.AddWebSocketService<Echo> ("/Echo");
wssv.AddWebSocketService<Chat> ("/Chat");
//wssv.AddWebSocketService<Chat> (
// "/Chat",
// () => new Chat ("Anon#") { Protocol = "chat" });
/* With initializing
wssv.AddWebSocketService<Echo> (
"/Echo",
() => new Echo () {
Protocol = "echo",
OriginValidator = value => {
Uri origin;
return !value.IsNullOrEmpty () &&
Uri.TryCreate (value, UriKind.Absolute, out origin) &&
origin.Host == "localhost";
},
CookiesValidator = (req, res) => {
foreach (Cookie cookie in req) {
cookie.Expired = true;
res.Add (cookie);
}
return true;
}
});
wssv.AddWebSocketService<Chat> (
"/Chat",
() => new Chat ("Anon#") {
Protocol = "chat",
OriginValidator = value => {
Uri origin;
return !value.IsNullOrEmpty () &&
Uri.TryCreate (value, UriKind.Absolute, out origin) &&
origin.Host == "localhost";
},
CookiesValidator = (req, res) => {
foreach (Cookie cookie in req) {
cookie.Expired = true;
res.Add (cookie);
}
return true;
}
});
*/
wssv.Start ();
if (wssv.IsListening) {