コード例 #1
0
        /// <summary>
        /// Reads and parses the request body as a form.
        /// </summary>
        /// <returns>The parsed form data.</returns>
        internal static IFormCollection ReadForm(this OwinRequest request)
        {
            var form = request.Get <IFormCollection>("Microsoft.Owin.Form#collection");

            if (form == null)
            {
                request.Body.Seek(0, SeekOrigin.Begin);

                string text;

                // Don't close, it prevents re-winding.
                using (var reader = new StreamReader(request.Body, Encoding.UTF8, detectEncodingFromByteOrderMarks: true, bufferSize: 4 * 1024, leaveOpen: true))
                {
                    text = reader.ReadToEnd();
                }

                // re-wind for the next caller
                request.Body.Seek(0, SeekOrigin.Begin);

                form = OwinHelpers.GetForm(text);
                request.Set("Microsoft.Owin.Form#collection", form);
            }

            return(form);
        }
コード例 #2
0
        public static AppFunc Enable(AppFunc next, Func <IDictionary <string, object>, bool> requiresAuth, string realm, Func <string, UserPassword?> authenticator)
        {
            return(env =>
            {
                if (!requiresAuth(env))
                {
                    return next(env);
                }

                var requestHeaders = (IDictionary <string, string[]>)env[OwinConstants.RequestHeaders];

                var header = OwinHelpers.GetHeader(requestHeaders, "Authorization");

                var parsedHeader = ParseDigestHeader(header);

                if (parsedHeader == null)
                {
                    return Unauthorized(env, realm);
                }

                string user = parsedHeader["username"];
                var pwd = authenticator(user);

                // TODO: check for increment of "nc" header value

                if (!pwd.HasValue || !IsValidResponse(pwd.Value.GetHA1(user, realm), (string)env[OwinConstants.RequestMethod], parsedHeader))
                {
                    return Unauthorized(env, realm);
                }

                env["gate.RemoteUser"] = user;
                return next(env);
            });
        }
コード例 #3
0
ファイル: OwinRequest.net45.cs プロジェクト: zhangrl/katana
        public async Task ReadForm(IDictionary <string, string[]> form)
        {
            using (var reader = new StreamReader(Body))
            {
                string text = await reader.ReadToEndAsync();

                OwinHelpers.ParseDelimited(text, new[] { '&' }, (name, value, state) => ((IDictionary <string, string[]>)state).Add(name, new[] { value }), form);
            }
        }
コード例 #4
0
ファイル: OwinRequest.net45.cs プロジェクト: zhangrl/katana
        public async Task ReadForm(NameValueCollection form)
        {
            using (var reader = new StreamReader(Body))
            {
                string text = await reader.ReadToEndAsync();

                OwinHelpers.ParseDelimited(text, new[] { '&' }, (name, value, state) => ((NameValueCollection)state).Add(name, value), form);
            }
        }
コード例 #5
0
ファイル: OwinRequest.net45.cs プロジェクト: zhangrl/katana
        public async Task ReadForm(Action <string, string, object> callback, object state)
        {
            using (var reader = new StreamReader(Body))
            {
                string text = await reader.ReadToEndAsync();

                OwinHelpers.ParseDelimited(text, new[] { '&' }, callback, state);
            }
        }
コード例 #6
0
		// Inspect the method and headers to see if this is a valid websocket request.
		// See RFC 6455 section 4.2.1.
		private static bool IsWebSocketRequest(IDictionary<string, object> env)
		{
			var requestHeaders = (IDictionary<string, string[]>)env[OwinConstants.RequestHeaders];
			var webSocketUpgrade = OwinHelpers.GetHeaderSplit(requestHeaders, "Upgrade");
			var webSocketVersion = OwinHelpers.GetHeader(requestHeaders, "Sec-WebSocket-Version");
			var webSocketKey = OwinHelpers.GetHeader(requestHeaders, "Sec-WebSocket-Key");
			return webSocketUpgrade != null &&
				webSocketUpgrade.Contains("websocket", StringComparer.OrdinalIgnoreCase) &&
				webSocketVersion != null && webSocketKey != null;
		}
コード例 #7
0
ファイル: WebHelpers.cs プロジェクト: zhangrl/katana
        public static NameValueCollection ParseNameValueCollection(string text)
        {
            var form = new NameValueCollection();

            OwinHelpers.ParseDelimited(
                text,
                new[] { '&' },
                (a, b, c) => ((NameValueCollection)c).Add(a, b),
                form);

            return(form);
        }
