Create new C# console application project (.NET 4.5 or more). Add reference to NuGet-packages:
- Microsoft.Owin
- Microsoft.Owin.Hosting
- Microsoft.Owin.Host.HttpListener
- Owin.Compression (this package)
Then write the program, e.g.:
using System;
using Owin;
[assembly: Microsoft.Owin.OwinStartup(typeof(MyServer.MyWebStartup))]
namespace MyServer
{
class MyWebStartup
{
public void Configuration(Owin.IAppBuilder app)
{
var settings = OwinCompression.DefaultCompressionSettingsWithPath(@"c:\temp\");
//or var settings = new CompressionSettings( ... )
app.MapCompressionModule("/zipped", settings);
}
}
class Program
{
static void Main(string[] args)
{
Microsoft.Owin.Hosting.WebApp.Start<MyWebStartup>("http://*:8080");
Console.WriteLine("Server started... Press enter to exit.");
Console.ReadLine();
}
}
}
|
Have a large text file in your temp-folder, c:\temp\test\mytempfile.txt
Now, run the program (F5) and start a browser to address:
http://localhost:8080/zipped/test/mytempfile.txt
Observe that the file is transfered as compressed but the browser will automatically decompress the traffic.
#r "Owin.dll"
#r "Microsoft.Owin.dll"
#r "Microsoft.Owin.Hosting.dll"
#r "System.Configuration.dll"
#r "Owin.Compression.dll"
open Owin
open System
let serverPath = System.Configuration.ConfigurationManager.AppSettings.["WwwRoot"]
type MyWebStartup() =
member __.Configuration(app:Owin.IAppBuilder) =
let compressionSetting =
{OwinCompression.DefaultCompressionSettings with
ServerPath = serverPath;
CacheExpireTime = Some (DateTimeOffset.Now.AddDays 7.) }
app.MapCompressionModule("/zipped", compressionSetting) |> ignore
()
[<assembly: Microsoft.Owin.OwinStartup(typeof<MyWebStartup>)>]
do()
// and then...
Microsoft.Owin.Hosting.WebApp.Start<MyWebStartup> "http://*:8080"
Or you can use app.UseCompressionModule() in the beginning of the configuration to compress the whole response.
type MyWebStartupExample2() =
member __.Configuration(app:Owin.IAppBuilder) =
app.UseCompressionModule() |> ignore
//app.MapSignalR(hubConfig)
//app.UseFileServer(fileServerOptions) |> ignore
//etc...
()
namespace Owin
namespace System
val serverPath: obj
namespace System.Configuration
Multiple items
type MyWebStartup =
new: unit -> MyWebStartup
member Configuration: app: IAppBuilder -> unit
--------------------
new: unit -> MyWebStartup
val app: IAppBuilder
type IAppBuilder =
member Build: returnType: Type -> obj
member New: unit -> IAppBuilder
member Use: middleware: obj * [<ParamArray>] args: obj[] -> IAppBuilder
member Properties: IDictionary<string,obj>
val compressionSetting: obj
union case Option.Some: Value: 'T -> Option<'T>
<summary>The representation of "Value of type 'T"</summary>
<param name="Value">The input value.</param>
<returns>An option representing the value.</returns>
Multiple items
[<Struct>]
type DateTimeOffset =
new: dateTime: DateTime -> unit + 8 overloads
member Add: timeSpan: TimeSpan -> DateTimeOffset
member AddDays: days: float -> DateTimeOffset
member AddHours: hours: float -> DateTimeOffset
member AddMicroseconds: microseconds: float -> DateTimeOffset
member AddMilliseconds: milliseconds: float -> DateTimeOffset
member AddMinutes: minutes: float -> DateTimeOffset
member AddMonths: months: int -> DateTimeOffset
member AddSeconds: seconds: float -> DateTimeOffset
member AddTicks: ticks: int64 -> DateTimeOffset
...
<summary>Represents a point in time, typically expressed as a date and time of day, relative to Coordinated Universal Time (UTC).</summary>
--------------------
DateTimeOffset ()
DateTimeOffset(dateTime: DateTime) : DateTimeOffset
DateTimeOffset(dateTime: DateTime, offset: TimeSpan) : DateTimeOffset
DateTimeOffset(ticks: int64, offset: TimeSpan) : DateTimeOffset
DateTimeOffset(date: DateOnly, time: TimeOnly, offset: TimeSpan) : DateTimeOffset
DateTimeOffset(year: int, month: int, day: int, hour: int, minute: int, second: int, offset: TimeSpan) : DateTimeOffset
DateTimeOffset(year: int, month: int, day: int, hour: int, minute: int, second: int, millisecond: int, offset: TimeSpan) : DateTimeOffset
DateTimeOffset(year: int, month: int, day: int, hour: int, minute: int, second: int, millisecond: int, calendar: Globalization.Calendar, offset: TimeSpan) : DateTimeOffset
DateTimeOffset(year: int, month: int, day: int, hour: int, minute: int, second: int, millisecond: int, microsecond: int, offset: TimeSpan) : DateTimeOffset
DateTimeOffset(year: int, month: int, day: int, hour: int, minute: int, second: int, millisecond: int, microsecond: int, calendar: Globalization.Calendar, offset: TimeSpan) : DateTimeOffset
property DateTimeOffset.Now: DateTimeOffset with get
<summary>Gets a <see cref="T:System.DateTimeOffset" /> object that is set to the current date and time on the current computer, with the offset set to the local time's offset from Coordinated Universal Time (UTC).</summary>
<returns>A <see cref="T:System.DateTimeOffset" /> object whose date and time is the current local time and whose offset is the local time zone's offset from Coordinated Universal Time (UTC).</returns>
DateTimeOffset.AddDays(days: float) : DateTimeOffset
val ignore: value: 'T -> unit
<summary>Ignore the passed value. This is often used to throw away results of a computation.</summary>
<param name="value">The value to ignore.</param>
<example id="min-example"><code lang="fsharp">
ignore 55555 // Evaluates to ()
</code></example>
namespace Microsoft
val typeof<'T> : Type
<summary>Generate a System.Type runtime representation of a static type.</summary>
<example id="typeof-example"><code lang="fsharp">
let t = typeof<int> // Gets the System.Type
t.FullName // Evaluates to "System.Int32"
</code></example>
Multiple items
type MyWebStartupExample2 =
new: unit -> MyWebStartupExample2
member Configuration: app: IAppBuilder -> unit
--------------------
new: unit -> MyWebStartupExample2