Upgrade to 10.x
This document is intended to guide you when upgrading from GenHTTP 9.x to GenHTTP 10.
Dependency Injection
In GenHTTP 10, support for dependency injection has been added. If you are using custom mechanisms to achieve dependency injection, you might want to switch to the new, built-in way.
API Cleanup
The following types have been moved into their corresponding module packages as they are too specific to be part of the API.
| Type | Moved to |
|---|---|
PriorityEvaluation |
GenHTTP.Modules.LoadBalancing |
BindingException ProtocolException |
GenHTTP.Engine.Internal |
IErrorMapper |
GenHTTP.Modules.ErrorHandling |
SecureUpgrade |
GenHTTP.Modules.Security |
Removal of GenHTTP.Modules.Basics
The basics module provided useful extensions (such as response.Type(ContentType)) as well
as the redirect functionality. As a core dependency, this modules was always pulled when
creating a GenHTTP application, but the useful extension methods were magically hidden
behind a using GenHTTP.Modules.Basic. If you did not include this directive in your code
(e.g. because you used a template or the redirect functionality), you would never know that
those extensions exist.
Therefore, the extensions have been moved into the I/O module, which is typically referenced
when working with response content. The redirect functionality has been moved into a new
GenHTTP.Modules.Redirects module.
In essence, in your code you either need to replace using GenHTTP.Modules.Basics
with using GenHTTP.Modules.IO or with using GenHTTP.Modules.Redirects, depending on
the functionality you use.
Please note, that the IResourceProvider.GetResourceAsStringAsync() extension method
has been removed. If your code did use this extension, you can add it manually to your
code base:
public static async ValueTask<string> GetResourceAsStringAsync(this IResource resourceProvider)
{
await using var stream = await resourceProvider.GetContentAsync();
return await new StreamReader(stream).ReadToEndAsync();
}Asynchronous Websocket Callbacks
In versions prior to GenHTTP 10, and following the design of Fleck, the callbacks of the websocket handler were synchronous, whereas the methods provided by the websocket connection were asynchronous (meaning that socket.Send() returns a Task). This was non-intuitive, leading consumers of that API to think that the operations were blocking.
Example in GenHTTP 9:
Websocket.Create()
.OnOpen(c =>
{
c.Send("One");
c.Send("Two");
c.Close();
});In GenHTTP 10, the callbacks accepted by the handler are expected to be asynchronous, and the methods have been renamed to include the Async postfix:
Websocket.Create()
.OnOpen(async c =>
{
await c.SendAsync("One");
await c.SendAsync("Two");
c.Close();
});If there is no need for asynchronous execution in an event handler, you can return a completed task instead:
Websocket.Create()
.OnOpen(_ =>
{
Console.WriteLine("Someone connected.");
return Task.CompletedTask;
});