You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// k.ListenUnixSocket("/tmp/rpc.sock", l => l.UseConnectionHandler<JsonRpcConnectionHandler>());
101
+
// k.ListenNamedPipe("rpc", l => l.UseConnectionHandler<JsonRpcConnectionHandler>());
57
102
});
58
103
```
59
104
60
-
Clients write JSON documents back to back (a newline between them is fine); each document is answered in
61
-
order on the same connection, notifications produce nothing. The `ConnectionContext` is the RPC context.
105
+
Clients write JSON documents back to back (whitespace or newlines between them are fine) and read the responses
106
+
in the same order, also back to back with no newline or `Content-Length` prefix, so the client must parse one
107
+
complete JSON value at a time. Notifications produce nothing. The `ConnectionContext` is the RPC context.
108
+
109
+
The framer accepts strict JSON only, even with the Json.NET serializer or a lenient `JsmnSerializer` selected.
110
+
A document larger than `MaxRequestBytes` aborts the connection. Documents on one connection are processed one at
111
+
a time, in order; separate connections run concurrently.
112
+
113
+
A raw connection does not pass through the HTTP middleware pipeline, so it has no authentication, authorisation
114
+
or rate limiting. Listen on loopback or a Unix socket, or configure transport security, authentication and
115
+
connection limits at the Kestrel listener or in a surrounding protocol.
116
+
117
+
## Async methods
118
+
119
+
Set `EnableAsyncMethods = true` to serve `Task` and `ValueTask` methods through `ProcessAsync`. With it off (the
120
+
default), requests are processed synchronously and an async method is answered with `-32603` without being
121
+
invoked.
122
+
123
+
-**HTTP:** the call is cancelled when the client disconnects (`HttpContext.RequestAborted`). Notifications are
124
+
awaited and still answer `204`. The body reader stays leased until the invocation finishes.
125
+
-**Raw connections:** documents are processed one at a time, in order. Replies already finished are flushed
126
+
before the connection waits on a slow method. When the connection closes, the running method is waited for and
127
+
its response discarded.
62
128
63
-
With `EnableAsyncMethods = true`, HTTP awaits `ProcessAsync` with `HttpContext.RequestAborted`;
64
-
the body reader remains leased until invocation finishes. Raw connections await each framed document
65
-
before starting the next and flush earlier completed replies before waiting for a slow document.
66
-
Notifications are awaited and keep the same HTTP status rules. Connection cancellation is cooperative:
67
-
the processor waits for the running method to terminate before releasing input and discards its staged response.
68
-
Mark a `CancellationToken` parameter with `[JsonRpcCancellation]` to receive that token.
69
-
The default mode preserves synchronous processing and rejects async methods at call time.
129
+
A method receives the token by declaring a `[JsonRpcCancellation] CancellationToken` parameter; see
130
+
[Asynchronous methods and cancellation](https://github.com/Astn/JSON-RPC.NET#asynchronous-methods-and-cancellation)
131
+
in the main README.
70
132
71
133
## Options
72
134
73
-
| Option | Default | Meaning |
74
-
|---|---|---|
75
-
|`EnableAsyncMethods`| false | use ProcessAsync for Task/ValueTask methods, with host cancellation |
76
-
|`SessionId`| default session | which session's methods answer |
77
-
|`SessionSelector`| null | pick the session per HTTP request |
78
-
|`Serializer`| session, then `Config.Serializer`| serializer for this host |
79
-
|`ContextFactory`|`HttpContext`| what `JsonRpcContext.Current()` returns |
80
-
|`MaxRequestBytes`| 4 MB | larger bodies get 413 (HTTP) or abort the connection |
81
-
|`ResponseContentType`|`application/json`||
82
-
|`NoContentForNotifications`| true | 204 for notifications, otherwise 200 with an empty body |
135
+
| Option | Default | Scope | Meaning |
136
+
|---|---|---|---|
137
+
|`EnableAsyncMethods`| false | HTTP and raw | use `ProcessAsync` for `Task`/`ValueTask` methods, with host cancellation |
138
+
|`SessionId`| default session | HTTP and raw | which session's methods answer |
139
+
|`SessionSelector`| null | HTTP | pick the session per request from the `HttpContext`; it must map to a fixed set of ids, because an unknown id creates a session that persists |
140
+
|`Serializer`| session, then `Config.Serializer`| HTTP and raw | serializer for this host |
141
+
|`ContextFactory`|`HttpContext`| HTTP | what `JsonRpcContext.Current()` returns |
142
+
|`MaxRequestBytes`| 4 MB | HTTP body, or one raw document | larger bodies get 413; a larger raw document aborts the connection |
0 commit comments