[Modify] Edit it
This commit is contained in:
parent
bcb05f04ce
commit
b8fa74b1a1
43
README.md
43
README.md
@ -553,7 +553,7 @@ And if you would like to send the cookies in the handshake request, you should s
|
|||||||
ws.SetCookie (new Cookie ("name", "nobita"));
|
ws.SetCookie (new Cookie ("name", "nobita"));
|
||||||
```
|
```
|
||||||
|
|
||||||
As a WebSocket server, if you would like to get the query string included in a handshake request, you should access the `WebSocketBehavior.Context.QueryString` property, such as the following.
|
As a WebSocket server, if you would like to get the query string included in a handshake request, you should access the `WebSocketBehavior.QueryString` property, such as the following.
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
public class Chat : WebSocketBehavior
|
public class Chat : WebSocketBehavior
|
||||||
@ -563,7 +563,7 @@ public class Chat : WebSocketBehavior
|
|||||||
|
|
||||||
protected override void OnOpen ()
|
protected override void OnOpen ()
|
||||||
{
|
{
|
||||||
_name = Context.QueryString["name"];
|
_name = QueryString["name"];
|
||||||
}
|
}
|
||||||
|
|
||||||
...
|
...
|
||||||
@ -574,31 +574,32 @@ If you would like to get the value of the Origin header included in a handshake
|
|||||||
|
|
||||||
If you would like to get the cookies included in a handshake request, you should access the `WebSocketBehavior.Context.CookieCollection` property.
|
If you would like to get the cookies included in a handshake request, you should access the `WebSocketBehavior.Context.CookieCollection` property.
|
||||||
|
|
||||||
And if you would like to validate the Origin header, cookies, or both, you should set each validation for it with your `WebSocketBehavior`, for example, by using the `WebSocketServer.AddWebSocketService<TBehavior> (string, Func<TBehavior>)` method with initializing, such as the following.
|
And if you would like to validate the Origin header, cookies, or both, you should set each validation for it with your `WebSocketBehavior`, for example, by using the `WebSocketServer.AddWebSocketService<TBehavior> (string, Action<TBehavior>)` method with initializing, such as the following.
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
wssv.AddWebSocketService<Chat> (
|
wssv.AddWebSocketService<Chat> (
|
||||||
"/Chat",
|
"/Chat",
|
||||||
() =>
|
s => {
|
||||||
new Chat () {
|
s.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 ()
|
|
||||||
&& 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.
|
|
||||||
foreach (Cookie cookie in req) {
|
|
||||||
cookie.Expired = true;
|
|
||||||
res.Add (cookie);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true; // If valid.
|
return !val.IsNullOrEmpty ()
|
||||||
|
&& Uri.TryCreate (val, UriKind.Absolute, out origin)
|
||||||
|
&& origin.Host == "example.com";
|
||||||
|
};
|
||||||
|
|
||||||
|
s.CookiesValidator = (req, res) => {
|
||||||
|
// Check the cookies in 'req', and set the cookies to send to
|
||||||
|
// the client with 'res' if necessary.
|
||||||
|
foreach (var cookie in req) {
|
||||||
|
cookie.Expired = true;
|
||||||
|
res.Add (cookie);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
return true; // If valid.
|
||||||
|
};
|
||||||
|
}
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user