public static object RegisterAuthenticationHandler(this IOwinRequest request, AuthenticationHandler handler) { var chained = request.Get <AuthenticateDelegate>(Constants.SecurityAuthenticate); var hook = new Hook(handler, chained); request.Set <AuthenticateDelegate>(Constants.SecurityAuthenticate, hook.AuthenticateAsync); return(hook); }
internal static IDictionary <string, string> GetCookies(IOwinRequest request) { var cookies = request.Get <IDictionary <string, string> >("Microsoft.Owin.Cookies#dictionary"); if (cookies == null) { cookies = new Dictionary <string, string>(StringComparer.Ordinal); request.Set("Microsoft.Owin.Cookies#dictionary", cookies); } string text = GetHeader(request.Headers, "Cookie"); if (request.Get <string>("Microsoft.Owin.Cookies#text") != text) { cookies.Clear(); ParseDelimited(text, SemicolonAndComma, AddCookieCallback, decodePlus: false, decodeKey: false, state: cookies); request.Set("Microsoft.Owin.Cookies#text", text); } return(cookies); }
public OwinRequest(IOwinRequest request) { _request = request; _urlInfo = new UrlInfo(request.Uri); _cookies = new OwinRequestCookieCollection(request.Cookies); // setup the request params ImmutableDictionary <string, string> .Builder parms = ImmutableDictionary.CreateBuilder <string, string>(); ImmutableList <string> .Builder flags = ImmutableList.CreateBuilder <string>(); // import the querystring foreach (KeyValuePair <string, string[]> entry in request.Query) { if (entry.Value != null) { if (entry.Key == null) { flags.InsertRange(0, entry.Value); } else { parms.Add(entry.Key, entry.Value[0]); } } } // import the post values IFormCollection form = request.Get <IFormCollection>("Microsoft.Owin.Form#collection"); if (form != null) { foreach (KeyValuePair <string, string[]> entry in form) { parms.Add(entry.Key, entry.Value[0]); } } // import the payload //_payload = request.Body.AsMemoryStream().AsText(); using (TextReader reader = new StreamReader(request.Body)) { _payload = reader.ReadToEnd(); } // import the headers ImmutableDictionary <string, string> .Builder headers = ImmutableDictionary.CreateBuilder <string, string>(); foreach (KeyValuePair <string, string[]> entry in request.Headers) { headers.Add(entry.Key, entry.Value[0]); } _flags = flags.ToImmutable(); _params = parms.ToImmutable(); _headers = headers.ToImmutable(); }
public static IOwinRequest SetCookie(this IOwinRequest self, string name, string value) { // Force the cookies collection to be initialized. var _ = self.Cookies; // Grab the internal dictionary var dict = self.Get <IDictionary <string, string> >("Microsoft.Owin.Cookies#dictionary"); // Set the cookie dict[name] = value; return(self); }
public static Task <IFormCollection> ReadFormAsync(this IOwinRequest value) { var form = value.Get <IFormCollection>("Microsoft.Owin.Form#collection"); if (form == null) { value.Body.Seek(0, System.IO.SeekOrigin.Begin); // needed so ReadToEndAsync() doesn't hang string text; // Don't close, it prevents re-winding. using (var reader = new System.IO.StreamReader(value.Body, Encoding.UTF8, detectEncodingFromByteOrderMarks: true, bufferSize: 4 * 1024, leaveOpen: true)) { // *not* async - we're seeing hangs. See another with this issue: https://github.com/damianh/LibOwin/issues/12 text = reader.ReadToEnd(); } value.Body.Seek(0, System.IO.SeekOrigin.Begin); // subsequent calls will return nothing if this isn't re-wound form = GetForm(text); value.Set("Microsoft.Owin.Form#collection", form); } return(Task.FromResult(form)); }
public OwinRequest(IOwinRequest request) { _request = request; _urlInfo = new UrlInfo(request.Uri); _cookies = new OwinRequestCookieCollection(request.Cookies); // setup the request params ImmutableDictionary<string, string>.Builder parms = ImmutableDictionary.CreateBuilder<string, string>(); ImmutableList<string>.Builder flags = ImmutableList.CreateBuilder<string>(); // import the querystring foreach (KeyValuePair<string, string[]> entry in request.Query) { if (entry.Value != null) { if (entry.Key == null) { flags.InsertRange(0, entry.Value); } else { parms.Add(entry.Key, entry.Value[0]); } } } // import the post values IFormCollection form = request.Get<IFormCollection>("Microsoft.Owin.Form#collection"); if (form != null) { foreach (KeyValuePair<string, string[]> entry in form) { parms.Add(entry.Key, entry.Value[0]); } } // import the payload _payload = request.Body.AsMemoryStream().AsText(); // import the headers ImmutableDictionary<string, string>.Builder headers = ImmutableDictionary.CreateBuilder<string, string>(); foreach (KeyValuePair<string, string[]> entry in request.Headers) { headers.Add(entry.Key, entry.Value[0]); } _flags = flags.ToImmutable(); _params = parms.ToImmutable(); _headers = headers.ToImmutable(); }
public static bool IsLocal(this IOwinRequest request) { return(request.Get <bool>("server.IsLocal")); }
//https://stackoverflow.com/a/4393198 private static bool IsAjax(IOwinRequest request) { return((request.Get <string>("X-Requested-With") == "XMLHttpRequest") || ((request.Headers != null) && (request.Headers["X-Requested-With"] == "XMLHttpRequest"))); }
public T Get <T>(string key) { return(_request.Get <T>(key)); }
public static ServiceUnitContext GetServiceUnitContext(this IOwinRequest request) { return(request.Get <ServiceUnitContext>(ServiceUnitContextKey)); }