コード例 #8
0
		// Se the websocket response headers.
		// See RFC 6455 section 4.2.2.
		private static void SetWebSocketResponseHeaders(IDictionary<string, object> env, IDictionary<string, object> acceptOptions)
		{
			var requestHeaders = (IDictionary<string, string[]>)env[OwinConstants.RequestHeaders];
			var webSocketKey = OwinHelpers.GetHeader(requestHeaders, "Sec-WebSocket-Key");

			env[OwinConstants.ResponseReasonPhrase] = "Switching Protocols";
			var responseHeaders = (IDictionary<string, string[]>)env[OwinConstants.ResponseHeaders];
			OwinHelpers.AddHeader(responseHeaders, "Connection", "Upgrade");
			OwinHelpers.AddHeader(responseHeaders, "Upgrade", "websocket");
			var webSocketAccept = Convert.ToBase64String(
				SHA1.Create().ComputeHash(Encoding.Default.GetBytes(webSocketKey + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11")));
			OwinHelpers.AddHeader(responseHeaders, "Sec-WebSocket-Accept", webSocketAccept);
		}
コード例 #9
0
        /// <summary>
        /// Asynchronously reads and parses the request body as a form.
        /// </summary>
        /// <returns>The parsed form data.</returns>
        public async Task <IFormCollection> ReadFormAsync()
        {
            var form = Get <IFormCollection>("Microsoft.Owin.Form#collection");

            if (form == null)
            {
                string text;
                using (var reader = new StreamReader(Body))
                {
                    text = await reader.ReadToEndAsync();
                }
                form = OwinHelpers.GetForm(text);
                Set("Microsoft.Owin.Form#collection", form);
            }

            return(form);
        }
コード例 #10
0
ファイル: OwinRequest.cs プロジェクト: iftree/DotHassServer
        /// <summary>
        /// Asynchronously reads and parses the request body as a form.
        /// </summary>
        /// <returns>The parsed form data.</returns>
        public async Task <IFormCollection> ReadFormAsync()
        {
            var form = Get <IFormCollection>("Microsoft.Owin.Form#collection");

            if (form == null)
            {
                string text;
                // Don't close, it prevents re-winding.
                using (var reader = new StreamReader(Body, Encoding.UTF8, detectEncodingFromByteOrderMarks: true, bufferSize: 4 * 1024, leaveOpen: true))
                {
                    text = await reader.ReadToEndAsync();
                }
                form = OwinHelpers.GetForm(text);
                Set("Microsoft.Owin.Form#collection", form);
            }

            return(form);
        }
コード例 #11
0
 public static IDictionary <string, string> GetCookies(this OwinRequest request)
 {
     return(OwinHelpers.GetCookies(request));
 }
コード例 #12
0
 public static OwinRequest ApplyMethodOverride(this OwinRequest request)
 {
     return(OwinHelpers.ApplyMethodOverride(request));
 }
コード例 #13
0
ファイル: HeaderDictionary.cs プロジェクト: evicertia/Katana
 /// <summary>
 /// Quotes any values containing comas, and then coma joins all of the values.
 /// </summary>
 /// <param name="key">The header name.</param>
 /// <param name="values">The header values.</param>
 public void SetCommaSeparatedValues(string key, params string[] values)
 {
     OwinHelpers.SetHeaderJoined(Store, key, values);
 }
コード例 #14
0
ファイル: HeaderDictionary.cs プロジェクト: evicertia/Katana
 /// <summary>
 /// Sets a specific header value.
 /// </summary>
 /// <param name="key">The header name.</param>
 /// <param name="value">The header value.</param>
 public void Set(string key, string value)
 {
     OwinHelpers.SetHeader(Store, key, value);
 }
コード例 #15
0
ファイル: HeaderDictionary.cs プロジェクト: evicertia/Katana
 /// <summary>
 /// Add a new value. Appends to the header if already present
 /// </summary>
 /// <param name="key">The header name.</param>
 /// <param name="value">The header value.</param>
 public void Append(string key, string value)
 {
     OwinHelpers.AppendHeader(Store, key, value);
 }
コード例 #16
0
ファイル: HeaderDictionary.cs プロジェクト: evicertia/Katana
 /// <summary>
 /// Get the associated values from the collection without modification.
 /// </summary>
 /// <param name="key">The header name.</param>
 /// <returns>the associated value from the collection without modification, or null if the key is not present.</returns>
 public IList <string> GetValues(string key)
 {
     return(OwinHelpers.GetHeaderUnmodified(Store, key));
 }
コード例 #17
0
 /// <summary>
 /// Sets a 302 response status code and the Location header.
 /// </summary>
 /// <param name="location">The location where to redirect the client.</param>
 public virtual void Redirect(string location)
 {
     StatusCode = 302;
     OwinHelpers.SetHeader(RawHeaders, Constants.Headers.Location, location);
 }
コード例 #18
0
 public static string GetMethodOverride(this OwinRequest request)
 {
     return(OwinHelpers.GetMethodOverride(request));
 }
コード例 #19
0
 public static IDictionary <string, string[]> GetQuery(this OwinRequest request)
 {
     return(OwinHelpers.GetQuery(request));
 }
コード例 #20
0
 /// <summary>
 /// Get the associated values from the collection without modification.
 /// </summary>
 /// <param name="key">The header name.</param>
 /// <returns>the associated value from the collection without modification, or null if the key is not present.</returns>
 public IList <string> GetValues(string key) => OwinHelpers.GetHeaderUnmodified(Store, key);
コード例 #21
0
ファイル: HeaderDictionary.cs プロジェクト: evicertia/Katana
 /// <summary>
 /// Get the associated value from the collection as a single string.
 /// </summary>
 /// <param name="key">The header name.</param>
 /// <returns>the associated value from the collection as a single string or null if the key is not present.</returns>
 public string Get(string key)
 {
     return(OwinHelpers.GetHeader(Store, key));
 }
コード例 #22
0
 /// <summary>
 /// Quotes any values containing comas, and then coma joins all of the values with any existing values.
 /// </summary>
 /// <param name="key">The header name.</param>
 /// <param name="values">The header values.</param>
 public void AppendCommaSeparatedValues(string key, params string[] values) =>
 OwinHelpers.AppendHeaderJoined(Store, key, values);
コード例 #23
0
ファイル: HeaderDictionary.cs プロジェクト: evicertia/Katana
        /// <summary>
        /// Get the associated values from the collection separated into individual values.
        /// Quoted values will not be split, and the quotes will be removed.
        /// </summary>
        /// <param name="key">The header name.</param>
        /// <returns>the associated values from the collection separated into individual values, or null if the key is not present.</returns>
        public IList <string> GetCommaSeparatedValues(string key)
        {
            IEnumerable <string> values = OwinHelpers.GetHeaderSplit(Store, key);

            return(values == null ? null : values.ToList());
        }
コード例 #24
0
 /// <summary>
 /// Get the associated value from the collection as a single string.
 /// </summary>
 /// <param name="key">The header name.</param>
 /// <returns>the associated value from the collection as a single string or null if the key is not present.</returns>
 public string Get(string key) => OwinHelpers.GetHeader(Store, key);
コード例 #25
0
ファイル: HeaderDictionary.cs プロジェクト: evicertia/Katana
 /// <summary>
 /// Add new values. Each item remains a separate array entry.
 /// </summary>
 /// <param name="key">The header name.</param>
 /// <param name="values">The header values.</param>
 public void AppendValues(string key, params string[] values)
 {
     OwinHelpers.AppendHeaderUnmodified(Store, key, values);
 }
コード例 #26
0
 /// <summary>
 /// Get the associated value from the collection.  Multiple values will be merged.
 /// Returns null if the key is not present.
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public string Get(string key)
 {
     return(OwinHelpers.GetJoinedValue(Store, key));
 }
コード例 #27
0
ファイル: HeaderDictionary.cs プロジェクト: evicertia/Katana
 /// <summary>
 /// Sets the specified header values without modification.
 /// </summary>
 /// <param name="key">The header name.</param>
 /// <param name="values">The header values.</param>
 public void SetValues(string key, params string[] values)
 {
     OwinHelpers.SetHeaderUnmodified(Store, key, values);
 }
コード例 #28
0
 public static OwinResponse AddCookie(this OwinResponse response, string key, string value, CookieOptions options)
 {
     OwinHelpers.AddCookie(response, key, value, options);
     return(response);
 }
コード例 #29
0
 /// <summary>
 /// Parses an HTTP form body.
 /// </summary>
 /// <param name="text">The HTTP form body to parse.</param>
 /// <returns>The <see cref="T:Microsoft.Owin.IFormCollection" /> object containing the parsed HTTP form body.</returns>
 public static IFormCollection ParseForm(string text)
 {
     return(OwinHelpers.GetForm(text));
 }
コード例 #30
0
 public static OwinResponse DeleteCookie(this OwinResponse response, string key, CookieOptions options)
 {
     OwinHelpers.DeleteCookie(response, key, options);
     return(response);
 }