public class AwesomeServer : IServer
{
public AwesomeServer(IOptions<AwesomeServerOptions> options)
{
Features.Set<IHttpRequestFeature>(new HttpRequestFeature());
Features.Set<IHttpResponseFeature>(new HttpResponseFeature());
var serverAddressesFeature = new ServerAddressesFeature();
serverAddressesFeature.Addresses.Add(options.Value.FolderPath);
Features.Set<IServerAddressesFeature>(serverAddressesFeature);
}
public IFeatureCollection Features { get; } = new FeatureCollection();
public void Dispose() { }
public Task StartAsync<TContext>(IHttpApplication<TContext>
application, CancellationToken cancellationToken)
{
return Task.Run(() =>
{
var watcher = new AwesomeFolderWatcher<TContext>(application,
Features);
watcher.Watch();
}); }
public Task StopAsync(CancellationToken cancellationToken)
{
return Task.FromResult(0);
}
}
The server we will build is called AwesomeServer, an HTTP server that receives specific requests via files that are dropped in a folder on disk (instead of a network port) and then forwards them as proper HTTP requests to the rest of the request pipeline of the application. After the application processes the request, the returning response will overwrite the same file. Shows a diagram of how a request is read from a file and the returning response is written back.
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.