The Open Web Interface for. NET (OWIN) source Read

Source: Internet
Author: User

Katana Open source for a long time, the online still did not search for its source of reading summary, I was in the work happened to meet the data processing process framework design, want to deal with the server request and response almost, then read Katana source code, and learn from its design ideas, bumps, difficulties, fortunately there are some gains, and exchanges with you.

Katana source https://katanaproject.codeplex.com/

Owin official website http://owin.org/

Two most important data structures

1 environment

Idictionary<string, object>

Official explanation:

This data structure are responsible for storing all of the state necessary for processing an HTTP request and response, As well as any relevant server state. An owin-compatible WEB server was responsible for populating the environment dictionary with data such as the body streams and header collections for an HTTP request and response. It is and then the responsibility of the application or framework and the populate or update the dictionary with Additio NAL values and write to the response body stream.

Environment is a data flow in the pipeline , representing a specific request and response, which will be introduced in each pipeline stage The data in this dictionary is processed, and the reference is discarded at the next stage, using atomic operations, so that each environment has only one Pipeline Stage . Data examples:

Key Name

Value Description

"Owin. Requestbody "

A Stream with the request body, if any. Stream.null may used as a placeholder if there is no request body. See Request Body.

"Owin. Requestheaders "

An idictionary<string, string[]> of request headers. See Headers.

"Owin. Requestmethod "

A string containing the HTTP request method of the request (e.g., "GET", "POST").

"Owin. Requestpath "

A string containing the request path. The path must is relative to the "root" of the application delegate; See Paths.

"Owin. Requestpathbase "

A string containing the portion of the request path corresponding to the "root" of the application delegate; See Paths.

"Owin. Requestprotocol "

A string containing the protocol name and version (e.g. "http/1.0" or "http/1.1").

"Owin. Requestquerystring "

A string containing the query string component of the HTTP request URI, without the leading "?" (e.g., "Foo=bar&baz=quux"). The value is an empty string.

"Owin. Requestscheme "

A string containing the URI scheme used for the request (e.g, "http", "https"); See URI Scheme.

2 Appfunc

Func<idictionary<string, Object>, task>;

Official explanation:

The second key element of OWIN is the application delegate. This was a function signature which serves as the primary interface between all components in an OWIN application. The definition for the application delegate is as follows:

The application delegate then was simply an implementation of the Func delegate type where the function accepts the Environ ment dictionary as input and returns a Task. This design have several implications for developers:

    • There is a very small number of type dependencies required in order to write OWIN components. This greatly increases the accessibility of OWIN to developers.
    • The asynchronous design enables the abstraction to being efficient with its handling of computing resources, particularly in More I/O intensive operations.
    • Because the application delegate is an atomic unit of execution and Because the environment Dictionary is carried as a par Ameter on the delegate, OWIN components can is easily chained together to create complex HTTP processing pipelines.

This is middleware, and each pipeline stage in the specific processing method, in the form of asynchronous invocation, by the StartUp class to register, and generate a chain, is actually pressed into a List .

Source reading, can learn a lot of things, there must be a lot of understanding of the deviation of the place, welcome to correct, I will from a specific middleware registration and StartUp of the executive cut-in, roughly outline a pipeline Process of construction and flow.

The Open Web Interface for. NET (OWIN) source Read

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.