KestrelCgi 0.0.2
dotnet add package KestrelCgi --version 0.0.2
NuGet\Install-Package KestrelCgi -Version 0.0.2
<PackageReference Include="KestrelCgi" Version="0.0.2" />
<PackageVersion Include="KestrelCgi" Version="0.0.2" />
<PackageReference Include="KestrelCgi" />
paket add KestrelCgi --version 0.0.2
#r "nuget: KestrelCgi, 0.0.2"
#:package KestrelCgi@0.0.2
#addin nuget:?package=KestrelCgi&version=0.0.2
#tool nuget:?package=KestrelCgi&version=0.0.2
KestrelCgi
KestrelCgi implements a simple CGI server directly on top of Kestrel.
How it works
An example is provided in Demo/Program.cs:
First, implement ICgiHttpContent:
class ExampleCgiContext : ICgiHttpContext
{
public required HttpContext HttpContext { get; set; }
public bool LogErrorOutput { get; set; } = true;
public TimeSpan ProcessingTimeout { get; set; } = TimeSpan.FromSeconds(3);
}
Then, derive from the abstract class CgiHttpApplication and implement GetCgiExecutionInfo to provide CgiExecutionInfo which gives necessary information on how to execute a CGI program:
class ExampleCgiServer(ILogger? logger = null) : CgiHttpApplication<ExampleCgiContext>(logger)
{
public override ExampleCgiContext CreateContext(IFeatureCollection contextFeatures)
{
ExampleCgiContext context = new() { HttpContext = new DefaultHttpContext(contextFeatures) };
return context;
}
public override CgiExecutionInfo? GetCgiExecutionInfo(ExampleCgiContext context)
{
var request = context.HttpContext.Request;
if (request.Path.StartsWithSegments(@"/env.fsx"))
{
const string scriptName = "/env.fsx";
var pathInfo = request.Path.Value![scriptName.Length..];
var envUpdate = new Dictionary<string, string> { { "FOO", "BAR" } };
CgiExecutionInfo result = new(
ScriptName: "env.fsx",
PathInfo: pathInfo,
CommandPath: "dotnet",
CommandArgs: ["fsi", Path.Join(".", "script", "env.fsx")],
EnvironmentUpdate: envUpdate
);
return result;
}
else
{
return null;
}
}
}
Now it can be run on a KestrelServer:
KestrelServer server = new(/*...*/);
server.StartAsync(new ExampleCgiServer(), CancellationToken.None);
See it in action
In the root directory, run:
cd Demo
dotnet run
Then in a Web browser, navigate to http://localhost:5001/env.fsx to see the output of the F# script.
Futhermore, the repository is served by git http-backend at http://127.0.0.1:5001/git which can be cloned like:
git clone http://127.0.0.1:5001/git/ new_repo
Installation
Install the nuget package:
dotnet package add KestrelCgi
For local instanll, a --source switch can be specified to indicate the directory where the nuget package resides.
Project Setup
Your .csproj needs reference to framework Microsoft.AspNetCore.App for Kestrel related stuff (see Demo/Demo.csproj):
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
How to package the nuget
In the root directory, run:
dotnet pack Lib -o nupkg
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.