[Modify] Edit it
This commit is contained in:
parent
d006215860
commit
e35babea1b
16
README.md
16
README.md
@ -567,17 +567,18 @@ And if you would like to validate the **Origin** header, **Cookies**, or both in
|
||||
```csharp
|
||||
wssv.AddWebSocketService<Chat> (
|
||||
"/Chat",
|
||||
() => new Chat () {
|
||||
() =>
|
||||
new Chat () {
|
||||
OriginValidator = val => {
|
||||
// Check the value of the Origin header, and return true if valid.
|
||||
Uri origin;
|
||||
return !val.IsNullOrEmpty () &&
|
||||
Uri.TryCreate (val, UriKind.Absolute, out origin) &&
|
||||
origin.Host == "example.com";
|
||||
return !val.IsNullOrEmpty ()
|
||||
&& Uri.TryCreate (val, UriKind.Absolute, out origin)
|
||||
&& origin.Host == "example.com";
|
||||
},
|
||||
CookiesValidator = (req, res) => {
|
||||
// Check the Cookies in 'req', and set the Cookies to send to the client with 'res'
|
||||
// if necessary.
|
||||
// Check the cookies in 'req', and set the cookies to send to
|
||||
// the client with 'res' if necessary.
|
||||
foreach (Cookie cookie in req) {
|
||||
cookie.Expired = true;
|
||||
res.Add (cookie);
|
||||
@ -585,7 +586,8 @@ wssv.AddWebSocketService<Chat> (
|
||||
|
||||
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.
|
||||
|
Loading…
Reference in New Issue
Block a user