Exemplo n.º 1
0
        public Task <IDictionary <string, string> > ReadFormAsync()
        {
            if (!HasFormData && !HasParseableData)
            {
                return(TaskHelpers.FromResult(ParamDictionary.Parse("")));
            }

            var form      = Get <IDictionary <string, string> >("Gate.Request.Form");
            var thisInput = Body;
            var lastInput = Get <object>("Gate.Request.Form#input");

            if (form != null && ReferenceEquals(thisInput, lastInput))
            {
                return(TaskHelpers.FromResult(form));
            }

            Request thisRequest = this;

            return(ReadTextAsync().Then(text =>
            {
                form = ParamDictionary.Parse(text);
                thisRequest.Set("Gate.Request.Form#input", thisInput);
                thisRequest.Set("Gate.Request.Form", form);
                return form;
            }));
        }
Exemplo n.º 2
0
        // Primarily for unit tests
        public static Request Create()
        {
            Request request = new Request(new Dictionary <string, object>());

            request.Set(OwinConstants.RequestHeaders, Gate.Headers.New());
            request.Set(OwinConstants.ResponseHeaders, Gate.Headers.New());
            return(request);
        }
Exemplo n.º 3
0
        // Returns false for fatal errors, along with a resulting message.
        // Otherwise any warnings are appended.
        private static bool TryValidateCall(IDictionary<string, object> env, IList<string> warnings)
        {
            if (env == null)
            {
                throw new ArgumentNullException("env");
            }

            var req = new Request(env);

            // Must be mutable
            try
            {
                string key = "validator.MutableKey";
                string input = "Mutable Value";
                req.Set(key, input);
                string output = req.Get<string>(key);
                if (output == null || output != input)
                {
                    SetFatalResult(env, "3.2", "Environment is not fully mutable.");
                    return false;
                }
                req.Set<string>(key, null);
            }
            catch (Exception ex)
            {
                SetFatalResult(env, "3.2", "Environment is not mutable: \r\n" + ex.ToString());
                return false;
            }

            // Environment key names MUST be case sensitive.
            string upperKey = "Validator.CaseKey";
            string lowerKey = "validator.casekey";
            string[] caseValue = new string[] { "Case Value" };
            env[upperKey] = caseValue;
            string[] resultValue = req.Get<string[]>(lowerKey);
            if (resultValue != null)
            {
                SetFatalResult(env, "3.2", "Environment is not case sensitive.");
                return false;
            }
            env.Remove(upperKey);

            // Check for required owin.* keys and the HOST header.
            if (!CheckRequiredCallData(env, warnings))
            {
                return false;
            }

            return true;
        }