SWebServer 1.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package SWebServer --version 1.2.0                
NuGet\Install-Package SWebServer -Version 1.2.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SWebServer" Version="1.2.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SWebServer --version 1.2.0                
#r "nuget: SWebServer, 1.2.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SWebServer as a Cake Addin
#addin nuget:?package=SWebServer&version=1.2.0

// Install SWebServer as a Cake Tool
#tool nuget:?package=SWebServer&version=1.2.0                

SWebServer

SWebServer is the simplest web server you can find on the Internet. It is a C# library to setup a web server in the fastest possible way. You can easily develop your response pages writing callbacks function. An example is included.

Source code is hosted on Github.

Description

Server implementations share a common interface, ISWebServer. Actually there are 2 main implementation of ISWebServer:

  1. SWebServerTcp is built on top of Griffin.Framework. It doesn't require any privileges to run.
  2. SWebServerNetsh is build on top of Netsh (utility provided by Window). It requires admin privileges to be run.

Installation

This package is published on Nuget to ease the integration with your project.

An alternative way is to clone and compile the example included in this library. The resulting SWebServer.dll and SWebServer.pdb files can be copied in your-project-path/bin/[debug|release]/, or in whatever folder you desire. You must be specify their location from Visual Studio (add a new Reference). SWebServer requires .NET v4.6.1.

Usage

To instantiate the web server based on TCP:

SWebServerTcp ws = new SWebServerTcp(SendResponse, 8081);

or Netsh-ed version:

SWebServerNetsh ws = new SWebServerNetsh(SendResponse, 8081);

where SendResponse is a function that manages the incoming requests, returning a string containg the body of the response. The simplest signature is:

string SendResponse(Stream request);

where the stream contains the payload (body) og HTTP request. Alternatively, a richer signature is:

string SendResponse(string method, string contentType, Stream request);

The response's code sent to the client is always 200, any error derived from your application should be managed in the response's body. To effectively start/stop the webserver:

ws.StartAndRun();
ws.Stop();

For more details check the example provided along with the source code.

Product Compatible and additional computed target framework versions.
.NET Framework net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.1 617 11/5/2019
1.2.0 491 10/31/2019
1.1.0 445 10/26/2019
1.0.2 453 10/20/2019
1.0.1 460 10/5/2019
1.0.0 567 10/5/2019

New method to add headers to HTTP response