OWIN : From Spec to Application
Damian Hickey
@randompunter / dhickey.ie
dotned, 26 June 2014
> whoami
• Not a web or http expert!
My Pain
Web APPIIS
WindowsService
SQL Database
WCF
Everyone does their own thing
• ServiceStack Selfhost
• Nancy Selfhost
• WebAPI Selfhost
• WCF Selfhost
• OpenRasta Selfhost
• etc
The Plan
• Part 1: OWIN• Raison d'être
• Design goals
• The Specification
• Part 2: Implementations• Hosts & Middleware
• Testing
• Samples & Recipes
• Part 3: OWIN in the wild
Part 1 – OWIN
Open Web Interface for .NET
Prior Art
• System.Web• Complicated lifecycle• Doesn’t look like HTTP• Tied to IIS, in most part• Difficult to test• Doesn’t look like HTTP
• Web Forms (let’s not talk about that)
• MVC rests on same System.Web bits as Web Forms
• Python: Web Server Gateway Interface (WSGI)
• Ruby: Rack
• Java\Clojure: Ring
ASP.NET Life Cycle
(Browser)
What is OWIN?
• A specification, not a technology, created by the community
• Defines a standard, minimal, interface between .NET web servers and web applications
• Decouples server from applications / frameworks
Design Goals
• Super simple signature for Applications and Middleware
• Dependency free (library and config)
• Asynchronous and concurrent by design
• Respect HTTP – Requests, Responses, Headers and Streams
• Composable
Terminology
• Host
• Middleware
• Web Framework
• Web Application
• Process (aka Sever)
IISSystemWeb
Helios
HttpListener
WebListener
Nowin
HTTTP.SYS
SocketsKestrel (libuv)
NGIXApache(FastCGI
FIOS
OWIN (AppFunc)
Application- Nancy- WebAPI- Security- Compression- FileServer- WebSockets- MVC 6- Mapping- Limiting- StatusCodeHandling- ViewEngines- Routing- etc
Headers
Request Stream
Body Stream
Headers
Response Stream
Body Stream
OWIN
The Core – The Application Function• Aka “AppFunc”
• That’s it!
App
The Environment Dictionary
• IDictionary<string, object>
• Has a set of well-defined keys and value types
• Stores Request & Response data
• Is mutable
The Environment(Browser, owin.org)
Middleware
Middleware is a pipeline
Middleware Middleware
Middleware
Some Rules
• Http pipelining is handled by the server. Do not respond with 100 Continues
• Never close the response body stream
• Always complete the Task
Code
(VS)
Testing
Resources
• owin.org
• katanaproject.codeplex.com
• #owin chat room on jabbr.net
• .NET HTTP Abstractions google group
• github.com/owin
Top Related