Giter Site home page Giter Site logo

kaliumhexacyanoferrat / genhttp Goto Github PK

View Code? Open in Web Editor NEW
169.0 3.0 27.0 9.9 MB

Lightweight web server written in pure C# with few dependencies to 3rd-party libraries.

Home Page: https://genhttp.org

License: MIT License

C# 99.48% HTML 0.33% JavaScript 0.10% CSS 0.09%
c-sharp http-server http webserver docker dotnet-framework embedded-server web-server embedded raspberry-pi

genhttp's Introduction

GenHTTP Webserver

GenHTTP is a lightweight web server written in pure C# with only a few dependencies to 3rd-party libraries. The main purpose of this project is to quickly create feature rich web applications and REST web services written in .NET 6/7/8, allowing developers to concentrate on the functionality rather than on messing around with configuration files, CSS or bundling and minifying JS files. Projects are mainly written in .NET, which allows C# developers to use their familiar toolset in web application development as well.

Creating a web application with GenHTTP

As an example, the website of this project is hosted on a Raspberry Pi: genhttp.org

CI Coverage nuget Package Discord

๐Ÿš€ Features

  • Setup new webservices or websites in a couple of minutes using project templates
  • Embed web services and applications into your existing console, service, WPF, WinForms, WinUI, MAUI or Uno application
  • Projects are fully described in code - no configuration files needed, no magical behavior you need to learn
  • Optimized out of the box (e.g. by bundling resources or compressing results)
  • Small memory and storage footprint
  • Several themes available to be chosen from
  • Grade A+ security level according to SSL Labs

๐Ÿ“– Getting Started

This section shows how to create a new project from scratch using project templates and how to extend your existing application by embedding the GenHTTP engine.

New Project

Project templates can be used to create apps for typical use cases with little effort. After installing the .NET SDK and the templates via dotnet new -i GenHTTP.Templates in the terminal, the templates are available via the console or directly in Visual Studio:

To create a project by using the terminal, create a new folder for your app and use one of the following commands:

Template Command Documentation
REST Webservice dotnet new genhttp-webservice Webservices
REST Webservice (single file) dotnet new genhttp-webservice-minimal Functional Handlers
Website dotnet new genhttp-website Websites
Website (Static HTML) dotnet new genhttp-website-static Statics Websites
Website (MVC + Razor) dotnet new genhttp-website-mvc-razor Controllers (MVC)
Website (MVC + Scriban) dotnet new genhttp-website-mvc-scriban Controllers (MVC)
Single Page Application (SPA) dotnet new genhttp-spa Single Page Applications (SPA)

After the project has been created, you can run it via dotnet run and access the server via http://localhost:8080.

Extending Existing Apps

If you would like to extend an existing .NET application, just add a nuget reference to the GenHTTP.Core nuget package. You can then spawn a new server instance with just a few lines of code:

var content = Content.From(Resource.FromString("Hello World!"));

using var server = Host.Create()
                       .Handler(content)
                       .Defaults()
                       .Start(); // or .Run() to block until the application is shut down

When you run this sample it can be accessed in the browser via http://localhost:8080.

Next Steps

The documentation provides a step-by-step starting guide as well as additional information on how to implement webservices, minimal webservices, websites, MVC style projects, or single page applications and how to host your application via Docker.

If you encounter issues implementing your application, feel free to join our Discord community to get help.

โš™๏ธ Building the Server

To build the server from source, clone this repository and run the playground project launcher for .NET 8:

git clone https://github.com/Kaliumhexacyanoferrat/GenHTTP.git
cd ./GenHTTP/Playground
dotnet run

This will build the playground project launcher with all the server dependencies and launch the server process on port 8080. You can access the playground in the browser via http://localhost:8080.

๐Ÿ™Œ Contributing

Writing a general purpose web application server is a tremendous task, so any contribution is very welcome. Besides extending the server core, you might want to

  • Extend the content capabilities of the server (e.g. by adding a new serialization format or rendering engine)
  • Add a new theme
  • Refine our project templates
  • Perform code reviews
  • Analyze the performance or security of the server
  • Clarfify and extend our tests
  • Improve the documentation on the website or in code

If you would like to contribute, please also have a look at the contribution guidelines and the good first issues.

