|
17 | 17 | - [EmbedIO 2.0 - What's new](#embedio-20---whats-new)
|
18 | 18 | - [Some usage scenarios](#some-usage-scenarios)
|
19 | 19 | - [Installation](#installation)
|
| 20 | +- [Usage](#usage) |
| 21 | + - [WebServer Setup](#webserver-setup) |
| 22 | + - [IHttpContext Extension Methods](#ihttpcontext-extension-methods) |
| 23 | + - [Easy Routes](#easy-routes) |
| 24 | +- [Support for SSL](#support-for-ssl) |
20 | 25 | - [Examples](#examples)
|
21 | 26 | - [Basic Example](#basic-example)
|
22 | 27 | - [Fluent Example](#fluent-example)
|
23 | 28 | - [REST API Example](#rest-api-example)
|
24 | 29 | - [WebSockets Example](#websockets-example)
|
25 |
| - - [Support for SSL](#support-for-ssl) |
26 | 30 | - [Related Projects and Nugets](#related-projects-and-nugets)
|
27 | 31 | - [Special Thanks](#special-thanks)
|
28 | 32 |
|
@@ -94,6 +98,51 @@ PM> Install-Package EmbedIO
|
94 | 98 | > dotnet add package EmbedIO
|
95 | 99 | ```
|
96 | 100 |
|
| 101 | +## Usage |
| 102 | + |
| 103 | +### WebServer Setup |
| 104 | + |
| 105 | +### IHttpContext Extension Methods |
| 106 | + |
| 107 | +By adding the namespace `Unosquare.Labs.EmbedIO` to your class, you can use some helpful extension methods for `IHttpContext`, `IHttpResponse` and `IHttpRequest`. Those can be used in any Web module (like [Fallback Module](https://unosquare.github.io/embedio/api/Unosquare.Labs.EmbedIO.Modules.FallbackModule.html)) or inside a [WebAPI Controller](https://unosquare.github.io/embedio/api/Unosquare.Labs.EmbedIO.Modules.WebApiController.html) method. |
| 108 | + |
| 109 | +Below, some common scenarios using a WebAPI Controller method as body function: |
| 110 | + |
| 111 | +#### Writing a binary stream |
| 112 | + |
| 113 | +For writing a binary stream directly to the Response Output Stream you can use [BinaryResponseAsync](https://unosquare.github.io/embedio/api/Unosquare.Labs.EmbedIO.Extensions.html#Unosquare_Labs_EmbedIO_Extensions_BinaryResponseAsync_Unosquare_Labs_EmbedIO_IHttpResponse_System_IO_Stream_System_Threading_CancellationToken_System_Boolean_). This method has an overload to use `IHttpContext` and you need to set the Content-Type beforehand. |
| 114 | + |
| 115 | +```csharp |
| 116 | + [WebApiHandler(HttpVerbs.Get, "/api/binary")] |
| 117 | + public async Task<bool> GetBinary() |
| 118 | + { |
| 119 | + var stream = new MemoryStream(); |
| 120 | + |
| 121 | + // Call a fictional external source |
| 122 | + await GetExternalStream(stream); |
| 123 | + |
| 124 | + return await this.BinaryResponseAsync(stream); |
| 125 | + } |
| 126 | +``` |
| 127 | + |
| 128 | +### Easy Routes |
| 129 | + |
| 130 | +## Support for SSL |
| 131 | + |
| 132 | +Both HTTP listeners (Microsoft and Unosquare) can open a web server using SSL. This support is for Windows only (for now) and you need to manually register your certificate or use the `WebServerOptions` class to initialize a new `WebServer` instance. This section will provide some examples of how to use SSL but first a brief explanation of how SSL works on Windows. |
| 133 | + |
| 134 | +For Windows Vista or better, Microsoft provides Network Shell (`netsh`). This command line tool allows to map an IP-port to a certificate, so incoming HTTP request can upgrade the connection to a secure stream using the provided certificate. EmbedIO can read or register certificates to a default store (My/LocalMachine) and use them against a netsh `sslcert` for binding the first `https` prefix registered. |
| 135 | + |
| 136 | +For Windows XP and Mono, you can use manually the `httpcfg` for registering the binding. |
| 137 | + |
| 138 | +### Using a PFX file and AutoRegister option |
| 139 | + |
| 140 | +The more practical case to use EmbedIO with SSL is the `AutoRegister` option. You need to create a `WebServerOptions` instance with the path to a PFX file and the `AutoRegister` flag on. This options will try to get or register the certificate to the default certificate store. Then it will use the certificate thumbprint to register with `netsh` the FIRST `https` prefix registered on the options. |
| 141 | + |
| 142 | +### Using AutoLoad option |
| 143 | + |
| 144 | +If you already have a certificate on the default certificate store and the binding is also registered in `netsh`, you can use `Autoload` flag and optionally provide a certificate thumbprint. If the certificate thumbprint is not provided, EmbedIO will read the data from `netsh`. After getting successfully the certificate from the store, the raw data is passed to the WebServer. |
| 145 | + |
97 | 146 | ## Examples
|
98 | 147 |
|
99 | 148 | ### Basic Example
|
@@ -364,22 +413,6 @@ public class WebSocketsChatServer : WebSocketsServer
|
364 | 413 | }
|
365 | 414 | ```
|
366 | 415 |
|
367 |
| -### Support for SSL |
368 |
| - |
369 |
| -Both HTTP listeners (Microsoft and Unosquare) can open a web server using SSL. This support is for Windows only (for now) and you need to manually register your certificate or use the `WebServerOptions` class to initialize a new `WebServer` instance. This section will provide some examples of how to use SSL but first a brief explanation of how SSL works on Windows. |
370 |
| - |
371 |
| -For Windows Vista or better, Microsoft provides Network Shell (`netsh`). This command line tool allows to map an IP-port to a certificate, so incoming HTTP request can upgrade the connection to a secure stream using the provided certificate. EmbedIO can read or register certificates to a default store (My/LocalMachine) and use them against a netsh `sslcert` for binding the first `https` prefix registered. |
372 |
| - |
373 |
| -For Windows XP and Mono, you can use manually the httpcfg for registering the binding. |
374 |
| - |
375 |
| -#### Using a PFX file and AutoRegister option |
376 |
| - |
377 |
| -The more practical case to use EmbedIO with SSL is the `AutoRegister` option. You need to create a `WebServerOptions` instance with the path to a PFX file and the `AutoRegister` flag on. This options will try to get or register the certificate to the default certificate store. Then it will use the certificate thumbprint to register with `netsh` the FIRST `https` prefix registered on the options. |
378 |
| - |
379 |
| -#### Using AutoLoad option |
380 |
| - |
381 |
| -If you already have a certificate on the default certificate store and the binding is also registered in `netsh`, you can use `Autoload` flag and optionally provide a certificate thumbprint. If the certificate thumbprint is not provided, EmbedIO will read the data from `netsh`. After getting successfully the certificate from the store, the raw data is passed to the WebServer. |
382 |
| - |
383 | 416 | ## Related Projects and Nugets
|
384 | 417 |
|
385 | 418 | Name | Author | Description
|
|
0 commit comments