WasiInMemoryHttpClient Class
An HTTP client that gives the requests to a handler of the process, without the network: a HttpMessageHandler (such as a mock), or a function. It works on every platform, including the browser.
public sealed class WasiInMemoryHttpClient : WasiHttpClientExample
// The requests of the component go to a function of the process, without the network
var client = new WasiInMemoryHttpClient((request, cancellationToken) => Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent("Hello from " + request.RequestUri!.Host),
}));
var wasi = new WasiComponentContext(new WasiOptions { HttpClient = client });- Inheritance
WasiHttpClientWasiInMemoryHttpClient
Constructors
| Name | Description |
|---|---|
| WasiInMemoryHttpClient(Func<HttpRequestMessage, CancellationToken, Task<HttpResponseMessage>>) | Initializes a new instance of the WasiInMemoryHttpClient class with a function. |
| WasiInMemoryHttpClient(HttpMessageHandler) | Initializes a new instance of the WasiInMemoryHttpClient class with a message handler. |
WasiInMemoryHttpClient overloads
WasiInMemoryHttpClient(Func<HttpRequestMessage, CancellationToken, Task<HttpResponseMessage>>)
WasiHttpClient.csInitializes a new instance of the WasiInMemoryHttpClient class with a function.
public WasiInMemoryHttpClient(Func<HttpRequestMessage, CancellationToken, Task<HttpResponseMessage>> handler)Parameters
handlerFunc<HttpRequestMessage, CancellationToken, Task<HttpResponseMessage>>- The function that returns the response of a request.
WasiInMemoryHttpClient(HttpMessageHandler)
WasiHttpClient.csInitializes a new instance of the WasiInMemoryHttpClient class with a message handler.
public WasiInMemoryHttpClient(HttpMessageHandler handler)Parameters
handlerHttpMessageHandler- The handler of the requests: the client does not dispose it.
Methods
| Name | Description |
|---|---|
| SendAsync(HttpRequestMessage, CancellationToken) | Sends a request, and returns the response once its headers are received. |
SendAsync(HttpRequestMessage, CancellationToken)
WasiHttpClient.csSends a request, and returns the response once its headers are received.
public override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)Parameters
requestHttpRequestMessage- The request.
cancellationTokenCancellationToken- The token that is cancelled when the component cancels the request.
Returns
Task<HttpResponseMessage> The response.