๐Ÿบ History

The web server was originally developed in 2008 to run on a netbook with an Intel Atom processor. Both IIS and Apache failed to render dynamic pages on such a slow CPU back then. The original project description can still be found on archive.org. In 2019, the source code has been moved to GitHub with the goal to rework the project to be able to run dockerized web applications written in C#.

๐Ÿ“Œ Links

๐Ÿ™ Thanks

  • .NET for a nice platform

genhttp's People

Contributors

dependabot[bot] avatar fiahblade avatar fossabot avatar iuliancaluian avatar kaliumhexacyanoferrat avatar monodepth avatar nm-naegeli avatar ondator avatar wcontayon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

genhttp's Issues

Switch to .NET Standard 2.1

As a developer of the server engine, I would like to benefit from the new APIs in .NET Satandard 2.1 (such as TLS extensions), so that I can replace workarounds and optimize code. Switching to .NET Standard 2.1 will break support for some platforms.

Acceptance criteria

Cache file resources by default

As the developer of a web application, I would like to have my file-based pages be cached by the server, so that they are rendered with less allocations by the rendering engine. Usually, file resources are static anyway.

Example

public static FileDataProviderBuilder FromFile(string file, bool allowCache)

Acceptance criteria

  • Caching of file resources can be configured
  • By default, file resources will be cached in release mode and not be cached in debug mode (allowing developers to view changes without restarting the server)

Add caching infrastructure

As the developer of content providers, I would like to have a caching API, so that I can leverage caching to improve performance where applicable.

Example

var cachePolicy = CachePolicy.Create(); // ...

var memoryCache = Cache.Memory().Policy(cachePolicy);
var fileCache = Cache.FileBased("./cache").Policy(cachePolicy);

Acceptance criteria

  • There is an interface that allows content providers to utilize a cache, independent from its implementation (allowing to add other backends later on)
  • Storage characteristics of a cache instance can be adjusted using a CachePolicy (e.g. maximum size or age)
  • When stopping a server instance or it's host, all resources held by the caches (unless persistent) are released
  • Keep caching tests in mind (see #87)
  • The functionality is covered by unit tests

Add server manager for easier lifecycle handling

As a hosting application, I would like to easily restart a server, so that configuration changes are applied.

Example

var server = Server.Create();

using var manager = ServerManager.Create().Server(server).Build();

// start the server (non-blocking)
manager.Start();

// change something and restart
manager.Server.Compression(false);
manager.Restart();

// stop the server instance
manager.Stop();

Acceptance criteria

  • Server instance can be started, stopped, restarted
  • Manager implements IDisposable
  • Builders are verified not to change the state of the builder instance

Add provider for directory listings

As a developer of a web application, I would like to be able to provide directory listing, so users can easily browse and download data.

Example

var listing = DirectoryListing.From("./files");

Acceptance criteria

  • The directory listing provider can be used to generate graphical views for a given directory tree
  • The provider is part of the core framework, with no dependencies to scriban

Add support for Content Type Options

As the hoster of a web application, I want my application to set the content type options to nosniff, so that browser will not try to analyze my content.

Example

Add an extension that will set the header, if applicable.

var server = Server.Create()
                   .Security(ContentTypeOptions.NoSniff);

public enum ContentTypeOptions
{
    None, // the header will not be set
    NoSniff // default
}

Acceptance criteria

  • The functionality is implemented in the security module
  • The extension will only be added if ContentTypeOptions != .None
  • Add the extension to the default practices

Add webservice API

As a developer, I would like to easily add webservices to my application, so that clients can consume them.

Example

var webservice = Webservice.Attributed().Add<ArticleResource>().Add(resourceInstance);

[Path("/articles")]
public class ArticleResource {

  [Get]
  public List<Article> GetArticles(int page = 0, int pageSize = 20) {
    // ...
  }

  [Get]
  [Path("/:id")]
  public Article GetArticle(int id)
    // ...
  }

}

Acceptance criteria

  • Result objects are automatically serialized to JSON/XML depending on the request of the client
  • Typical features are available (HTTP method, path, query, body as object, stream as body, stream as result, ...)
  • The server returns HTTP 405 where expected

