[Modify] Edit it

This commit is contained in:
sta 2016-07-07 15:12:43 +09:00
parent d006215860
commit e35babea1b

View File

@ -567,17 +567,18 @@ And if you would like to validate the **Origin** header, **Cookies**, or both in
```csharp ```csharp
wssv.AddWebSocketService<Chat> ( wssv.AddWebSocketService<Chat> (
"/Chat", "/Chat",
() => new Chat () { () =>
new Chat () {
OriginValidator = val => { OriginValidator = val => {
// Check the value of the Origin header, and return true if valid. // Check the value of the Origin header, and return true if valid.
Uri origin; Uri origin;
return !val.IsNullOrEmpty () && return !val.IsNullOrEmpty ()
Uri.TryCreate (val, UriKind.Absolute, out origin) && && Uri.TryCreate (val, UriKind.Absolute, out origin)
origin.Host == "example.com"; && origin.Host == "example.com";
}, },
CookiesValidator = (req, res) => { CookiesValidator = (req, res) => {
// Check the Cookies in 'req', and set the Cookies to send to the client with 'res' // Check the cookies in 'req', and set the cookies to send to
// if necessary. // the client with 'res' if necessary.
foreach (Cookie cookie in req) { foreach (Cookie cookie in req) {
cookie.Expired = true; cookie.Expired = true;
res.Add (cookie); res.Add (cookie);
@ -585,7 +586,8 @@ wssv.AddWebSocketService<Chat> (
return true; // If valid. return true; // If valid.
} }
}); }
);
``` ```
And also if you would like to get each value of the Origin header and cookies, you should access each of the `WebSocketBehavior.Context.Origin` and `WebSocketBehavior.Context.CookieCollection` properties. And also if you would like to get each value of the Origin header and cookies, you should access each of the `WebSocketBehavior.Context.Origin` and `WebSocketBehavior.Context.CookieCollection` properties.