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
/// Creates a test in-process HTTP server configured for FastEndpoints with optional authentication, error behaviors, startup delay, and client TLS certificate requirement.
60
+
/// </summary>
61
+
/// <param name="withTokenAuth">Enable JWT bearer authentication and related authorization checks for endpoints.</param>
62
+
/// <param name="withBasicAuth">Enable basic-like username/password validation on test endpoints.</param>
63
+
/// <param name="withRetriableError">Make certain endpoints return retriable error responses to simulate transient failures.</param>
64
+
/// <param name="withErrorMessage">Include error messages in responses for endpoints that simulate failures.</param>
65
+
/// <param name="withStartDelay">Optional delay applied at startup; pass null for no delay.</param>
66
+
/// <param name="requireClientCert">Require client TLS certificates for HTTPS connections when true.</param>
@@ -195,7 +210,10 @@ public async Task StopAsync()
195
210
/// <summary>
196
211
/// Gets the server's in-memory text buffer of received data.
197
212
/// </summary>
198
-
/// <returns>The mutable <see cref="StringBuilder"/> containing the accumulated received text; modifying it updates the server's buffer.</returns>
213
+
/// <summary>
214
+
/// Gets the server instance's accumulated received-text buffer for the configured port.
215
+
/// </summary>
216
+
/// <returns>The mutable <see cref="StringBuilder"/> containing the accumulated received text for this port; modifying it updates the server's buffer.</returns>
199
217
publicStringBuilderGetReceiveBuffer()
200
218
{
201
219
returnIlpEndpoint.GetReceiveBuffer(_port);
@@ -204,17 +222,28 @@ public StringBuilder GetReceiveBuffer()
204
222
/// <summary>
205
223
/// Gets the in-memory list of bytes received by the ILP endpoint.
206
224
/// </summary>
207
-
/// <returns>The mutable list of bytes received by the endpoint.</returns>
225
+
/// <summary>
226
+
/// Retrieve the mutable list of raw bytes received by this server instance's endpoint.
227
+
/// </summary>
228
+
/// <returns>The mutable list of bytes received by the endpoint for the current port.</returns>
208
229
publicList<byte>GetReceivedBytes()
209
230
{
210
231
returnIlpEndpoint.GetReceiveBytes(_port);
211
232
}
212
233
234
+
/// <summary>
235
+
/// Retrieves the last exception recorded for the server instance's configured port.
236
+
/// </summary>
237
+
/// <returns>The most recent <see cref="Exception"/> captured for the server port, or <c>null</c> if no error has been recorded.</returns>
213
238
publicException?GetLastError()
214
239
{
215
240
returnIlpEndpoint.GetLastError(_port);
216
241
}
217
242
243
+
/// <summary>
244
+
/// Checks whether the server's /ping endpoint responds with a successful HTTP status.
245
+
/// </summary>
246
+
/// <returns>`true` if the /ping endpoint returns a successful HTTP status code, `false` otherwise.</returns>
Copy file name to clipboardExpand all lines: src/dummy-http-server/IlpEndpoint.cs
+94-4Lines changed: 94 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -98,7 +98,11 @@ public class IlpEndpoint : Endpoint<Request, JsonErrorResponse?>
98
98
publicstaticboolWithRetriableError=false;
99
99
publicstaticboolWithErrorMessage=false;
100
100
101
-
// Get the port from request headers (set by DummyHttpServer)
101
+
/// <summary>
102
+
/// Determine the port key used for per-port state, preferring an explicit X-Server-Port request header when present.
103
+
/// </summary>
104
+
/// <param name="context">HTTP context from which to read the X-Server-Port header or the connection's local port.</param>
105
+
/// <returns>The port number from the X-Server-Port header if present and valid; otherwise the connection's local port; or 0 if neither is available.</returns>
/// Retrieves the current request counter for the specified port.
183
+
/// </summary>
184
+
/// <param name="port">The server port whose counter to retrieve.</param>
185
+
/// <returns>The current request counter value associated with the specified port.</returns>
147
186
publicstaticintGetCounter(intport)
148
187
{
149
188
lock(PortData)
@@ -152,6 +191,11 @@ public static int GetCounter(int port)
152
191
}
153
192
}
154
193
194
+
/// <summary>
195
+
/// Set the request counter for the specified server port's per-port state.
196
+
/// </summary>
197
+
/// <param name="port">Port key identifying which server instance's state to modify.</param>
198
+
/// <param name="value">New counter value to store for that port.</param>
155
199
publicstaticvoidSetCounter(intport,intvalue)
156
200
{
157
201
lock(PortData)
@@ -161,6 +205,10 @@ public static void SetCounter(int port, int value)
161
205
}
162
206
}
163
207
208
+
/// <summary>
209
+
/// Clears stored state for the specified port, removing accumulated request text and bytes and resetting the port's last error and request counter.
210
+
/// </summary>
211
+
/// <param name="port">Port number whose stored buffers and metadata will be reset.</param>
164
212
publicstaticvoidClearPort(intport)
165
213
{
166
214
lock(PortData)
@@ -174,6 +222,14 @@ public static void ClearPort(int port)
174
222
}
175
223
}
176
224
225
+
/// <summary>
226
+
/// Set per-port configuration flags that control authentication requirements and simulated error behavior for the server running on the specified port.
227
+
/// </summary>
228
+
/// <param name="port">The server port to configure.</param>
229
+
/// <param name="tokenAuth">If true, token-based authentication is required for requests to this port.</param>
230
+
/// <param name="basicAuth">If true, HTTP Basic authentication is required for requests to this port.</param>
231
+
/// <param name="retriableError">If true, the endpoint will respond with an HTTP 500 to simulate a retriable server error for this port.</param>
232
+
/// <param name="errorMessage">If true, the endpoint will respond with a JSON error payload and HTTP 400 to simulate a client error for this port.</param>
/// Resolve authentication and error-behavior flags for the specified server port, falling back to global defaults when no per-port configuration exists.
243
+
/// </summary>
244
+
/// <param name="port">TCP port number used to look up per-port configuration.</param>
245
+
/// <returns>
246
+
/// A tuple with the resolved flags:
247
+
/// <list type="bullet">
248
+
/// <item><description><c>TokenAuth</c>: <c>true</c> if token authentication is enabled for the port, <c>false</c> otherwise.</description></item>
249
+
/// <item><description><c>BasicAuth</c>: <c>true</c> if basic authentication is enabled for the port, <c>false</c> otherwise.</description></item>
250
+
/// <item><description><c>RetriableError</c>: <c>true</c> if the port is configured to respond with retriable errors, <c>false</c> otherwise.</description></item>
251
+
/// <item><description><c>ErrorMessage</c>: <c>true</c> if the port is configured to return structured error messages, <c>false</c> otherwise.</description></item>
/// Configure the endpoint's route, authentication behavior, request description, and request binder.
269
+
/// </summary>
270
+
/// <remarks>
271
+
/// Maps the POST route "api/v2/write" to the endpoint, allows anonymous access when token auth is disabled,
272
+
/// registers a basic-auth preprocessor when basic auth is enabled, declares that the endpoint accepts a <see cref="Request"/>,
273
+
/// and assigns the <see cref="Binder"/> as the request binder.
274
+
/// </remarks>
198
275
publicoverridevoidConfigure()
199
276
{
200
277
Post("write","api/v2/write");
@@ -212,6 +289,19 @@ public override void Configure()
212
289
RequestBinder(newBinder());
213
290
}
214
291
292
+
/// <summary>
293
+
/// Processes an incoming write request for a specific port's dummy server, recording the request body into that port's in-memory buffers or returning configured error responses.
294
+
/// </summary>
295
+
/// <param name="req">The bound request containing raw bytes and a UTF-8 string representation of the body.</param>
296
+
/// <param name="ct">A cancellation token to observe while processing the request.</param>
297
+
/// <remarks>
298
+
/// Behavior:
299
+
/// - Increments the per-port request counter.
300
+
/// - If the port's configuration requests a retriable error, responds with HTTP 500 and no content.
301
+
/// - If the port's configuration requests an error message, responds with a JsonErrorResponse and HTTP 400.
302
+
/// - Otherwise appends the request string to the port's receive buffer and the request bytes to the port's byte list, then responds with HTTP 204.
303
+
/// - On exception, stores the exception as the port's last error and rethrows.
0 commit comments