Add reverse proxy content provider

As a developer, I would like to add content of other web servers to my applicaion, so that I can provide more functionality.

Example

var proxy = ReverseProxy.Create()
                         .Upstream("http://localhost:8080/app/")
                         .ConnectTimeout(TimeSpan.FromSeconds(5))
                         .RequestTimeout(TimeSpan.FromSeconds(60));

Acceptance criteria

  • The proxy serves content provided by the upstream as expected
  • Functionality for HTTP status 502 and 504 must be provided
  • Redirects must be rewritten based on the host of the request

Allow or block requests by IP address

As the operator of a web application, I would like to restrict access to a known set of IP addresses so that unauthorized access is blocked.

Example

var content = Layout.Create(...);

var response = Content.From(Resource.FromString("Don't you dare"));

var access = Access.Create()
                   .Rule(AccessRule.BlockIP("91.8.20.0", response))
                   .Rule(AccessRule.BlockIPs(...))
                   .Rule(AccessRule.AllowIP(...));

content.Add(access);

Acceptance criteria

  • The functionality is implemented as a concern in the security module
  • Requests can be blocked (blacklist) or allowed (whitelist) by IP address (or range)
  • The handler returns the given content alongside with a AccessDenied status code if the request is blocked
  • If no content is given, a default error page is rendered to inform the user
  • The framework is open for additional access rules in the future (e.g. geoblocking, behavior-based, ...)
  • Acceptance tests are written for this functionality

Add framework to develop model-based pages

As a developer, I would like to add web pages with additional logic in their model classes, so that I can handle situations like submitted data.

Example

var page = Page.Create<SomeModel>(ScribanView.From("someview.html"));

public class SomeModel : PageModel
{
  public string MyProperty { get; }

  public void OnPost() 
  {
    // ...
  }
}

