コード例 #1
0
ファイル: Request.cs プロジェクト: majimenezp/gate
        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);
        }
コード例 #2
0
ファイル: Request.cs プロジェクト: majimenezp/gate
        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;
            }));
        }
コード例 #3
0
ファイル: Request.cs プロジェクト: majimenezp/gate
        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;
            }));
        }
コード例 #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);
        }
コード例 #5
0
ファイル: Request.cs プロジェクト: majimenezp/gate
        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);
        }