Esempio n. 1
0
        public string ReadText()
        {
            var text = Environment.Get <string>("Gate.Request.Text");

            var thisInput = Body;
            var lastInput = Environment.Get <object>("Gate.Request.Text#input");

            if (text != null && ReferenceEquals(thisInput, lastInput))
            {
                return(text);
            }

            if (thisInput != null)
            {
                if (thisInput.CanSeek)
                {
                    thisInput.Seek(0, SeekOrigin.Begin);
                }
                text = new StreamReader(thisInput).ReadToEnd();
            }

            Environment.Set("Gate.Request.Text#input", thisInput);
            Environment.Set("Gate.Request.Text", text);
            return(text);
        }
Esempio n. 2
0
        public Task <IDictionary <string, string> > ReadFormAsync()
        {
            if (!HasFormData && !HasParseableData)
            {
                return(TaskHelpers.FromResult(ParamDictionary.Parse("")));
            }

            var form      = Environment.Get <IDictionary <string, string> >("Gate.Request.Form");
            var thisInput = Body;
            var lastInput = Environment.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.Environment.Set("Gate.Request.Form#input", thisInput);
                thisRequest.Environment.Set("Gate.Request.Form", form);
                return form;
            }));
        }
Esempio n. 3
0
        public Task <string> ReadTextAsync()
        {
            var text = Environment.Get <string>("Gate.Request.Text");

            var thisInput = Body;
            var lastInput = Environment.Get <object>("Gate.Request.Text#input");

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

            var buffer = new MemoryStream();

            Request thisRequest = this;

            //TODO: determine encoding from request content type
            return(CopyToStreamAsync(buffer)
                   .Then(() =>
            {
                buffer.Seek(0, SeekOrigin.Begin);
                text = new StreamReader(buffer).ReadToEnd();
                thisRequest.Environment["Gate.Request.Text#input"] = thisInput;
                thisRequest.Environment["Gate.Request.Text"] = text;
                return text;
            }));
        }
Esempio n. 4
0
        public Response SetHeader(string name, string value)
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                Headers.Remove(value);
            }
            else
            {
                Headers[name] = new[] { value }
            };
            return(this);
        }

        void OnSendingHeaders(Action <object> callback, object state)
        {
            var register = Environment.Get <Action <Action <object>, object> >(OwinConstants.OnSendingHeaders);

            if (register == null)
            {
                throw new NotImplementedException("Environment does not contain server.OnSendingHeaders");
            }
            register(callback, state);
        }
Esempio n. 5
0
        public IDictionary <string, string> ReadForm()
        {
            if (!HasFormData && !HasParseableData)
            {
                return(ParamDictionary.Parse(""));
            }

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

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

            var text = ReadText();

            form = ParamDictionary.Parse(text);
            Environment.Set("Gate.Request.Form#input", thisInput);
            Environment.Set("Gate.Request.Form", form);
            return(form);
        }