Acceptance criteria

  • The framework is available as a separate nuget package
  • The framework allows to work with views from different rendering engines (e.g. #48)
  • There is an additional router which allows to specify a whole directory with view files
  • The framework aligns with Razor Pages where appropriate to keep the learning curve low

Replace codecov.io with coveralls.io

As a developer of the GenHTTP web server I would like to have working code coverage metrics.

Acceptance criteria

  • Coverage is automatically uploaded after Travis CI build
  • Codecov.io has been disabled

Add support for virtual hosts

As someone hosting multiple domains, I would like be able to run virtual hosts, so that I can re-use a single IP address for multiple domains.

Example

As this is a classic routing feature, this should be fairly easy to be implemented.

var firstWebsite = Layout.Create(...);
var secondWebsite = Layout.Create(...);

var hosts = VirtualHosts.Create()
                        .Add("firstwebsite.com", firstWebsite)
                        .Add("secondwebsite.com", secondWebsite)
                        .Default(firstWebsite)

using var server = Server.Create().Router(hosts).Build();

Such a router could be used anywhere in the tree, but it's probably most useful on root level.

Acceptance criteria

  • Requests to virtual hosts are relayed to the expected router
  • A default router can be specified. If not set, HTTP 404 should be returned for all unknown requests.

Add adapter for Prometheus

As the hoster of an application, I would like to report my server metrics to Prometheus, so that I can easily monitor my instance.

Example

Depends, whether we need a library for that and how the webservice should be exposed. Probably implement with #9?

Acceptance criteria

  • Servers can easily be extended to provide an endpoint which can be consumed by Prometheus
  • There's a dashboard that can be used to visualize server metrics

Automatically generate thumbnails

As a developer of a web application, I would like to serve images in an optimized manner, so that resources are saved and clients are able to render content faster.

Example

// access via http://host/.../300x300/myimage.png

var tree = ResourceTree.FromDirectory("./images");

var thumbnails = Resources.From(tree)
                          .Thumbnails()
                          .Minified() // see #59 
                          .Cached(); // see #25

Host.Create()
    .Handler(thumbnails)
    .Run();

Acceptance criteria

  • Implement the functionality in a new module (probably Imaging) as a concern
  • The thumbnail provider allows to fetch scaled images of the specified size (with aspect ratio maintained)
  • The provider will not scale images up (make them larger as the original one)
  • The solution has been benchmarked and profiled for performance
  • Acceptance tests have been added to cover the functionality

Add simple load balancer based on redirects/reverse proxies

As the operator of a web application serving downloads, I would like to be able to redirect download requests to other servers, so that my server stays responsive and the load is distributed.

Example

LoadBalancer.Redirection() /* .ReverseProxy() */
            .Node("https://some.mirror/mirror/")
            .Node("https://another.mirror/", (r) => Priority.Low)
            .Node(Static.Files("./downloads"))

Acceptance criteria

  • If a file is requested, the load balancer will select a random node to redirect/pass the client to
  • Only temporary redirects are used
  • For each node, the priority can be determined on per-request basis. The balancer chooses randomly from the mirrors with the highest priority (allowing to automatically choose node by region etc.).
  • The implementation re-uses the already existing Priority class

Add provider to cache content

As an operator of a web application I would like to leverage caching for specific content served by my application to improve latency and performance.

Example

var content = Resources.From(ResourceTree.FromDirectory("./"))
                       .Cached();

Host.Create()
    .Handler(content)
    .Run();

Acceptance criteria

  • The functionality is implemented as a concern in the Caching module
  • The implementation makes use of the caching infrastructure (see #45)
  • By default, a file-based cache is used
  • The concern detects changes to cached responses to invalidate the cache
  • Responses are sent with a known content length instead of Transfer-Encoding: chunked
  • Acceptance tests have been added to ensure the functionality

Improve overall allocation handling

As the developer of the server engine, I would like to have the server to allocate as few objects as possible, so that memory pressure is reduced and the overall performance improves.

For reference: https://michaelscodingspot.com/avoid-gc-pressure/

Acceptance criteria

  • Allocation, memory and CPU profiling have been performed
  • All lists and dictionaries are initialized with a reasonable capacity
  • All array allocations use pooling where applicable
  • Classes have been converted to structs if applicable
  • GC.SuppressFinalize(this) is called in all IDisposable implementations
  • Use stackalloc where applicable together with Span<T>
  • Use string.Intern for common strings such as headers
  • String allocations have been decreased
  • Memory management types (Span, ReadOnlySequence, ...) are fully understood and consistently used across the source
  • Critical code has been checked for inlining where applicable

Add basic authentication (RFC 7617)

As a developer of a web project, I would like to easily add basic authentication, so that not everyone can access restricted areas.

Example

var auth = BasicAuthentication.Create()
                              .Add("username", "password");

var secured = Layout.Create().Authentication(auth);

var secured = Layout.Create().Authentication((user, password) => true);

Acceptance criteria

  • Authentication can either be configured by supplying a lambda or adding credentials one by one
  • The handler complies to RFC 7617

Allow WebDAV requests to be handled (RFC 4918)

As a developer, I would like the server to pass through WebDAV, so that I can provide such content.

Implementation Notes

Probably change some of the fixed enums in core (RequestType, ResponseType, ContentType) to more flexible types that can include a raw string value, e.g. Flexible<ResponseType>.

Acceptance criteria

  • Add methods
    • PROPFIND
    • PROPPATCH
    • MKCOL
    • COPY
    • MOVE
    • LOCK
    • UNLOCK
  • Add status codes
    • 207 Multi-Status
    • 422 Unprocessable Entity
    • 423 Locked
    • 424 Failed Dependency
    • 507 Insufficient Storage

Add support for HSTS

As the hoster of a web application, I want my application to enforce strict transport security, so that man-in-the-middle attacks can be avoided to some extend.

Example

Could be achieved with an extension that is automatically added as soon a secure endpoint is configured.

// that's the default one that will automatically be applied
// disable via StrictTransportPolicy.None()

var policy = StrictTransportPolicy.Create()
                                  .MaximumAge(TimeSpan.FromDays(365))
                                  .IncludeSubdomains(true)
                                  .Preload(true);

var server = Server.Create()
                   .Bind(IPAddress.Any, 443, myCertificate)
                   .Security(policy);

Acceptance criteria

  • The extension appends a Strict-Transport-Security header with the given configuration to every response served via HTTPS (unless StrictTransportSecurity.None() has been set)

Add support for WebDAV (RFC 4918)

As a developer of a web application, I would like to provide content via WebDAV so that client applications can consume this content in a file based way.

Example

var provider = WebDAV.From("./dav").ReadOnly();

Acceptance criteria

  • The provider decouples the protocol from the actual data source (e.g. files and folders)
  • There is an easy to use implementation for file system based access
  • Features required by the implementation (e.g. handling of ETags) are not coupled with the WebDAV provider and are solved in separate issues
  • The implementation supports at least class 1 of the RFC

Error when serving requests without body via reverse proxy

When an upstream server returns a response without a entity (such as a redirect), the server will throw an exception:

REQ - 10.255.0.2 - PROPFIND /remote.php/webdav/some.mp3 - 308 - 0
ERR - ClientConnection - System.IO.IOException: Unable to read data from the transport connection: Broken pipe.
 ---> System.Net.Sockets.SocketException (32): Broken pipe
   --- End of inner exception stack trace ---
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
   at System.Net.Security.SslStream.<WriteSingleChunk>g__CompleteAsync|210_1[TWriteAdapter](ValueTask writeTask, Byte[] bufferToReturn)
   at System.Net.Security.SslStream.WriteAsyncChunked[TWriteAdapter](TWriteAdapter writeAdapter, ReadOnlyMemory`1 buffer)
   at System.Net.Security.SslStream.WriteAsyncInternal[TWriteAdapter](TWriteAdapter writeAdapter, ReadOnlyMemory`1 buffer)
   at System.Net.Http.HttpConnection.CopyFromBufferAsync(Stream destination, Int32 count, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnection.CopyToContentLengthAsync(Stream destination, UInt64 length, Int32 bufferSize, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnection.ContentLengthReadStream.CompleteCopyToAsync(Task copyTask, CancellationToken cancellationToken)
   at GenHTTP.Core.Protocol.ResponseHandler.WriteBody(IResponse response)
   at GenHTTP.Core.Protocol.ResponseHandler.Handle(IRequest request, IResponse response, Boolean keepAlive, Exception error)

Add pipeline-based server implementation

Add an implementation of the IServer which uses:

  • Pipelines to handle client connections without allocations
  • Advanced worker architecture (e.g. one worker per core) by implementing a PipeScheduler
  • Avoid allocations where possible
  • Utilize ValueTask where useful

The change must be compatible with the existing API for routing and content. Probably best to be implemented with #4.

Add support for SSL

Check, whether SSL support can easily be added on socket level using .NET Standard functionality. If not (or if it cannot be implemented in a secure manner), concentrate on a reverse proxy setup with Docker / Let's Encrypt and add appropriate documentation and guides.

Optimize transfer of file-based resources

As a developer of a web application, I would like file-based resources to be transferred in an optimized way, e.g. using Socket.SendFile() with Kernel APC.

Acceptance criteria

  • Performance gain has been proven compared to the regular provider

Remove Brotli support for now

Currently there seems to be no good solution to provide Brotli compression in .NET Standard:

  • Brotli.NET does not run on linux-arm32 and has interesting runtime characteristics
  • BrotliSharpLib spikes with 300 MB process memory usage on first instantiation of the stream
  • BrotliStream is not available in .NET Standard 2.0

Add support for robots.txt

As the developer of a web application, I would like to have an object-oriented way to provide the robots.txt configuration.

Example

var layout = Layout.Create().Add(Robots.Create().Sitemap(..));

Acceptance criteria

  • Crawlers can be controlled using an object-oriented API
  • A sitemap can be linked

Allocation-free streaming of content

As the developer of an IContentProvider, I would like to be able to stream my content without the need of additional allocations (e.g. by creating a temporary memory stream).

The bundle provider demonstrates the issues with the current implementation very clearly. Instead of a stream the server should expect some kind of promise that will directly write content into the target stream.

Example

public interface IResponseContent {
  long? Length { get; }
  Task Write(Stream target);
}

new StreamContent(stream);
new StringContent("Hello World");

Acceptance criteria

  • All providers are optimized to write their content free of unnecessary allocations
  • The old mechanism is removed from the engine but the API stays compatible
  • The compression algorithm architecture is simplified and optimized as well
  • If the content object implements IDisposable, the server will call Dispose on this object after use
  • HEAD requests are still properly processed

Add unit test for pipelining

As a client, I may want to use pipelining to improve latency on an already existing connection. As a developer, I would like the already existing feature to be unit tested.

Acceptance criteria

  • There is an unit test that ensures that pipelining is working as expected
  • The test must ensure the correctness of the responses

Automatically upgrade requests to SSL

As the hoster of a web application, I want requests automatically be upgraded to SSL, so that they are served in a secure manner.

Example

Probably add an extension that will analyze the incoming request and upgrade them, if necessary:

var server = Server.Create()
                   .Bind(IPAddress.Any, 80)
                   .Bind(IPAddress.Any, 443, myCertificate)
                   .Security(SecureUpgrade.Allow);

public enum SecureUpgrade
{
    None, // The server will not attempt to upgrade requests
    Allow, // The server will upgrade when Upgrade-Insecure-Requests is sent
    Enforce // The server will always redirect to HTTPs (default)
}

Acceptance criteria

  • Requests served via a secure endpoint are not upgraded
  • If there is no secure endpoint, the extension will not be installed
  • If SecureUpgrade.None, the extension will not be installed
  • With SecureUpgrade.Allow the extension will check for the Upgrade-Insecure-Requests header and return a response including the Vary: Upgrade-Insecure-Requests header (and HTTP 307)
  • With SecureUpgrade.Force, return with HTTP 301 and the HTTPs location

Document all the code

As a developer, I would like to have the public API of GenHTTP to be documented, so that it is easier to use and understand.

Acceptance criteria

  • All public methods, properties and interfaces within the server code are documented

Add support for Content Security Policy

As the hoster of a web application, I want to be able to define a Content Security Policy (CSP), so that several protection mechanisms can be applied. Note: This is implemented instead of X-XSS-Protection.

Example

The CSP can be send using an additional extension for this purpose, with a sane default to be applied.

var policy = ContentSecurityPolicy.Create()
                                  .BaseUri(...)
                                  .Source(ContentSource.Script, ...)
                                  .BlockMixed(true);

var server = Server.Create.Security(policy);

Acceptance criteria

  • The functionality is implemented in the security module
  • If a policy is defined, it will be sent to the client with every response
  • If no custom policy is set, a sane default will be applied automatically
  • If policy is set to ContentSecurityPolicy.None(), the extension will not be registered and no header will be sent

Add support for response compression

As a client, I would like to receive responses in a compressed form, so that less bandwith is required and pages can load more quickly.

Example

Compression should be enabled by default, so developers do not need to care about this feature. Probably add something like an IInterceptor or an ICoreExtension that can be added to the IServerBuilder.

// default with compression handling enabled
var server = Server.Create();

// disable compression
var server = Server.Create().Compression(false);

// custom compression
var server = Server.Create().Compression(SomeFancyCompression.Create());

// custom algorithm
var server = Server.Create().Compression(Zstandard.Create());

// general extension functionality
var server = Server.Create().Extension(SomeFancyCompression.Create());

Acceptance criteria

  • A newly created server instance automatically compresses content if requested by the client
  • The server will not compress already compressed content types
  • At least gzip and deflate are be supported
  • Additional alogrithms can be added using an API contract
  • Brotli should is supported (built-in or as a module)
  • Large downloads can be provided compressed
  • Content providers can disable compression for a response

Pre-compress static files

As the administrator of a web application, I would like file resources to be compressed once, so that they do not need to get compressed on-the-fly. This allows to use higher compression ratios and to save CPU cycles during runtime.

Example

var tree = ResourceTree.FromDirectory("./");

var resources = Resources.From(tree)
                         .Compression(/* pass something that indicates high compression ratio */)
                         .Cached(); // see #25

Host.Create()
    .Handler(resources)
    .Run();

Acceptance criteria

  • The existing compression concern is extended to increase compression ratio
  • There are acceptance tests to ensure the functionality

Add framework to develop pages based on the MVC pattern

As the developer of a web application, I would like to develop pages using the MVC pattern, so that I can structure and decouple my architecture.

Example

var project = Layout.Create().Add<MyController>();

public class MyController
{

   // GET /details/id
   public IContentProvider Details(int id) {
     return new ScribanView("view.html", GetModel(id));
   }

}

Acceptance criteria

  • The MVC framework is available as a separate nuget package
  • The framework allows to return views from different rendering engines
  • The framework supports typical features such as HTTP verbs, query and path params, request injection etc.
  • The framework aligns with ASP.NET MVC where appropriate to keep the learning curve low

Add support for IPv6

Add proper support for binding of IPv6 interfaces and extend the server builder to support any number of network interfaces / port combinations (e.g. .Bind(IPAddress.Any, 80).Bind(...)).

Add CI and Unit Tests

As a developer of the server source, I would like to have a Continous Integration mechanism, so that buildability and correctnes are automatically ensured.

Acceptance criteria

  • There's a Travis CI build job
  • Unit tests are executed
  • Coverage of unit tests is reported

Add website builder API

As a developer of a web application, I would like to have some default templates that can be used out of the box, so I can concentrate on my actual project/use case.

Example

var project = Layout.Create();

var website = Website.Create();

// add a predefined theme (or a custom one)
// probably add a CoreUI theme?
website.Theme(Themes.Activello().Background(...).OtherSetting(...));

// add a navigation menu that will be rendered by the theme
// probably auto-discover this via the given layout?
website.Menu(Menu.Create().Add("Home", "home"));

// add additional resources (which will be minified and bundled)
// in development mode, they will be referenced without being bundled
// all resources should be efficiently cached (when not in development mode)
website.Script(..., async: true);
website.Stylesheet(..., bundle: false);

website.Content(project);

Acceptance criteria

  • The builder definition should be available via the public API (IWebsiteBuilder, IMenuBuilder, ...)
  • Implemented Scriban themes should be provided by an additional module (due to embedded resources)

Implement FastCGI (RFC 3875)

As a developer, I would like to relay requests to a FastCGI socket, so that I can provide additional features (such as serving PHP applications).

Example

var php = FastCGI.Create()
                 .Upstream("127.0.0.1:9000")
                 .DocumentRoot("./some/folder");

Acceptance criteria

  • Requests can be relayed to a FastCGI handler
  • Requests handling properly supports POST/PUT/DELETE/HEAD etc.

Extract themes into their own repository

As a developer of the GenHTTP Webserver, I would like to separate the themes from the server repo to keep the repo clean and small and allow themes to be developed independently and with higher quality.

Acceptance criteria

  • Themes are available from their own repository
  • Themes reference the lowest server version possible
  • Every theme has its own version
  • There is an example project to demonstrate the themes which are available
  • Themes provide symbol packages for code completion

Add support for sitemaps

As the developer of a web application, I would like to automatically generate a sitemap so that my website is crawled more easily.

Example

var project = Layout.Create().Add();
var sitemap = Sitemap.From(project);
project.Add(sitemap);

Acceptance criteria

  • A sitemap can either be automatically generated from the parent router or manually defined by the developer (where both modes can be mixed)
  • The sitemap provider will automatically split sitemaps if typical entry limits are reached

Support Forwarded HTTP Extension (RFC 7239)

As an upstream server to a reverse proxy, I would like to retrieve additional information about the original request. The information should be accessible in a transparent manner.

Acceptance criteria

  • When acting as an upstream server, the Request interface should provide data of the original request instead of the proxying one
  • When acting as a reverse proxy, the server should send additional headers about the origin of the request

Add developer mode

As a developer of a web project, I would like to see exceptions rendered in the browser, so that I can trace an error more quickly. As a devops member, I do not want an web application to leak internal implementation detail with exception messages.

Example

var server = Server.Create();

#if DEBUG
server.Development();
#endif

Acceptance criteria

  • When in development mode, the server prints exception details on HTTP 500 error pages

Add support for async/await

Currently, GenHTTP.Core uses a mix of synchronous methods and the old-fashioned BeginSend / EndSend style. All I/O-related methods should be reworked to be async.

Add renderer for Razor files

As a developer of a web application, I would like to use Razor as a templating engine, so that I can re-use my knowledge from ASP.NET.

Example

var page = Razor.Page<CartModel>(Data.FromResource("cart.cshtml"), (r) => new CartModel());

Acceptance criteria

  • The Razor integration is available as a separate nuget package

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.